Skip to content

Commit

Permalink
Merge pull request #43178 from terminalmage/issue43143
Browse files Browse the repository at this point in the history
git.detached: Fix traceback when rev is a SHA and is not present locally
  • Loading branch information
Nicole Thomas committed Aug 25, 2017
2 parents 12e9507 + 2640833 commit ace2715
Showing 1 changed file with 15 additions and 10 deletions.
25 changes: 15 additions & 10 deletions salt/states/git.py
Expand Up @@ -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
Expand All @@ -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,
Expand Down Expand Up @@ -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:
Expand Down

0 comments on commit ace2715

Please sign in to comment.