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