allow tracking branch names when the branches only exist on origin

Fix a problem with branch references so that it is now possible to use a
local tracking branch name when the branch only exists on the 'origin'
remote. For example, this allows references to 'stable/ocata' when there
is no local branch with that name but there is an 'origin/stable/ocata'
branch.

Change-Id: If11a0ff10ad3b1dfc82f99e6f68684ec9268af26
Signed-off-by: Doug Hellmann <doug@doughellmann.com>
This commit is contained in:
Doug Hellmann 2017-03-02 09:27:44 -05:00
parent 65a82c37d2
commit 2e9cd7cfe5
3 changed files with 48 additions and 0 deletions

View File

@ -0,0 +1,8 @@
---
fixes:
- |
Fix a problem with branch references so that it is now possible to
use a local tracking branch name when the branch only exists on
the 'origin' remote. For example, this allows references to
'stable/ocata' when there is no local branch with that name but
there is an 'origin/stable/ocata' branch.

View File

@ -487,6 +487,10 @@ class Scanner(object):
'refs/tags/' + name,
# If a stable branch was removed, look for its EOL tag.
'refs/tags/' + (name.rpartition('/')[-1] + '-eol'),
# If someone is using the "short" name for a branch
# without a local tracking branch, look to see if the
# name exists on the 'origin' remote.
'refs/remotes/origin/' + name,
]
for ref in candidates:
key = ref.encode('utf-8')

View File

@ -1416,6 +1416,42 @@ class BranchTest(Base):
self.assertIsNotNone(head2)
self.assertEqual(head1, head2)
def test_remote_branch_without_prefix(self):
self.repo.git('checkout', '2.0.0')
self.repo.git('checkout', '-b', 'stable/2')
self.repo.git('checkout', 'master')
scanner1 = scanner.Scanner(self.c)
head1 = scanner1._get_ref('stable/2')
self.assertIsNotNone(head1)
print('head1', head1)
# Create a second repository by cloning the first.
print(utils.check_output(
['git', 'clone', self.reporoot, 'reporoot2'],
cwd=self.temp_dir,
))
reporoot2 = os.path.join(self.temp_dir, 'reporoot2')
print(utils.check_output(
['git', 'remote', 'update'],
cwd=reporoot2,
))
print(utils.check_output(
['git', 'remote', '-v'],
cwd=reporoot2,
))
print(utils.check_output(
['find', '.git/refs'],
cwd=reporoot2,
))
print(utils.check_output(
['git', 'branch', '-a'],
cwd=reporoot2,
))
c2 = config.Config(reporoot2)
scanner2 = scanner.Scanner(c2)
head2 = scanner2._get_ref('stable/2')
self.assertIsNotNone(head2)
self.assertEqual(head1, head2)
class ScanStopPointPrereleaseVersionsTest(Base):