1
0
Fork 0
mirror of https://github.com/ansible-collections/community.general.git synced 2024-09-14 20:13:21 +02:00
community.general/test/integration/targets/git/tasks/change-repo-url.yml
Robin Roth cd02d0ca1d Cleanup git tests (#19737)
* Cleanup git tests
* Split git tests in seperate files
* Remove use of repo_depth_url
* Use native yaml
* Remove unnecessary remote/local clones
* Fix newlines for yamllint
* If the hash is valid (full-length) but doesn't exist, git returns 128 instead of 1.
* Ensure git doesn't use hardlinks for shallow clones
2017-01-06 14:38:53 -08:00

118 lines
3 KiB
YAML

---
# test change of repo url
# see https://github.com/ansible/ansible-modules-core/pull/721
- name: clear checkout_dir
file: state=absent path={{ checkout_dir }}
- name: Clone example git repo
git:
repo: '{{ repo_update_url_1 }}'
dest: '{{ checkout_dir }}'
- name: Clone repo with changed url to the same place
git:
repo: '{{ repo_update_url_2 }}'
dest: '{{ checkout_dir }}'
register: clone2
- assert:
that: "clone2|success"
- name: check url updated
shell: git remote show origin | grep Fetch
register: remote_url
args:
chdir: '{{ checkout_dir }}'
environment:
LC_ALL: C
- assert:
that:
- "'git-test-new' in remote_url.stdout"
- "'git-test-old' not in remote_url.stdout"
- name: check for new content in git-test-new
stat: path={{ checkout_dir }}/newfilename
register: repo_content
- name: assert presence of new file in repo (i.e. working copy updated)
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
file: state=absent path={{ checkout_dir }}
- name: "Clone example git repo that we're going to modify"
git:
repo: '{{ repo_update_url_1 }}'
dest: '{{ checkout_dir }}/repo'
- name: Clone the repo again - this is what we test
git:
repo: '{{ checkout_dir }}/repo'
dest: '{{ checkout_dir }}/checkout'
- name: Add a branch to the repo
command: git branch new-branch
args:
chdir: '{{ checkout_dir }}/repo'
- name: Checkout the new branch in the checkout
git:
repo: '{{ checkout_dir}}/repo'
version: 'new-branch'
dest: '{{ checkout_dir }}/checkout'