Add tests for Git remote URL changes (#16893)

* Update Git tests for set remote URL changes
* Git: report changed when needed in check mode
This commit is contained in:
Rob Cutmore 2016-12-22 16:46:47 -05:00 committed by Matt Clay
parent 438cd6687f
commit 1da6a67c50
2 changed files with 51 additions and 1 deletions

View file

@ -993,7 +993,7 @@ def main():
if module.check_mode: if module.check_mode:
remote_head = get_remote_head(git_path, module, dest, version, remote, bare) remote_head = get_remote_head(git_path, module, dest, version, remote, bare)
result.update(changed=(result['before'] != remote_head), after=remote_head) result.update(changed=(result['before'] != remote_head or remote_url_changed), after=remote_head)
# FIXME: This diff should fail since the new remote_head is not fetched yet?! # FIXME: This diff should fail since the new remote_head is not fetched yet?!
if module._diff: if module._diff:
diff = get_diff(module, git_path, dest, repo, remote, depth, bare, result['before'], result['after']) diff = get_diff(module, git_path, dest, repo, remote, depth, bare, result['before'], result['after'])

View file

@ -36,6 +36,7 @@
- "{{ lookup('env','HOME') }}/.ssh/known_hosts" - "{{ lookup('env','HOME') }}/.ssh/known_hosts"
- '/etc/ssh/ssh_known_hosts' - '/etc/ssh/ssh_known_hosts'
git_version_supporting_depth: 1.9.1 git_version_supporting_depth: 1.9.1
git_version_supporting_ls_remote: 1.7.5
- name: clean out the output_dir - name: clean out the output_dir
shell: rm -rf {{ output_dir }}/* shell: rm -rf {{ output_dir }}/*
@ -442,6 +443,55 @@
assert: assert:
that: "repo_content.stat.exists" that: "repo_content.stat.exists"
# Make sure 'changed' result is accurate in check mode.
# See https://github.com/ansible/ansible-modules-core/pull/4243
- name: clear checkout_dir
file: state=absent path={{ checkout_dir }}
- name: clone repo
git: repo={{ repo_update_url_1 }} dest={{ checkout_dir }}
- name: clone repo with same url to same destination
git: repo={{ repo_update_url_1 }} dest={{ checkout_dir }}
register: checkout_same_url
- name: check repo not changed
assert:
that:
- not checkout_same_url|changed
- name: clone repo with new url to same destination
git: repo={{ repo_update_url_2 }} dest={{ checkout_dir }}
register: checkout_new_url
- name: check repo changed
assert:
that:
- checkout_new_url|changed
- name: clone repo with new url in check mode
git: repo={{ repo_update_url_1 }} dest={{ checkout_dir }}
register: checkout_new_url_check_mode
check_mode: True
- name: check repo reported changed in check mode
assert:
that:
- checkout_new_url_check_mode|changed
when: git_version.stdout | version_compare("{{git_version_supporting_ls_remote}}", '>=')
- name: clone repo with new url after check mode
git: repo={{ repo_update_url_1 }} dest={{ checkout_dir }}
register: checkout_new_url_after_check_mode
- name: check repo still changed after check mode
assert:
that:
- checkout_new_url_after_check_mode|changed
# Test that checkout by branch works when the branch is not in our current repo but the sha is # Test that checkout by branch works when the branch is not in our current repo but the sha is
- name: clear checkout_dir - name: clear checkout_dir