Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add tests for Git remote URL changes #16893

Merged
merged 7 commits into from
Dec 22, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/ansible/modules/source_control/git.py
Original file line number Diff line number Diff line change
Expand Up @@ -993,7 +993,7 @@ def main():

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)
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?!
if module._diff:
diff = get_diff(module, git_path, dest, repo, remote, depth, bare, result['before'], result['after'])
Expand Down
50 changes: 50 additions & 0 deletions test/integration/targets/git/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
- "{{ lookup('env','HOME') }}/.ssh/known_hosts"
- '/etc/ssh/ssh_known_hosts'
git_version_supporting_depth: 1.9.1
git_version_supporting_ls_remote: 1.7.5

- name: clean out the output_dir
shell: rm -rf {{ output_dir }}/*
Expand Down Expand Up @@ -442,6 +443,55 @@
assert:
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

- name: clear checkout_dir
Expand Down