[jhbuild] git: fix current branch detection



commit a00fb9f981cd2f799b830ccdeb5595e0fced7082
Author: Maciek Borzecki <maciek borzecki gmail com>
Date:   Wed Aug 26 14:14:33 2015 +0200

    git: fix current branch detection
    
    The current branch name will be incorrect if threre's a slash in it. For
    instance, if one uses a branch naming pattern like 'foo/master',
    get_current_branch() will incorrectly return 'master'.
    
    Signed-off-by: Maciek Borzecki <maciek borzecki gmail com>
    
    https://bugzilla.gnome.org/show_bug.cgi?id=754116

 jhbuild/versioncontrol/git.py |    7 ++++---
 1 files changed, 4 insertions(+), 3 deletions(-)
---
diff --git a/jhbuild/versioncontrol/git.py b/jhbuild/versioncontrol/git.py
index 840d94f..2f181ee 100644
--- a/jhbuild/versioncontrol/git.py
+++ b/jhbuild/versioncontrol/git.py
@@ -218,10 +218,11 @@ class GitBranch(Branch):
             raise CommandError(_('Unexpected: Checkoutdir is not a git '
                     'repository:' + self.get_checkoutdir()))
         try:
-            return os.path.basename(
-                    get_output(['git', 'symbolic-ref', '-q', 'HEAD'],
+            full_branch = get_output(['git', 'symbolic-ref', '-q', 'HEAD'],
                             cwd=self.get_checkoutdir(),
-                            extra_env=get_git_extra_env()).strip())
+                            extra_env=get_git_extra_env()).strip()
+            # strip refs/heads/ to get the branch name only
+            return full_branch.replace('refs/heads/', '')
         except CommandError:
             return None
 


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