From 69730d4475f6f76db5701da3f63d03f2a1ae070f Mon Sep 17 00:00:00 2001 From: Frederic Massart Date: Wed, 5 Nov 2014 12:54:54 +0800 Subject: [PATCH] Doctor command can check the value of the master branch --- extra/bash_completion | 2 +- mdk/commands/doctor.py | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++ mdk/git.py | 2 +- mdk/workplace.py | 3 ++- 4 files changed, 56 insertions(+), 3 deletions(-) diff --git a/extra/bash_completion b/extra/bash_completion index 1cb8f1d..3b7e32c 100644 --- a/extra/bash_completion +++ b/extra/bash_completion @@ -108,7 +108,7 @@ function _mdk() { OPTS="--compile --debug --sheets --theme --watch" ;; doctor) - OPTS="--all --branch --cached --dependencies --directories --remotes --symlink --wwwroot" + OPTS="--all --branch --cached --dependencies --directories --masterbranch --remotes --symlink --wwwroot" ;; fix) if [[ "$PREV" == "-n" || "$PREV" == "--name" ]]; then diff --git a/mdk/commands/doctor.py b/mdk/commands/doctor.py index cb3da5c..0f75cd4 100644 --- a/mdk/commands/doctor.py +++ b/mdk/commands/doctor.py @@ -23,6 +23,7 @@ http://github.com/FMCorz/mdk """ import os +import re import shutil import subprocess from .. import git @@ -84,6 +85,13 @@ class DoctorCommand(Command): } ), ( + ['--masterbranch'], + { + 'action': 'store_true', + 'help': 'Check the status of the master branch' + } + ), + ( ['--remotes'], { 'action': 'store_true', @@ -145,6 +153,10 @@ class DoctorCommand(Command): if args.branch or allChecks: self.branch(args) + # Check the master branch + if args.masterbranch or allChecks: + self.masterbranch(args) + # Check what you see is what you get if args.hi: self.hi(args) @@ -274,6 +286,46 @@ class DoctorCommand(Command): print ' Creating %s' % d mkdir(d, 0777) + def masterbranch(self, args): + """Checks the current master branch and the value set in config.""" + + print 'Checking master branch' + + if not self._checkWorkplace(): + return + + repoPath = self.Wp.getCachedRemote() + if not os.path.isdir(repoPath): + return + + try: + self.Wp.updateCachedClones(verbose=False) + except Exception: + print ' Could not update clone, please try again.' + return + + repo = git.Git(repoPath, self.C.get('git')) + result = repo.execute(['show', 'master:version.php']) + if result[0] != 0: + print ' Could not read the master version.php' + return + + reBranch = re.compile(r'^\s*\$branch\s*=\s*(?P[\'"])?([0-9]+)(?P=brackets)\s*;') + latestBranch = None + for line in result[1].split('\n'): + if reBranch.search(line): + latestBranch = int(reBranch.search(line).group(2)) + + masterBranch = int(self.C.get('masterBranch')) + if not latestBranch: + print ' Oops, could not identify the mater branch' + elif masterBranch != latestBranch: + print ' The config masterBranch is set to %d, expecting %d' % (masterBranch, latestBranch) + if args.fix: + print ' Setting masterBranch to %d' % (latestBranch) + self.C.set('masterBranch', latestBranch) + + def hi(self, args): """I wonder what is the purpose of this... diff --git a/mdk/git.py b/mdk/git.py index ac89158..8a2bff7 100644 --- a/mdk/git.py +++ b/mdk/git.py @@ -123,7 +123,7 @@ class Git(object): if not self.isRepository(path): raise Exception('This is not a Git repository') - if not type(cmd) == 'list': + if not type(cmd) == list: cmd = shlex.split(str(cmd)) cmd.insert(0, self.getBin()) diff --git a/mdk/workplace.py b/mdk/workplace.py index a9dff86..f16bdab 100644 --- a/mdk/workplace.py +++ b/mdk/workplace.py @@ -426,7 +426,8 @@ class Workplace(object): repo = git.Git(cache, C.get('git')) - logging.info('Fetching cached repository %s...' % os.path.basename(cache)) + if verbose: + logging.info('Fetching cached repository %s...', os.path.basename(cache)) if not repo.fetch(): raise Exception('Could not fetch in repository %s' % (cache)) -- 2.11.0