From 60424196245b7d1f1648ff12c1e54d9317b81b79 Mon Sep 17 00:00:00 2001 From: Ashley Penney Date: Fri, 12 Oct 2012 18:16:37 +0000 Subject: [PATCH 1/2] Check rc instead of parsing for errors. This now catches the case where the remote branch has been deleted and you're still trying to pull against it. --- library/git | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/library/git b/library/git index 5395f516a96..6b5b5039bf1 100755 --- a/library/git +++ b/library/git @@ -155,7 +155,7 @@ def pull(module, repo, dest, version): if b.startswith('* '): cur_branch = b if is_local_branch(module, dest, version) and not is_current_branch(module, dest, version): - (out, err) = switch_version(module, dest, remote, version) + (rc, out, err) = switch_version(module, dest, remote, version) cmd = "git pull -u origin" cmd = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE) @@ -219,9 +219,11 @@ def main(): if rc != 0: module.fail_json(msg=err) (rc, out, err) = pull(module, repo, dest, version) + if rc != 0: + module.fail_json(msg=err) # handle errors from clone or pull - if out.find('error') != -1 or err.find('ERROR') != -1: + if rc != 0: module.fail_json(msg=err) # switch to version specified regardless of whether From f4484f800b872d628566e67a216f5fe9cddd94ac Mon Sep 17 00:00:00 2001 From: Ashley Penney Date: Fri, 12 Oct 2012 18:26:40 +0000 Subject: [PATCH 2/2] Further cleanup to add another rc check and remove a now redundent one. --- library/git | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/library/git b/library/git index 6b5b5039bf1..89affbba115 100755 --- a/library/git +++ b/library/git @@ -156,6 +156,8 @@ def pull(module, repo, dest, version): cur_branch = b if is_local_branch(module, dest, version) and not is_current_branch(module, dest, version): (rc, out, err) = switch_version(module, dest, remote, version) + if rc != 0: + module.fail_json(msg=err) cmd = "git pull -u origin" cmd = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE) @@ -222,10 +224,6 @@ def main(): if rc != 0: module.fail_json(msg=err) - # handle errors from clone or pull - if rc != 0: - module.fail_json(msg=err) - # switch to version specified regardless of whether # we cloned or pulled (rc, out, err) = switch_version(module, dest, remote, version)