Skip to content
This repository has been archived by the owner on Oct 30, 2018. It is now read-only.

Commit

Permalink
Fix UnboundLocalError remote_head in git (#19057)
Browse files Browse the repository at this point in the history
* 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 afca957)
  • Loading branch information
abadger committed Dec 14, 2016
1 parent 48a3ce1 commit 59a334c
Showing 1 changed file with 14 additions and 21 deletions.
35 changes: 14 additions & 21 deletions source_control/git.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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
Expand All @@ -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:
Expand All @@ -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:
Expand All @@ -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:
Expand Down

0 comments on commit 59a334c

Please sign in to comment.