From 4f77f8a64c479c146890eb4e1a9069be2d5fc49b Mon Sep 17 00:00:00 2001 From: Andreas Lutro Date: Sat, 11 Apr 2015 22:09:41 +0200 Subject: [PATCH] Make git.latest work with empty repositories --- salt/states/git.py | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/salt/states/git.py b/salt/states/git.py index 45b0b6d44e..442a26063c 100644 --- a/salt/states/git.py +++ b/salt/states/git.py @@ -205,11 +205,18 @@ def latest(name, log.debug(('target {0} is found, "git pull" ' 'is probably required'.format(target))) try: - current_rev = __salt__['git.revision'](target, user=user) + 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 - branch = __salt__['git.current_branch'](target, user=user) + 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') - new_rev = __salt__['git.revision'](cwd=target, user=user) + 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(