kas: Support --force-checkout argument
When checking out a repository the default behaviour is to abort if local changes are present. If the new `--force-checkout` argument is passed on the command line then any local changes will instead be discarded so that the desired refspec can be checked out. Signed-off-by: Paul Barker <pbarker@konsulko.com> Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
This commit is contained in:
parent
90598db3c8
commit
1569895001
@ -126,3 +126,7 @@ class Context:
|
|||||||
The reference directory for the repo
|
The reference directory for the repo
|
||||||
"""
|
"""
|
||||||
return self.__kas_repo_ref_dir
|
return self.__kas_repo_ref_dir
|
||||||
|
|
||||||
|
@property
|
||||||
|
def force_checkout(self):
|
||||||
|
return getattr(self.args, 'force_checkout', None)
|
||||||
|
@ -106,6 +106,9 @@ def setup_parser_common_args(parser):
|
|||||||
parser.add_argument('--skip',
|
parser.add_argument('--skip',
|
||||||
help='Skip build steps',
|
help='Skip build steps',
|
||||||
default=[])
|
default=[])
|
||||||
|
parser.add_argument('--force-checkout', action='store_true',
|
||||||
|
help='Always checkout the desired refspec of each '
|
||||||
|
'repository, discarding any local changes')
|
||||||
|
|
||||||
def kas_get_argparser():
|
def kas_get_argparser():
|
||||||
"""
|
"""
|
||||||
|
22
kas/repos.py
22
kas/repos.py
@ -221,13 +221,14 @@ class RepoImpl(Repo):
|
|||||||
if self.operations_disabled or self.refspec is None:
|
if self.operations_disabled or self.refspec is None:
|
||||||
return
|
return
|
||||||
|
|
||||||
# Check if repos is dirty
|
if not get_context().force_checkout:
|
||||||
(_, output) = run_cmd(self.is_dirty_cmd(),
|
# Check if repos is dirty
|
||||||
cwd=self.path,
|
(_, output) = run_cmd(self.is_dirty_cmd(),
|
||||||
fail=False)
|
cwd=self.path,
|
||||||
if output:
|
fail=False)
|
||||||
logging.warning('Repo %s is dirty - no checkout', self.name)
|
if output:
|
||||||
return
|
logging.warning('Repo %s is dirty - no checkout', self.name)
|
||||||
|
return
|
||||||
|
|
||||||
(_, output) = run_cmd(self.resolve_branch_cmd(),
|
(_, output) = run_cmd(self.resolve_branch_cmd(),
|
||||||
cwd=self.path, fail=False)
|
cwd=self.path, fail=False)
|
||||||
@ -359,6 +360,8 @@ class GitRepo(RepoImpl):
|
|||||||
cmd = ['git', 'checkout', '-q', desired_ref]
|
cmd = ['git', 'checkout', '-q', desired_ref]
|
||||||
if branch:
|
if branch:
|
||||||
cmd.extend(['-B', self.refspec])
|
cmd.extend(['-B', self.refspec])
|
||||||
|
if get_context().force_checkout:
|
||||||
|
cmd.append('--force')
|
||||||
return cmd
|
return cmd
|
||||||
|
|
||||||
def prepare_patches_cmd(self):
|
def prepare_patches_cmd(self):
|
||||||
@ -400,7 +403,10 @@ class MercurialRepo(RepoImpl):
|
|||||||
return ['false']
|
return ['false']
|
||||||
|
|
||||||
def checkout_cmd(self, desired_ref, branch):
|
def checkout_cmd(self, desired_ref, branch):
|
||||||
return ['hg', 'checkout', desired_ref]
|
cmd = ['hg', 'checkout', desired_ref]
|
||||||
|
if get_context().force_checkout:
|
||||||
|
cmd.append('--clean')
|
||||||
|
return cmd
|
||||||
|
|
||||||
def prepare_patches_cmd(self):
|
def prepare_patches_cmd(self):
|
||||||
return ['hg', 'branch', '-f',
|
return ['hg', 'branch', '-f',
|
||||||
|
Loading…
Reference in New Issue
Block a user