Check valid import branch argument value
Report invalid import branch to user when combined with --finish option as the value provided to --import-branch must be a valid reference. Change-Id: Ibd9e52bd4e387e997cb845721e49a91520989298 Closes-Bug: #1625878
This commit is contained in:
parent
0e30d3898b
commit
691ae783e0
|
@ -140,6 +140,13 @@ class ImportCommand(LogDedentMixin, GitUpstreamCommand):
|
|||
import_branch=self.args.import_branch,
|
||||
extra_branches=self.args.branches)
|
||||
|
||||
# perform additional checks requiring git operations
|
||||
if self.args.finish and not import_upstream.is_valid_commit(
|
||||
self.args.import_branch):
|
||||
self.parser.error(
|
||||
"Invalid ref for argument '--import-branch', '%s' not found!"
|
||||
% self.args.import_branch)
|
||||
|
||||
self.log.notice("Searching for previous import")
|
||||
strategy = ImportStrategiesFactory.create_strategy(
|
||||
self.args.strategy, branch=self.args.branch,
|
||||
|
|
|
@ -0,0 +1,75 @@
|
|||
# Copyright (c) 2016 Hewlett Packard Enterprise 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.
|
||||
|
||||
"""Tests for the 'import' command failures"""
|
||||
|
||||
import inspect
|
||||
import os
|
||||
|
||||
import mock
|
||||
from six import moves
|
||||
from testtools import matchers
|
||||
|
||||
from git_upstream import main
|
||||
from git_upstream.tests import base
|
||||
|
||||
|
||||
class TestImportCommandFailure(base.BaseTestCase):
|
||||
|
||||
tree = [
|
||||
["A", []],
|
||||
["B", ["A"]],
|
||||
["C", ["B"]],
|
||||
["D", ["C"]],
|
||||
["E", ["B"]],
|
||||
["F", ["E"]]
|
||||
]
|
||||
|
||||
branches = {
|
||||
'head': ["master", "D"],
|
||||
'upstream': ["upstream/master", "F"]
|
||||
}
|
||||
|
||||
def setUp(self):
|
||||
self.commands, self.parser = main.build_parsers()
|
||||
|
||||
script_cmdline = self.parser.get_default('script_cmdline')
|
||||
script_cmdline[-1] = os.path.join(os.getcwd(), main.__file__)
|
||||
self.parser.set_defaults(script_cmdline=script_cmdline)
|
||||
|
||||
# builds the tree to be tested
|
||||
super(TestImportCommandFailure, self).setUp()
|
||||
|
||||
self.upstream_branch = self.branches['upstream'][0]
|
||||
self.target_branch = self.branches['head'][0]
|
||||
|
||||
def test_invalid_import_branch(self):
|
||||
"""Test that a parser error is returned on an invalid import branch
|
||||
|
||||
Checks that if an invalid import branch is passed as an argument
|
||||
when trying to use the --finish mode that the command will exit
|
||||
with a parser error.
|
||||
"""
|
||||
self.git.tag(inspect.currentframe().f_code.co_name,
|
||||
self.upstream_branch)
|
||||
|
||||
args = self.parser.parse_args(
|
||||
['import', '--finish', '--import-branch', 'invalid',
|
||||
'upstream/master'])
|
||||
with mock.patch('sys.stderr', new_callable=moves.StringIO) as console:
|
||||
self.assertRaises(SystemExit, args.cmd.run, args)
|
||||
self.assertThat(
|
||||
console.getvalue(),
|
||||
matchers.Contains("'invalid' not found!"))
|
Loading…
Reference in New Issue