mirror of
https://github.com/saltstack/salt.git
synced 2025-04-17 10:10:20 +00:00
git.detached: Fix traceback when rev is a SHA and is not present locally
This catches the (expected) CommandExecutionError when git.describe is run on a commit that doesn't exist. This also renames the remote_ref_type variable to remote_rev_type. This change was made for the 2017.7 branch, but this fix is being applied to 2016.11, so by making the rename here as well we will avoid a potential bug from creeping in on a merge-forward.
This commit is contained in:
parent
669b376abf
commit
2640833400
1 changed files with 15 additions and 10 deletions
|
@ -2221,11 +2221,11 @@ def detached(name,
|
|||
return ret
|
||||
|
||||
# Determine if supplied ref is a hash
|
||||
remote_ref_type = 'ref'
|
||||
remote_rev_type = 'ref'
|
||||
if len(ref) <= 40 \
|
||||
and all(x in string.hexdigits for x in ref):
|
||||
ref = ref.lower()
|
||||
remote_ref_type = 'hash'
|
||||
remote_rev_type = 'hash'
|
||||
|
||||
comments = []
|
||||
hash_exists_locally = False
|
||||
|
@ -2238,13 +2238,18 @@ def detached(name,
|
|||
|
||||
local_commit_id = _get_local_rev_and_branch(target, user, password)[0]
|
||||
|
||||
if remote_ref_type is 'hash' \
|
||||
and __salt__['git.describe'](target,
|
||||
ref,
|
||||
user=user,
|
||||
password=password):
|
||||
# The ref is a hash and it exists locally so skip to checkout
|
||||
hash_exists_locally = True
|
||||
if remote_rev_type is 'hash':
|
||||
try:
|
||||
__salt__['git.describe'](target,
|
||||
ref,
|
||||
user=user,
|
||||
password=password,
|
||||
ignore_retcode=True)
|
||||
except CommandExecutionError:
|
||||
hash_exists_locally = False
|
||||
else:
|
||||
# The rev is a hash and it exists locally so skip to checkout
|
||||
hash_exists_locally = True
|
||||
else:
|
||||
# Check that remote is present and set to correct url
|
||||
remotes = __salt__['git.remotes'](target,
|
||||
|
@ -2409,7 +2414,7 @@ def detached(name,
|
|||
|
||||
#get refs and checkout
|
||||
checkout_commit_id = ''
|
||||
if remote_ref_type is 'hash':
|
||||
if remote_rev_type is 'hash':
|
||||
if __salt__['git.describe'](target, ref, user=user, password=password):
|
||||
checkout_commit_id = ref
|
||||
else:
|
||||
|
|
Loading…
Add table
Reference in a new issue