Merge pull request #22553 from alprs/fix-git_latest_empty

Make git.latest work with empty source repositories
This commit is contained in:
Thomas S Hatch 2015-04-13 14:12:04 -06:00
commit bd83b6c0b5

View File

@ -204,12 +204,19 @@ def latest(name,
# git pull is probably required
log.debug(('target {0} is found, "git pull" '
'is probably required'.format(target)))
try:
try:
current_rev = __salt__['git.revision'](target, user=user)
except CommandExecutionError:
current_rev = None
# handle the case where a branch was provided for rev
remote_rev, new_rev = None, None
try:
branch = __salt__['git.current_branch'](target, user=user)
except CommandExecutionError:
branch = None
# We're only interested in the remote branch if a branch
# (instead of a hash, for example) was provided for rev.
if (branch != 'HEAD' and branch == rev) or rev is None:
@ -309,7 +316,10 @@ def latest(name,
identity=identity,
opts='--recursive')
try:
new_rev = __salt__['git.revision'](cwd=target, user=user)
except CommandExecutionError:
new_rev = None
except Exception as exc:
return _fail(
ret,
@ -369,8 +379,12 @@ def latest(name,
identity=identity,
opts='--recursive')
new_rev = None if bare else (
__salt__['git.revision'](cwd=target, user=user))
new_rev = None
if not bare:
try:
new_rev = __salt__['git.revision'](cwd=target, user=user)
except CommandExecutionError:
pass
except Exception as exc:
return _fail(