After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 564672 - Don't use git-rev-parse to check for branch existance
Don't use git-rev-parse to check for branch existance
Status: RESOLVED FIXED
Product: jhbuild
Classification: Infrastructure
Component: general
unspecified
Other Linux
: Normal normal
: ---
Assigned To: Jhbuild maintainers
Jhbuild QA
Depends on:
Blocks:
 
 
Reported: 2008-12-15 22:19 UTC by Owen Taylor
Modified: 2009-04-24 14:14 UTC
See Also:
GNOME target: ---
GNOME version: ---



Description Owen Taylor 2008-12-15 22:19:17 UTC
def branch_exist(self, branch):
        if not branch:
            return False
        try:
            get_output(['git', 'rev-parse', branch], cwd = self.srcdir)
            return True
        except:
            return False

    def branchname(self):
        for b in [self.tag, 'origin/' + str(self.branch), 'origin/svn/' + str(self.branch),
                  self.branch, 'origin/master', 'origin/trunk', 'master', 'trunk']:
            if self.branch_exist(b):
                return b
        raise GitUnknownBranchNameError()
    branchname = property(branchname)

git-rev-parse does guessing on the argument to determine what it is. The
combination of that with the "try everything" approach can produce very
strange and confusing results. I'd suggest using git-show-rev --quiet --verify
to check for the existence of branch.

 git-show-rev --quiet --verify refs/remotes/origin/<branchname>
 git-show-rev --quiet --verify refs/heads/master
Comment 1 Owen Taylor 2008-12-15 22:20:18 UTC
Err, that's "git show-ref", not git-show-rev.
Comment 2 Frederic Peters 2009-04-13 08:31:53 UTC
I do not feel confortable doing this myself, apart:

-            get_output(['git', 'rev-parse', branch], cwd = self.srcdir)
+            get_output(['git', 'show-rev', '--quiet', '--verify', branch], cwd = self.srcdir)

What was the reasoning for checking origin/master and master? what about git-svn support provided by origin/svn/ + self.branch?

Could someone with more git confidence write a patch? (marc-andre and john, you are somehow targetted here :) )
Comment 3 Frederic Peters 2009-04-24 14:14:47 UTC
I went ahead, but didn't check git-svn and git-cvs were still ok.

commit bb0119d28d8d4823a493f43f165ee2575366bf73
Author: Frederic Peters <fpeters@0d.be>
Date:   Fri Apr 24 16:08:46 2009 +0200

    improve git support in many ways
    
    Changes to a simpler support of branches; switch from git fetch/git
    rebase to git pull --rebase, only stash when there is a diff, and
    pop afterwards, and no longer use git rev-parse to check for branch
    existance. (GNOME #532673, #549704, #552476 and #564672)