Debian Codegraph @

test/integration/targets/git/tasks/specific-revision.yml

raw
1 # Test that a specific revision can be checked out
2
3 - name: SPECIFIC-REVISION | clear checkout_dir
4 file:
5 state: absent
6 path: '{{ checkout_dir }}'
7
8 - name: SPECIFIC-REVISION | check clone to specific revision
9 git:
10 repo: "{{ repo_dir }}/format1"
11 dest: "{{ checkout_dir }}"
12 version: df4612ba925fbc1b3c51cbb006f51a0443bd2ce9
13 check_mode: true
14 register: specific_revision_check
15
16 - name: SPECIFIC-REVISION | clone to specific revision
17 git:
18 repo: "{{ repo_dir }}/format1"
19 dest: "{{ checkout_dir }}"
20 version: df4612ba925fbc1b3c51cbb006f51a0443bd2ce9
21 register: specific_revision_clone
22
23 - name: SPECIFIC-REVISION | check HEAD after clone to revision
24 command: git rev-parse HEAD
25 args:
26 chdir: "{{ checkout_dir }}"
27 register: git_result
28
29 - assert:
30 that:
31 - 'git_result.stdout == "df4612ba925fbc1b3c51cbb006f51a0443bd2ce9"'
32
33 - assert:
34 that:
35 - specific_revision_check is changed
36 - specific_revision_check.changed == specific_revision_clone.changed
37
38 - name: SPECIFIC-REVISION | update to specific revision
39 git:
40 repo: "{{ repo_dir }}/format1"
41 dest: "{{ checkout_dir }}"
42 version: 4e739a34719654db7b04896966e2354e1256ea5d
43 register: git_result
44
45 - assert:
46 that:
47 - git_result is changed
48
49 - name: SPECIFIC-REVISION | check HEAD after update to revision
50 command: git rev-parse HEAD
51 args:
52 chdir: "{{ checkout_dir }}"
53 register: git_result
54
55 - assert:
56 that:
57 - 'git_result.stdout == "4e739a34719654db7b04896966e2354e1256ea5d"'
58
59 - name: SPECIFIC-REVISION | update to HEAD from detached HEAD state
60 git:
61 repo: "{{ repo_dir }}/format1"
62 dest: "{{ checkout_dir }}"
63 version: HEAD
64 register: git_result
65
66 - assert:
67 that:
68 - git_result is changed
69
70 # Test a revision not available under refs/heads/ or refs/tags/
71
72 - name: SPECIFIC-REVISION | attempt to get unavailable revision
73 git:
74 repo: "{{ repo_dir }}/format1"
75 dest: "{{ checkout_dir }}"
76 version: 5473e343e33255f2da0b160f53135c56921d875c
77 ignore_errors: true
78 register: git_result
79
80 - assert:
81 that:
82 - git_result is failed
83
84 # Same as the previous test, but this time we specify which ref
85 # contains the SHA1
86 - name: SPECIFIC-REVISION | update to revision by specifying the refspec
87 git: &git_ref_spec
88 repo: "{{ repo_dir }}/shallow_branches/.git"
89 dest: '{{ checkout_dir }}'
90 version: "{{ test_branch_ref_head_id }}"
91 refspec: refs/heads/test_branch
92
93 - name: SPECIFIC-REVISION | check HEAD after update with refspec
94 command: git rev-parse HEAD
95 args:
96 chdir: "{{ checkout_dir }}"
97 register: git_result
98
99 - assert:
100 that:
101 - 'git_result.stdout == test_branch_ref_head_id'
102
103 # try out combination of refspec and depth
104 - name: SPECIFIC-REVISION | clear checkout_dir
105 file:
106 state: absent
107 path: "{{ checkout_dir }}"
108
109 - name: SPECIFIC-REVISION | update to revision by specifying the refspec with depth=1
110 git:
111 depth: 1
112 <<: *git_ref_spec
113
114 - name: SPECIFIC-REVISION | check HEAD after update with refspec
115 command: git rev-parse HEAD
116 args:
117 chdir: "{{ checkout_dir }}"
118 register: git_result
119
120 - assert:
121 that:
122 - 'git_result.stdout == test_branch_ref_head_id'
123
124 - name: SPECIFIC-REVISION | try to access other commit
125 shell: git checkout 0ce1096
126 register: checkout_shallow
127 failed_when: False
128 args:
129 chdir: "{{ checkout_dir }}"
130
131 - name: SPECIFIC-REVISION | "make sure the old commit was not fetched, task is 'forced success'"
132 assert:
133 that:
134 - checkout_shallow.rc != 0
135 - checkout_shallow is successful
136 when: git_version.stdout is version(git_version_supporting_depth, '>=')
137
138 - name: SPECIFIC-REVISION | clear checkout_dir
139 file:
140 state: absent
141 path: "{{ checkout_dir }}"
142
143 - name: SPECIFIC-REVISION | clone to revision by specifying the refspec
144 git: *git_ref_spec
145
146 - name: SPECIFIC-REVISION | check HEAD after update with refspec
147 command: git rev-parse HEAD
148 args:
149 chdir: "{{ checkout_dir }}"
150 register: git_result
151
152 - assert:
153 that:
154 - 'git_result.stdout == test_branch_ref_head_id'
155
156 # Test that a forced shallow checkout referencing branch only always fetches latest head
157
158 - name: SPECIFIC-REVISION | clear checkout_dir
159 file:
160 state: absent
161 path: "{{ item }}"
162 with_items:
163 - "{{ checkout_dir }}"
164 - "{{ checkout_dir }}.copy"
165
166 - name: SPECIFIC-REVISION | create original repo dir
167 file:
168 state: directory
169 path: "{{ checkout_dir }}"
170
171 - name: SPECIFIC-REVISION | prepare origina repo
172 shell: |
173 set -eEu
174
175 git init
176
177 echo "1" > a
178 git add a
179 git commit -m "1"
180 args:
181 chdir: "{{ checkout_dir }}"
182
183 - name: SPECIFIC-REVISION | clone example repo locally
184 git:
185 repo: "{{ checkout_dir }}"
186 dest: "{{ checkout_dir }}.copy"
187
188 - name: SPECIFIC-REVISION | create branch in original
189 command: git checkout -b test/branch
190 args:
191 chdir: "{{ checkout_dir }}"
192
193 - name: SPECIFIC-REVISION | get commit for HEAD on new branch
194 command: git rev-parse HEAD
195 args:
196 chdir: "{{ checkout_dir }}.copy"
197 register: originaltip0
198
199 - name: SPECIFIC-REVISION | shallow force checkout new branch in copy
200 git:
201 repo: "{{ checkout_dir }}"
202 dest: "{{ checkout_dir }}.copy"
203 version: test/branch
204 depth: 1
205 force: yes
206
207 - name: SPECIFIC-REVISION | create new commit in original
208 shell: |
209 set -eEu
210
211 git init
212
213 echo "2" > b
214 git add b
215 git commit -m "2"
216 args:
217 chdir: "{{ checkout_dir }}"
218
219 - name: SPECIFIC-REVISION | get commit for new HEAD on original branch
220 command: git rev-parse HEAD
221 args:
222 chdir: "{{ checkout_dir }}"
223 register: originaltip1
224
225 - name: SPECIFIC-REVISION | get commit for HEAD on new branch
226 command: git rev-parse HEAD
227 args:
228 chdir: "{{ checkout_dir }}.copy"
229 register: newtip
230
231 - name: SPECIFIC-REVISION | assert that copy is still pointing at previous tip
232 assert:
233 that:
234 - newtip.stdout == originaltip0.stdout
235
236 - name: SPECIFIC-REVISION | create a local modification in the copy
237 shell: echo "3" > c
238 args:
239 chdir: "{{ checkout_dir }}.copy"
240
241 - name: SPECIFIC-REVISION | shallow force checkout new branch in copy (again)
242 git:
243 repo: "{{ checkout_dir }}"
244 dest: "{{ checkout_dir }}.copy"
245 version: test/branch
246 depth: 1
247 force: yes
248
249 - name: SPECIFIC-REVISION | get commit for HEAD on new branch
250 command: git rev-parse HEAD
251 args:
252 chdir: "{{ checkout_dir }}.copy"
253 register: newtip
254
255 - name: SPECIFIC-REVISION | make sure copy tip is not pointing at previous sha and that new tips match
256 assert:
257 that:
258 - newtip.stdout != originaltip0.stdout
259 - newtip.stdout == originaltip1.stdout