From be781cc50b92b8ca0b748be09e96c6bc0f1a9493 Mon Sep 17 00:00:00 2001 From: Darragh Bailey Date: Tue, 27 Sep 2016 17:52:41 +0100 Subject: [PATCH] Support tags for input args Enable users to specify tags to be used to import and reference commits. Change-Id: If2a9a2fa52d6c34ab110ae7a7fdbd02fae82e3b9 Closes-Bug: #1547180 --- git_upstream/lib/searchers.py | 2 +- git_upstream/lib/strategies.py | 4 ++-- .../tests/commands/import/test_import.py | 18 ++++++++++++++++++ 3 files changed, 21 insertions(+), 3 deletions(-) diff --git a/git_upstream/lib/searchers.py b/git_upstream/lib/searchers.py index 3a1280c..205625c 100644 --- a/git_upstream/lib/searchers.py +++ b/git_upstream/lib/searchers.py @@ -304,7 +304,7 @@ class UpstreamMergeBaseSearcher(LogDedentMixin, Searcher): ["refs/remotes/*/{0}".format(ref) for ref in self.patterns]) if search_tags: - self._references.append( + self._references.extend( ["refs/tags/{0}".format(ref) for ref in self.patterns]) @property diff --git a/git_upstream/lib/strategies.py b/git_upstream/lib/strategies.py index 6142431..02c7bc0 100644 --- a/git_upstream/lib/strategies.py +++ b/git_upstream/lib/strategies.py @@ -116,8 +116,8 @@ class LocateChangesWalk(LocateChangesStrategy): super(LocateChangesWalk, self).__init__(*args, **kwargs) - self.searcher = UpstreamMergeBaseSearcher(branch=branch, - patterns=search_refs) + self.searcher = UpstreamMergeBaseSearcher( + branch=branch, patterns=search_refs, search_tags=True) @property def previous_upstream(self): diff --git a/git_upstream/tests/commands/import/test_import.py b/git_upstream/tests/commands/import/test_import.py index 6ceff8d..226a913 100644 --- a/git_upstream/tests/commands/import/test_import.py +++ b/git_upstream/tests/commands/import/test_import.py @@ -101,6 +101,24 @@ class TestImportCommand(TestWithScenarios, BaseTestCase): self._check_tree_state() + def test_command_with_tags(self): + # add tag for each branch/ref and test with added tag + parser_args = [] + for arg in self.parser_args: + if (arg.startswith('-') or arg in ("import",)): + parser_args.append(arg) + continue + + tag_name = "tag-gu-%s" % arg.replace('~', '-') + self.git.tag(tag_name, arg) + parser_args.append(tag_name) + + args = self.parser.parse_args(parser_args) + self.assertThat(args.cmd.run(args), Equals(True), + "import command failed to complete successfully") + + self._check_tree_state() + def _check_tree_state(self): expected = getattr(self, 'expect_found', None)