Skip to content

Commit

Permalink
Add reference fallback argument
Browse files Browse the repository at this point in the history
and have it default to `HEAD`
so that the same behavior is kept
while being robust to git rebasing

users can set both reference revision and fallback to the same thing
if they would like the command to error for unresolvable references
  • Loading branch information
ruffsl committed Jul 2, 2021
1 parent e8f7410 commit 0295d39
Showing 1 changed file with 17 additions and 6 deletions.
23 changes: 17 additions & 6 deletions colcon_cache/task/lock/git.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,20 @@ def add_arguments(self, *, parser): # noqa: D102
'--git-reference-revision',
type=str, default=None,
help=(
'Optional choose revision used as a reference. If unset, '
'Optionally specify revision used as a reference. If unset, '
'the reference from the previous lockfile will be reused. '
'If nether provide references, revision defaults to HEAD.'
'If nether provide references, the fallback will be used.'
' View docs for info: https://git-scm.com/docs/gitrevisions'
)
)

parser.add_argument(
'--git-reference-fallback',
type=str, default='HEAD',
help=(
'Override fallback revision used as a reference. If nether '
'the user and the previous lockfile specify a revision, or '
'if reference is unresolvable, this fallback will be used.'
' View docs for info: https://git-scm.com/docs/gitrevisions'
)
)
Expand Down Expand Up @@ -91,13 +102,13 @@ async def lock(self, *, additional_hooks=None): # noqa: D102
def compute_current_checksums(self, args, lockfile): # noqa: D102
repo = Repo(args.path, search_parent_directories=True)

if args.git_reference_revision is None:
reference_commit = repo.commit()
else:
reference_commit = repo.commit(args.git_reference_fallback)
if args.git_reference_revision:
try:
reference_commit = repo.commit(args.git_reference_revision)
except ValueError:
reference_commit = repo.commit()
pass

lockfile.metadata['reference_revision'] = reference_commit.hexsha

diff_args = []
Expand Down

0 comments on commit 0295d39

Please sign in to comment.