gump-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bode...@apache.org
Subject svn commit: r1306165 - /gump/trunk/python/gump/core/update/git.py
Date Wed, 28 Mar 2012 04:55:09 GMT
Author: bodewig
Date: Wed Mar 28 04:55:09 2012
New Revision: 1306165

URL: http://svn.apache.org/viewvc?rev=1306165&view=rev
Log:
ensure working copy uses the correct git branch

Modified:
    gump/trunk/python/gump/core/update/git.py

Modified: gump/trunk/python/gump/core/update/git.py
URL: http://svn.apache.org/viewvc/gump/trunk/python/gump/core/update/git.py?rev=1306165&r1=1306164&r2=1306165&view=diff
==============================================================================
--- gump/trunk/python/gump/core/update/git.py (original)
+++ gump/trunk/python/gump/core/update/git.py Wed Mar 28 04:55:09 2012
@@ -16,15 +16,19 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
+import re
 from gump.core.update.scmupdater import match_workspace_template, ScmUpdater, \
-    should_be_quiet, log_repository_and_url
-from gump.util.process.command import Cmd
+    should_be_quiet, log_repository_and_url, extract_URL
+from gump.util.process.command import Cmd, getCmdFromString
+from gump.util.process.launcher import execute
 from gump.util.tools import tailFileToString
 
 def maybe_make_quiet(module, cmd):
     if should_be_quiet(module):    
         cmd.addParameter('--quiet')
 
+BRANCH_REGEX = re.compile('^\* (.*)$', re.MULTILINE | re.UNICODE)
+
 ###############################################################################
 # Classes
 ###############################################################################
@@ -68,8 +72,24 @@ class GitUpdater(ScmUpdater):
 
     def workspaceMatchesModule(self, module):
         """
-            Run git config remote.origin.url to see whether the URL matches
+            Run git branch and git config remote.origin.url
+            to see whether the branch and URL match
         """
+        cmd = getCmdFromString('git branch',
+                               'check_workspace_branch_' + module.getName(), 
+                               module.getSourceControlStagingDirectory())
+        result = execute(cmd)
+
+        if not result.isOk():
+            return (False, 'git branch returned ' + str(result.exit_code))
+        elif not result.hasOutput():
+            return (False, 'git branch didn\'t return any output.')
+
+        current_branch = extract_URL(result, BRANCH_REGEX, 'git branch')
+        if module.getScm().getBranch() != current_branch:
+            return (False, 'Expected branch \'' + module.getScm().getBranch() \
+                        + '\' but working copy was \'' + current_branch + '\'')
+
         return match_workspace_template(module, 'git config remote.origin.url',
                                         lambda result:
                                             tailFileToString(result.getOutput(),



Mime
View raw message