diff --git a/salt/states/git.py b/salt/states/git.py index 0654d46d190e..428d256b41b9 100644 --- a/salt/states/git.py +++ b/salt/states/git.py @@ -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: