| 1 |
# Test the depth option and fetching revisions that were ignored first |
| 2 |
|
| 3 |
- name: DEPTH | clear checkout_dir |
| 4 |
file: |
| 5 |
state: absent |
| 6 |
path: "{{ checkout_dir }}" |
| 7 |
|
| 8 |
- name: DEPTH | Clone example git repo with depth 1 |
| 9 |
git: |
| 10 |
repo: 'file://{{ repo_dir|expanduser }}/shallow' |
| 11 |
dest: '{{ checkout_dir }}' |
| 12 |
depth: 1 |
| 13 |
|
| 14 |
- name: DEPTH | try to access earlier commit |
| 15 |
command: "git checkout {{git_shallow_head_1.stdout}}" |
| 16 |
register: checkout_early |
| 17 |
failed_when: False |
| 18 |
args: |
| 19 |
chdir: '{{ checkout_dir }}' |
| 20 |
|
| 21 |
- name: DEPTH | make sure the old commit was not fetched |
| 22 |
assert: |
| 23 |
that: 'checkout_early.rc != 0' |
| 24 |
when: git_version.stdout is version(git_version_supporting_depth, '>=') |
| 25 |
|
| 26 |
# tests https://github.com/ansible/ansible/issues/14954 |
| 27 |
- name: DEPTH | fetch repo again with depth=1 |
| 28 |
git: |
| 29 |
repo: 'file://{{ repo_dir|expanduser }}/shallow' |
| 30 |
dest: '{{ checkout_dir }}' |
| 31 |
depth: 1 |
| 32 |
register: checkout2 |
| 33 |
|
| 34 |
- assert: |
| 35 |
that: "checkout2 is not changed" |
| 36 |
when: git_version.stdout is version(git_version_supporting_depth, '>=') |
| 37 |
|
| 38 |
- name: DEPTH | again try to access earlier commit |
| 39 |
shell: "git checkout {{git_shallow_head_1.stdout}}" |
| 40 |
register: checkout_early |
| 41 |
failed_when: False |
| 42 |
args: |
| 43 |
chdir: '{{ checkout_dir }}' |
| 44 |
|
| 45 |
- name: DEPTH | again make sure the old commit was not fetched |
| 46 |
assert: |
| 47 |
that: 'checkout_early.rc != 0' |
| 48 |
when: git_version.stdout is version(git_version_supporting_depth, '>=') |
| 49 |
|
| 50 |
# make sure we are still able to fetch other versions |
| 51 |
- name: DEPTH | Clone same repo with older version |
| 52 |
git: |
| 53 |
repo: 'file://{{ repo_dir|expanduser }}/shallow' |
| 54 |
dest: '{{ checkout_dir }}' |
| 55 |
depth: 1 |
| 56 |
version: earlytag |
| 57 |
register: cloneold |
| 58 |
|
| 59 |
- assert: |
| 60 |
that: cloneold is successful |
| 61 |
|
| 62 |
- name: DEPTH | try to access earlier commit |
| 63 |
shell: "git checkout {{git_shallow_head_1.stdout}}" |
| 64 |
args: |
| 65 |
chdir: '{{ checkout_dir }}' |
| 66 |
|
| 67 |
- name: DEPTH | clear checkout_dir |
| 68 |
file: |
| 69 |
state: absent |
| 70 |
path: "{{ checkout_dir }}" |
| 71 |
|
| 72 |
# Test for https://github.com/ansible/ansible/issues/21316 |
| 73 |
- name: DEPTH | Shallow clone with tag |
| 74 |
git: |
| 75 |
repo: 'file://{{ repo_dir|expanduser }}/shallow' |
| 76 |
dest: '{{ checkout_dir }}' |
| 77 |
depth: 1 |
| 78 |
version: earlytag |
| 79 |
register: cloneold |
| 80 |
|
| 81 |
- assert: |
| 82 |
that: cloneold is successful |
| 83 |
|
| 84 |
- name: DEPTH | clear checkout_dir |
| 85 |
file: |
| 86 |
state: absent |
| 87 |
path: "{{ checkout_dir }}" |
| 88 |
|
| 89 |
|
| 90 |
# Test for https://github.com/ansible/ansible-modules-core/issues/3456 |
| 91 |
# clone a repo with depth and version specified |
| 92 |
|
| 93 |
- name: DEPTH | clone repo with both version and depth specified |
| 94 |
git: |
| 95 |
repo: 'file://{{ repo_dir|expanduser }}/shallow' |
| 96 |
dest: '{{ checkout_dir }}' |
| 97 |
depth: 1 |
| 98 |
version: >- |
| 99 |
{{ git_default_branch }} |
| 100 |
|
| 101 |
- name: DEPTH | run a second time (now fetch, not clone) |
| 102 |
git: |
| 103 |
repo: 'file://{{ repo_dir|expanduser }}/shallow' |
| 104 |
dest: '{{ checkout_dir }}' |
| 105 |
depth: 1 |
| 106 |
version: >- |
| 107 |
{{ git_default_branch }} |
| 108 |
register: git_fetch |
| 109 |
|
| 110 |
- name: DEPTH | ensure the fetch succeeded |
| 111 |
assert: |
| 112 |
that: git_fetch is successful |
| 113 |
|
| 114 |
|
| 115 |
- name: DEPTH | clear checkout_dir |
| 116 |
file: |
| 117 |
state: absent |
| 118 |
path: "{{ checkout_dir }}" |
| 119 |
|
| 120 |
- name: DEPTH | clone repo with both version and depth specified |
| 121 |
git: |
| 122 |
repo: 'file://{{ repo_dir|expanduser }}/shallow' |
| 123 |
dest: '{{ checkout_dir }}' |
| 124 |
depth: 1 |
| 125 |
version: >- |
| 126 |
{{ git_default_branch }} |
| 127 |
|
| 128 |
- name: DEPTH | switch to older branch with depth=1 (uses fetch) |
| 129 |
git: |
| 130 |
repo: 'file://{{ repo_dir|expanduser }}/shallow' |
| 131 |
dest: '{{ checkout_dir }}' |
| 132 |
depth: 1 |
| 133 |
version: earlybranch |
| 134 |
register: git_fetch |
| 135 |
|
| 136 |
- name: DEPTH | ensure the fetch succeeded |
| 137 |
assert: |
| 138 |
that: git_fetch is successful |
| 139 |
|
| 140 |
- name: DEPTH | clear checkout_dir |
| 141 |
file: |
| 142 |
state: absent |
| 143 |
path: "{{ checkout_dir }}" |
| 144 |
|
| 145 |
# test for https://github.com/ansible/ansible-modules-core/issues/3782 |
| 146 |
# make sure shallow fetch works when no version is specified |
| 147 |
|
| 148 |
- name: DEPTH | checkout old repo |
| 149 |
git: |
| 150 |
repo: 'file://{{ repo_dir|expanduser }}/shallow' |
| 151 |
dest: '{{ checkout_dir }}' |
| 152 |
depth: 1 |
| 153 |
|
| 154 |
- name: DEPTH | "update repo" |
| 155 |
shell: echo "3" > a; git commit -a -m "3" |
| 156 |
args: |
| 157 |
chdir: "{{ repo_dir }}/shallow" |
| 158 |
|
| 159 |
- name: DEPTH | fetch updated repo |
| 160 |
git: |
| 161 |
repo: 'file://{{ repo_dir|expanduser }}/shallow' |
| 162 |
dest: '{{ checkout_dir }}' |
| 163 |
depth: 1 |
| 164 |
register: git_fetch |
| 165 |
ignore_errors: yes |
| 166 |
|
| 167 |
- name: DEPTH | get "a" file |
| 168 |
slurp: |
| 169 |
src: '{{ checkout_dir }}/a' |
| 170 |
register: a_file |
| 171 |
|
| 172 |
- name: DEPTH | check update arrived |
| 173 |
assert: |
| 174 |
that: |
| 175 |
- a_file.content | b64decode | int == 3 |
| 176 |
- git_fetch is changed |
| 177 |
|
| 178 |
- name: DEPTH | clear checkout_dir |
| 179 |
file: |
| 180 |
state: absent |
| 181 |
path: "{{ checkout_dir }}" |
| 182 |
|
| 183 |
# |
| 184 |
# Make sure shallow fetch works when switching to (fetching) a new a branch |
| 185 |
# |
| 186 |
|
| 187 |
- name: DEPTH | clone from branch with depth specified |
| 188 |
git: |
| 189 |
repo: 'file://{{ repo_dir|expanduser }}/shallow_branches' |
| 190 |
dest: '{{ checkout_dir }}' |
| 191 |
depth: 1 |
| 192 |
version: test_branch |
| 193 |
|
| 194 |
- name: DEPTH | check if clone is shallow |
| 195 |
stat: path={{ checkout_dir }}/.git/shallow |
| 196 |
register: is_shallow |
| 197 |
when: git_version.stdout is version(git_version_supporting_depth, '>=') |
| 198 |
|
| 199 |
- name: DEPTH | assert that clone is shallow |
| 200 |
assert: |
| 201 |
that: |
| 202 |
- is_shallow.stat.exists |
| 203 |
when: git_version.stdout is version(git_version_supporting_depth, '>=') |
| 204 |
|
| 205 |
- name: DEPTH | switch to new branch (fetch) with the shallow clone |
| 206 |
git: |
| 207 |
repo: 'file://{{ repo_dir|expanduser }}/shallow_branches' |
| 208 |
dest: '{{ checkout_dir }}' |
| 209 |
depth: 1 |
| 210 |
version: new_branch |
| 211 |
register: git_fetch |
| 212 |
|
| 213 |
- name: DEPTH | assert if switching a shallow clone to a new branch worked |
| 214 |
assert: |
| 215 |
that: |
| 216 |
- git_fetch is changed |
| 217 |
|
| 218 |
- name: DEPTH | check if clone is still shallow |
| 219 |
stat: path={{ checkout_dir }}/.git/shallow |
| 220 |
register: is_shallow |
| 221 |
when: git_version.stdout is version(git_version_supporting_depth, '>=') |
| 222 |
|
| 223 |
- name: DEPTH | assert that clone still is shallow |
| 224 |
assert: |
| 225 |
that: |
| 226 |
- is_shallow.stat.exists |
| 227 |
when: git_version.stdout is version(git_version_supporting_depth, '>=') |
| 228 |
|
| 229 |
- name: DEPTH | clear checkout_dir |
| 230 |
file: |
| 231 |
state: absent |
| 232 |
path: "{{ checkout_dir }}" |