| 1 |
# test change of repo url |
| 2 |
# see https://github.com/ansible/ansible-modules-core/pull/721 |
| 3 |
|
| 4 |
- name: CHANGE-REPO-URL | clear checkout_dir |
| 5 |
file: |
| 6 |
state: absent |
| 7 |
path: "{{ checkout_dir }}" |
| 8 |
|
| 9 |
- name: CHANGE-REPO-URL | Clone example git repo |
| 10 |
git: |
| 11 |
repo: "{{ repo_update_url_1 }}" |
| 12 |
dest: "{{ checkout_dir }}" |
| 13 |
|
| 14 |
- name: CHANGE-REPO-URL | Clone repo with changed url to the same place |
| 15 |
git: |
| 16 |
repo: "{{ repo_update_url_2 }}" |
| 17 |
dest: "{{ checkout_dir }}" |
| 18 |
register: clone2 |
| 19 |
|
| 20 |
- assert: |
| 21 |
that: "clone2 is successful" |
| 22 |
|
| 23 |
- name: CHANGE-REPO-URL | check url updated |
| 24 |
shell: git remote show origin | grep Fetch |
| 25 |
register: remote_url |
| 26 |
args: |
| 27 |
chdir: "{{ checkout_dir }}" |
| 28 |
environment: |
| 29 |
LC_ALL: C |
| 30 |
|
| 31 |
- assert: |
| 32 |
that: |
| 33 |
- "'git-test-new' in remote_url.stdout" |
| 34 |
- "'git-test-old' not in remote_url.stdout" |
| 35 |
|
| 36 |
- name: CHANGE-REPO-URL | check for new content in git-test-new |
| 37 |
stat: path={{ checkout_dir }}/newfilename |
| 38 |
register: repo_content |
| 39 |
|
| 40 |
- name: CHANGE-REPO-URL | assert presence of new file in repo (i.e. working copy updated) |
| 41 |
assert: |
| 42 |
that: "repo_content.stat.exists" |
| 43 |
|
| 44 |
# Make sure 'changed' result is accurate in check mode. |
| 45 |
# See https://github.com/ansible/ansible-modules-core/pull/4243 |
| 46 |
|
| 47 |
- name: CHANGE-REPO-URL | clear checkout_dir |
| 48 |
file: |
| 49 |
state: absent |
| 50 |
path: "{{ checkout_dir }}" |
| 51 |
|
| 52 |
- name: CHANGE-REPO-URL | clone repo |
| 53 |
git: |
| 54 |
repo: "{{ repo_update_url_1 }}" |
| 55 |
dest: "{{ checkout_dir }}" |
| 56 |
|
| 57 |
- name: CHANGE-REPO-URL | clone repo with same url to same destination |
| 58 |
git: |
| 59 |
repo: "{{ repo_update_url_1 }}" |
| 60 |
dest: "{{ checkout_dir }}" |
| 61 |
register: checkout_same_url |
| 62 |
|
| 63 |
- name: CHANGE-REPO-URL | check repo not changed |
| 64 |
assert: |
| 65 |
that: |
| 66 |
- checkout_same_url is not changed |
| 67 |
|
| 68 |
|
| 69 |
- name: CHANGE-REPO-URL | clone repo with new url to same destination |
| 70 |
git: |
| 71 |
repo: "{{ repo_update_url_2 }}" |
| 72 |
dest: "{{ checkout_dir }}" |
| 73 |
register: checkout_new_url |
| 74 |
|
| 75 |
- name: CHANGE-REPO-URL | check repo changed |
| 76 |
assert: |
| 77 |
that: |
| 78 |
- checkout_new_url is changed |
| 79 |
|
| 80 |
|
| 81 |
- name: CHANGE-REPO-URL | clone repo with new url in check mode |
| 82 |
git: |
| 83 |
repo: "{{ repo_update_url_1 }}" |
| 84 |
dest: "{{ checkout_dir }}" |
| 85 |
register: checkout_new_url_check_mode |
| 86 |
check_mode: True |
| 87 |
|
| 88 |
- name: CHANGE-REPO-URL | check repo reported changed in check mode |
| 89 |
assert: |
| 90 |
that: |
| 91 |
- checkout_new_url_check_mode is changed |
| 92 |
when: git_version.stdout is version(git_version_supporting_ls_remote, '>=') |
| 93 |
|
| 94 |
- name: CHANGE-REPO-URL | clone repo with new url after check mode |
| 95 |
git: |
| 96 |
repo: "{{ repo_update_url_1 }}" |
| 97 |
dest: "{{ checkout_dir }}" |
| 98 |
register: checkout_new_url_after_check_mode |
| 99 |
|
| 100 |
- name: CHANGE-REPO-URL | check repo still changed after check mode |
| 101 |
assert: |
| 102 |
that: |
| 103 |
- checkout_new_url_after_check_mode is changed |
| 104 |
|
| 105 |
|
| 106 |
# Test that checkout by branch works when the branch is not in our current repo but the sha is |
| 107 |
|
| 108 |
- name: CHANGE-REPO-URL | clear checkout_dir |
| 109 |
file: |
| 110 |
state: absent |
| 111 |
path: "{{ checkout_dir }}" |
| 112 |
|
| 113 |
- name: CHANGE-REPO-URL | "Clone example git repo that we're going to modify" |
| 114 |
git: |
| 115 |
repo: "{{ repo_update_url_1 }}" |
| 116 |
dest: "{{ checkout_dir }}/repo" |
| 117 |
|
| 118 |
- name: CHANGE-REPO-URL | Clone the repo again - this is what we test |
| 119 |
git: |
| 120 |
repo: "{{ checkout_dir }}/repo" |
| 121 |
dest: "{{ checkout_dir }}/checkout" |
| 122 |
|
| 123 |
- name: CHANGE-REPO-URL | Add a branch to the repo |
| 124 |
command: git branch new-branch |
| 125 |
args: |
| 126 |
chdir: "{{ checkout_dir }}/repo" |
| 127 |
|
| 128 |
- name: CHANGE-REPO-URL | Checkout the new branch in the checkout |
| 129 |
git: |
| 130 |
repo: "{{ checkout_dir}}/repo" |
| 131 |
version: 'new-branch' |
| 132 |
dest: "{{ checkout_dir }}/checkout" |