From e231483adc26a25e3fa3428e98a453de1023d3ed Mon Sep 17 00:00:00 2001 From: Darragh Bailey Date: Mon, 4 Jul 2016 11:25:02 +0100 Subject: [PATCH] Handle all local changes landed upstream Allow importing an upstream that contains all local changes by simply merging to replace the existing target with the upstream branch given. In certain workflows it is possible for the local changes to have all landed upstream. In such a case, applying of the changes carried should detect there is nothing to apply and create import branch to point to the upstream branch to allow the standard finish actions to complete. Change-Id: I61ae706f2b240a0e2590e03d2e83db97dafdf962 Closes-Bug: #1367985 --- git_upstream/lib/importupstream.py | 5 +- .../import_everything_already_upstreamed.yaml | 48 +++++++++++++++++++ .../tests/commands/import/test_import.py | 11 +++++ 3 files changed, 62 insertions(+), 2 deletions(-) create mode 100644 git_upstream/tests/commands/import/scenarios/import_everything_already_upstreamed.yaml diff --git a/git_upstream/lib/importupstream.py b/git_upstream/lib/importupstream.py index bdb9d72..4426ba9 100644 --- a/git_upstream/lib/importupstream.py +++ b/git_upstream/lib/importupstream.py @@ -269,8 +269,9 @@ class ImportUpstream(LogDedentMixin, GitMixin): commit_list = list(strategy.filtered_iter()) if len(commit_list) == 0: - self.log.notice("There are no local changes to be applied!") - return False + self.log.notice("All carried changes gone upstream") + self._set_branch(self.import_branch, self.upstream, force=True) + return True self.log.debug( """ diff --git a/git_upstream/tests/commands/import/scenarios/import_everything_already_upstreamed.yaml b/git_upstream/tests/commands/import/scenarios/import_everything_already_upstreamed.yaml new file mode 100644 index 0000000..93c92de --- /dev/null +++ b/git_upstream/tests/commands/import/scenarios/import_everything_already_upstreamed.yaml @@ -0,0 +1,48 @@ +# +# Copyright (c) 2016 Hewlett-Packard Enterprise Development Company, L.P. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or +# implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +--- +- desc: | + Test importing where everything is upstreamed + + Checks that importing an upstream where all local changes have + gone upstream, will correctly replace the local master with + the latest upstream branch. + + C---D local/master + / + A---B---E---C1--D1 upstream/master + + tree: + - [A, []] + - [B, [A]] + - [C, [B]] + - [D, [C]] + - [C1, [E]] + - [D1, [C1]] + - [E, [B]] + + branches: + head: [master, D] + upstream: [upstream/master, D1] + + parser_args: + - -q + - import + - --into=master + - upstream/master + + expect_found: [] diff --git a/git_upstream/tests/commands/import/test_import.py b/git_upstream/tests/commands/import/test_import.py index 70bb914..c3dff15 100644 --- a/git_upstream/tests/commands/import/test_import.py +++ b/git_upstream/tests/commands/import/test_import.py @@ -124,3 +124,14 @@ class TestImportCommand(TestWithScenarios, BaseTestCase): self.assertThat( self.logger.output, Contains("No updated additional branch given, nothing to be done")) + + def _verify_import_everything_already_upstreamed(self): + """Additional verification for the finished results""" + + self.assertThat( + self.logger.output, + Contains("All carried changes gone upstream")) + self.assertThat( + self.logger.output, + Contains("Creating branch 'import/test_command' from specified " + "commit 'upstream/master'"))