From ff03bec0707b4566a4f0e0228a942c1ceedab662 Mon Sep 17 00:00:00 2001 From: Guido Günther Date: Sun, 12 Nov 2017 17:48:03 +0100 Subject: 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 --- gbp/git/repository.py | 10 +++++----- tests/09_test_git_repository.py | 10 ++++++++++ 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\:·: -- cgit v1.2.3