Debian Codegraph @

test/integration/targets/git/tasks/localmods.yml

raw
1 # test for https://github.com/ansible/ansible-modules-core/pull/5505
2 - name: LOCALMODS | prepare old git repo
3 shell: |
4 set -eEu
5
6 rm -rf localmods
7 mkdir localmods
8 cd localmods
9
10 git init
11
12 echo "1" > a
13 git add a
14 git commit -m "1"
15 args:
16 chdir: "{{repo_dir}}"
17
18 - name: LOCALMODS | checkout old repo
19 git:
20 repo: '{{ repo_dir }}/localmods'
21 dest: '{{ checkout_dir }}'
22
23 - name: LOCALMODS | "update repo"
24 shell: echo "2" > a; git commit -a -m "2"
25 args:
26 chdir: "{{repo_dir}}/localmods"
27
28 - name: LOCALMODS | "add local mods"
29 shell: echo "3" > a
30 args:
31 chdir: "{{ checkout_dir }}"
32
33 - name: LOCALMODS | fetch with local mods without force (should fail)
34 git:
35 repo: '{{ repo_dir }}/localmods'
36 dest: '{{ checkout_dir }}'
37 register: git_fetch
38 ignore_errors: yes
39
40 - name: LOCALMODS | check fetch with localmods failed
41 assert:
42 that:
43 - git_fetch is failed
44
45 - name: LOCALMODS | fetch with local mods with force
46 git:
47 repo: '{{ repo_dir }}/localmods'
48 dest: '{{ checkout_dir }}'
49 force: True
50 register: git_fetch_force
51 ignore_errors: yes
52
53 - name: LOCALMODS | get "a" file
54 slurp:
55 src: '{{ checkout_dir }}/a'
56 register: a_file
57
58 - name: LOCALMODS | check update arrived
59 assert:
60 that:
61 - a_file.content | b64decode | int == 2
62 - git_fetch_force is changed
63
64 - name: LOCALMODS | clear checkout_dir
65 file: state=absent path={{ checkout_dir }}
66
67 # localmods and shallow clone
68 - name: LOCALMODS | prepare old git repo
69 shell: |
70 set -eEu
71
72 rm -rf localmods
73 mkdir localmods
74 cd localmods
75
76 git init
77
78 echo "1" > a
79 git add a
80 git commit -m "1"
81 args:
82 chdir: "{{repo_dir}}"
83
84 - name: LOCALMODS | checkout old repo
85 git:
86 repo: '{{ repo_dir }}/localmods'
87 dest: '{{ checkout_dir }}'
88 depth: 1
89
90 - name: LOCALMODS | "update repo"
91 shell: echo "2" > a; git commit -a -m "2"
92 args:
93 chdir: "{{repo_dir}}/localmods"
94
95 - name: LOCALMODS | "add local mods"
96 shell: echo "3" > a
97 args:
98 chdir: "{{ checkout_dir }}"
99
100 - name: LOCALMODS | fetch with local mods without force (should fail)
101 git:
102 repo: '{{ repo_dir }}/localmods'
103 dest: '{{ checkout_dir }}'
104 depth: 1
105 register: git_fetch
106 ignore_errors: yes
107
108 - name: LOCALMODS | check fetch with localmods failed
109 assert:
110 that:
111 - git_fetch is failed
112
113 - name: LOCALMODS | fetch with local mods with force
114 git:
115 repo: '{{ repo_dir }}/localmods'
116 dest: '{{ checkout_dir }}'
117 depth: 1
118 force: True
119 register: git_fetch_force
120 ignore_errors: yes
121
122 - name: LOCALMODS | get "a" file
123 slurp:
124 src: '{{ checkout_dir }}/a'
125 register: a_file
126
127 - name: LOCALMODS | check update arrived
128 assert:
129 that:
130 - a_file.content | b64decode | int == 2
131 - git_fetch_force is changed
132
133 - name: LOCALMODS | clear checkout_dir
134 file: state=absent path={{ checkout_dir }}
135
136 # Regression test for https://github.com/ansible/ansible/issues/83367
137 - name: Check that commits aren't overwritten
138 vars:
139 branch: "testbranch"
140 block:
141 - name: LOCALMODS | create branch on remote
142 shell: |
143 git checkout -b {{ branch }}
144 echo "remote" > c
145 git add c
146 git commit -m "remote branch"
147 args:
148 chdir: "{{ repo_dir }}/localmods"
149
150 - name: LOCALMODS | checkout repo with branch
151 git:
152 repo: '{{ repo_dir }}/localmods'
153 dest: '{{ checkout_dir }}'
154 version: '{{ branch }}'
155
156 - name: LOCALMODS | make local commit
157 shell: |
158 echo "local" > b
159 git add b
160 git commit -m "local"
161 git rev-parse HEAD
162 args:
163 chdir: "{{ checkout_dir }}"
164 register: local_commit
165
166 - name: LOCALMODS | rerun git module without force (should fail)
167 git:
168 repo: '{{ repo_dir }}/localmods'
169 dest: '{{ checkout_dir }}'
170 version: '{{ branch }}'
171 register: rerun_no_force
172 ignore_errors: yes
173
174 - name: LOCALMODS | assert task failed with local commits ahead
175 assert:
176 that:
177 - rerun_no_force is failed
178
179 - name: LOCALMODS | verify local commit still exists after failed run
180 shell: git rev-parse HEAD
181 args:
182 chdir: "{{ checkout_dir }}"
183 register: commit_after_fail
184
185 - name: LOCALMODS | assert local commit preserved after failure
186 assert:
187 that:
188 - local_commit.stdout_lines[-1] == commit_after_fail.stdout
189
190 - name: LOCALMODS | rerun git module with force (should succeed and reset)
191 git:
192 repo: '{{ repo_dir }}/localmods'
193 dest: '{{ checkout_dir }}'
194 version: '{{ branch }}'
195 force: yes
196 register: rerun_with_force
197
198 - name: LOCALMODS | get remote commit hash
199 shell: git rev-parse origin/{{ branch }}
200 args:
201 chdir: "{{ checkout_dir }}"
202 register: remote_commit
203
204 - name: LOCALMODS | verify local commit was reset
205 shell: git rev-parse HEAD
206 args:
207 chdir: "{{ checkout_dir }}"
208 register: commit_after_force
209
210 - name: LOCALMODS | assert force reset to remote
211 assert:
212 that:
213 - local_commit.stdout_lines[-1] != commit_after_force.stdout
214 - commit_after_force.stdout == remote_commit.stdout
215 - rerun_with_force is changed
216
217 - name: LOCALMODS | make remote commit to create diverged state
218 shell: |
219 echo "remote2" > d
220 git add d
221 git commit -m "remote commit 2"
222 args:
223 chdir: "{{ repo_dir }}/localmods"
224
225 - name: LOCALMODS | make local commit to complete diverged state
226 shell: |
227 echo "local2" > e
228 git add e
229 git commit -m "local commit 2"
230 git rev-parse HEAD
231 args:
232 chdir: "{{ checkout_dir }}"
233 register: diverged_local_commit
234
235 - name: LOCALMODS | rerun git module with diverged branches without force (should fail)
236 git:
237 repo: '{{ repo_dir }}/localmods'
238 dest: '{{ checkout_dir }}'
239 version: '{{ branch }}'
240 register: diverged_no_force
241 ignore_errors: yes
242
243 - name: LOCALMODS | assert task failed with diverged branches
244 assert:
245 that:
246 - diverged_no_force is failed
247 - "'local commits will be lost' in diverged_no_force.msg"
248
249 - name: LOCALMODS | verify local commit still exists after diverged failure
250 shell: git rev-parse HEAD
251 args:
252 chdir: "{{ checkout_dir }}"
253 register: commit_after_diverged_fail
254
255 - name: LOCALMODS | assert local commit preserved after diverged failure
256 assert:
257 that:
258 - diverged_local_commit.stdout_lines[-1] == commit_after_diverged_fail.stdout
259
260 - name: LOCALMODS | rerun git module with diverged branches with force (should succeed)
261 git:
262 repo: '{{ repo_dir }}/localmods'
263 dest: '{{ checkout_dir }}'
264 version: '{{ branch }}'
265 force: yes
266 register: diverged_with_force
267
268 - name: LOCALMODS | get remote commit after diverged force
269 shell: git rev-parse origin/{{ branch }}
270 args:
271 chdir: "{{ checkout_dir }}"
272 register: remote_after_diverged
273
274 - name: LOCALMODS | verify diverged branch was reset with force
275 shell: git rev-parse HEAD
276 args:
277 chdir: "{{ checkout_dir }}"
278 register: commit_after_diverged_force
279
280 - name: LOCALMODS | assert force reset diverged branch to remote
281 assert:
282 that:
283 - diverged_local_commit.stdout_lines[-1] != commit_after_diverged_force.stdout
284 - commit_after_diverged_force.stdout == remote_after_diverged.stdout
285 - diverged_with_force is changed
286
287 always:
288 - name: LOCALMODS | cleanup checkout_dir
289 file:
290 state: absent
291 path: "{{ checkout_dir }}"