diff options
author | Toshio Kuratomi <a.badger@gmail.com> | 2016-12-14 08:43:01 -0800 |
---|---|---|
committer | Toshio Kuratomi <a.badger@gmail.com> | 2016-12-14 08:43:47 -0800 |
commit | 59a334c621abc2fbb82710e4d0f483b1816e4353 (patch) | |
tree | 9008199eed2a6b75f6430218e4d34d2897c4fe26 | |
parent | 48a3ce12234c663f6e2b60be2b9f0cba9323a203 (diff) | |
download | ansible-modules-core-59a334c621abc2fbb82710e4d0f483b1816e4353.tar.gz |
Fix UnboundLocalError remote_head in git (#19057)
* Fix UnboundLocalError remote_head in git
Fixes #5505
The use of remote_head was a leftover of #4562.
remote_head is not necessary, since the repo is unchanged anyway and
after is set correctly.
Further changes:
* Set changed=True and msg once local_mods are detected and reset.
* Remove need_fetch that is always True (due to previous if) to improve
clarity
* Don't exit early for local_mods but run submodules update and
switch_version
* Add test for git with local modifications
(cherry picked from afca95739630891d5678d362362877270ae2e80e)
-rw-r--r-- | source_control/git.py | 35 |
1 files changed, 14 insertions, 21 deletions
diff --git a/source_control/git.py b/source_control/git.py index 06965f03..7f0fcd86 100644 --- a/source_control/git.py +++ b/source_control/git.py @@ -871,7 +871,7 @@ def main(): ssh_opts = module.params['ssh_opts'] umask = module.params['umask'] - result = dict( warnings=list() ) + result = dict(changed = False, warnings=list()) # evaluate and set the umask before doing anything else if umask is not None: @@ -951,7 +951,7 @@ def main(): # this does no checking that the repo is the actual repo # requested. result['before'] = get_version(module, git_path, dest) - result.update(changed=False, after=result['before']) + result.update(after=result['before']) module.exit_json(**result) else: # else do a pull @@ -964,6 +964,7 @@ def main(): # if force and in non-check mode, do a reset if not module.check_mode: reset(git_path, module, dest) + result.update(changed=True, msg='Local modifications exist.') # exit if already at desired sha version if module.check_mode: @@ -974,27 +975,20 @@ def main(): if remote_url_changed: result.update(remote_url_changed=True) - if need_fetch: - if module.check_mode: - remote_head = get_remote_head(git_path, module, dest, version, remote, bare) - result.update(changed=(result['before'] != remote_head), after=remote_head) - # FIXME: This diff should fail since the new remote_head is not fetched yet?! - if module._diff: - diff = get_diff(module, git_path, dest, repo, remote, depth, bare, result['before'], result['after']) - if diff: - result['diff'] = diff - module.exit_json(**result) - else: - fetch(git_path, module, repo, dest, version, remote, depth, bare, refspec, git_version_used) + if module.check_mode: + remote_head = get_remote_head(git_path, module, dest, version, remote, bare) + result.update(changed=(result['before'] != remote_head), after=remote_head) + # FIXME: This diff should fail since the new remote_head is not fetched yet?! + if module._diff: + diff = get_diff(module, git_path, dest, repo, remote, depth, bare, result['before'], result['after']) + if diff: + result['diff'] = diff + module.exit_json(**result) + else: + fetch(git_path, module, repo, dest, version, remote, depth, bare, refspec, git_version_used) result['after'] = get_version(module, git_path, dest) - if result['before'] == result['after']: - if local_mods: - result.update(changed=True, after=remote_head, msg='Local modifications exist') - # no diff, since the repo didn't change - module.exit_json(**result) - # switch to version specified regardless of whether # we got new revisions from the repository if not bare: @@ -1017,7 +1011,6 @@ def main(): # determine if we changed anything result['after'] = get_version(module, git_path, dest) - result.update(changed=False) if result['before'] != result['after'] or local_mods or submodules_updated or remote_url_changed: result.update(changed=True) if module._diff: |