[jhbuild] [git] Try to find requested branch remotely if not available



commit 3c31272066f5ff1d1c92fd244e14b71d68c7ee01
Author: Dirk Wallenstein <halsmit t-online de>
Date:   Mon May 17 14:48:10 2010 +0200

    [git] Try to find requested branch remotely if not available
    
    If a branch switch is requested but the branch is not available,
    upstream will be fetched and the branch will be looked up again, before
    failing.
    
    This should make the branch switching independent of the concerns stated
    in (GNOME bug 591470) and commit f7d5f81b6ca02ee5.

 jhbuild/versioncontrol/git.py |   16 ++++++++++++++++
 1 files changed, 16 insertions(+), 0 deletions(-)
---
diff --git a/jhbuild/versioncontrol/git.py b/jhbuild/versioncontrol/git.py
index 3c7bbf5..ea35efd 100644
--- a/jhbuild/versioncontrol/git.py
+++ b/jhbuild/versioncontrol/git.py
@@ -206,6 +206,17 @@ class GitBranch(Branch):
         except CommandError:
             return None
 
+    def _find_remote_branch_online_if_necessary(self, buildscript,
+            remote_name, branch_name):
+        """Try to find the given branch first, locally, then remotely, and state
+        the availability in the return value."""
+        wanted_ref = remote_name + '/' + branch_name
+        if self._execute_git_predicate( ['git', 'show-ref', wanted_ref]):
+            return True
+        buildscript.execute(['git', 'fetch'], cwd=self.get_checkoutdir(),
+                extra_env=get_git_extra_env())
+        return self._execute_git_predicate( ['git', 'show-ref', wanted_ref])
+
     def _switch_branch_if_necessary(self, buildscript):
         """
         The switch depends on the requested tag, the requested branch, and the
@@ -231,6 +242,11 @@ class GitBranch(Branch):
                 if self.local_branch_exist(wanted_branch, buildscript):
                     switch_command = ['git', 'checkout', wanted_branch]
                 else:
+                    if not self._find_remote_branch_online_if_necessary(
+                            buildscript, 'origin', wanted_branch):
+                        raise CommandError(_('The requested branch "%s" is '
+                                'not available. Neither locally, nor remotely '
+                                'in the origin remote.' % wanted_branch))
                     switch_command = ['git', 'checkout', '--track', '-b',
                             wanted_branch, 'origin/' + wanted_branch]
         if switch_command:



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]