summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorGuido Günther <agx@sigxcpu.org>2017-11-12 17:48:03 +0100
committerGuido Günther <agx@sigxcpu.org>2017-11-12 17:48:03 +0100
commitff03bec0707b4566a4f0e0228a942c1ceedab662 (patch)
treef1fdf433566594084573654cf6481fe00c025926
parentb775e36d5589b1ab0ce429c76ad4b68c5b476a95 (diff)
GitRepository: require an exact ref path when looking for branches
Otherwise we might match on refs/heads/refs/heads/foo instead of refs/heads/foo when looking for branch named 'foo' Closes: #813298
-rw-r--r--gbp/git/repository.py10
-rw-r--r--tests/09_test_git_repository.py10
2 files changed, 15 insertions, 5 deletions
diff --git a/gbp/git/repository.py b/gbp/git/repository.py
index aeaa5a36..a7524a4d 100644
--- a/gbp/git/repository.py
+++ b/gbp/git/repository.py
@@ -402,12 +402,12 @@ class GitRepository(object):
@return: C{True} if the repository has this branch, C{False} otherwise
@rtype: C{bool}
"""
- if remote:
- ref = 'refs/remotes/%s' % branch
- else:
- ref = 'refs/heads/%s' % branch
+ args = GitArgs('--verify')
+
+ branch_pattern = 'refs/remotes/%s' if remote else 'refs/heads/%s'
+ args.add(branch_pattern % branch)
try:
- self._git_command('show-ref', [ref])
+ self._git_command('show-ref', args.args)
except GitRepositoryError:
return False
return True
diff --git a/tests/09_test_git_repository.py b/tests/09_test_git_repository.py
index 8d9eeceb..3f032470 100644
--- a/tests/09_test_git_repository.py
+++ b/tests/09_test_git_repository.py
@@ -70,4 +70,14 @@ class TestWriteTree(testutils.DebianGitTestRepo):
with self.assertRaises(gbp.errors.GbpError):
self.repo.commit_tree(sha1, "failed commit", ['doesnotexist'])
+
+class TestHasBranch(testutils.DebianGitTestRepo):
+ def test_has_branch(self):
+ self.add_file('whatever')
+ self.repo.create_branch("foo")
+ self.assertTrue(self.repo.has_branch("foo"))
+ # Don't be too sloppy on (#813298)
+ self.repo.create_branch("refs/heads/bar")
+ self.assertFalse(self.repo.has_branch("bar"))
+
# vim:et:ts=4:sw=4:et:sts=4:ai:set list listchars=tab\:»·,trail\:·: