diff --git a/releasenotes/notes/allow-short-branch-names-61a35be55f04cea4.yaml b/releasenotes/notes/allow-short-branch-names-61a35be55f04cea4.yaml new file mode 100644 index 0000000..280ce62 --- /dev/null +++ b/releasenotes/notes/allow-short-branch-names-61a35be55f04cea4.yaml @@ -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. \ No newline at end of file diff --git a/reno/scanner.py b/reno/scanner.py index 73df536..ef7dade 100644 --- a/reno/scanner.py +++ b/reno/scanner.py @@ -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') diff --git a/reno/tests/test_scanner.py b/reno/tests/test_scanner.py index 6fe08dd..2d5f923 100644 --- a/reno/tests/test_scanner.py +++ b/reno/tests/test_scanner.py @@ -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):