blob: 26fa7cf33894240d360b8179eeee3190e5c78291 (
plain)
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
233
234
235
236
237
238
|
# Test that a specific revision can be checked out
- name: SPECIFIC-REVISION | clear checkout_dir
file:
state: absent
path: '{{ checkout_dir }}'
- name: SPECIFIC-REVISION | clone to specific revision
git:
repo: "{{ repo_dir }}/format1"
dest: "{{ checkout_dir }}"
version: df4612ba925fbc1b3c51cbb006f51a0443bd2ce9
- name: SPECIFIC-REVISION | check HEAD after clone to revision
command: git rev-parse HEAD
args:
chdir: "{{ checkout_dir }}"
register: git_result
- assert:
that:
- 'git_result.stdout == "df4612ba925fbc1b3c51cbb006f51a0443bd2ce9"'
- name: SPECIFIC-REVISION | update to specific revision
git:
repo: "{{ repo_dir }}/format1"
dest: "{{ checkout_dir }}"
version: 4e739a34719654db7b04896966e2354e1256ea5d
register: git_result
- assert:
that:
- git_result is changed
- name: SPECIFIC-REVISION | check HEAD after update to revision
command: git rev-parse HEAD
args:
chdir: "{{ checkout_dir }}"
register: git_result
- assert:
that:
- 'git_result.stdout == "4e739a34719654db7b04896966e2354e1256ea5d"'
- name: SPECIFIC-REVISION | update to HEAD from detached HEAD state
git:
repo: "{{ repo_dir }}/format1"
dest: "{{ checkout_dir }}"
version: HEAD
register: git_result
- assert:
that:
- git_result is changed
# Test a revision not available under refs/heads/ or refs/tags/
- name: SPECIFIC-REVISION | attempt to get unavailable revision
git:
repo: "{{ repo_dir }}/format1"
dest: "{{ checkout_dir }}"
version: 5473e343e33255f2da0b160f53135c56921d875c
ignore_errors: true
register: git_result
- assert:
that:
- git_result is failed
# Same as the previous test, but this time we specify which ref
# contains the SHA1
- name: SPECIFIC-REVISION | update to revision by specifying the refspec
git:
repo: https://github.com/ansible/ansible-examples.git
dest: '{{ checkout_dir }}'
version: 5473e343e33255f2da0b160f53135c56921d875c
refspec: refs/pull/7/merge
- name: SPECIFIC-REVISION | check HEAD after update with refspec
command: git rev-parse HEAD
args:
chdir: "{{ checkout_dir }}"
register: git_result
- assert:
that:
- 'git_result.stdout == "5473e343e33255f2da0b160f53135c56921d875c"'
# try out combination of refspec and depth
- name: SPECIFIC-REVISION | clear checkout_dir
file:
state: absent
path: "{{ checkout_dir }}"
- name: SPECIFIC-REVISION | update to revision by specifying the refspec with depth=1
git:
repo: https://github.com/ansible/ansible-examples.git
dest: '{{ checkout_dir }}'
version: 5473e343e33255f2da0b160f53135c56921d875c
refspec: refs/pull/7/merge
depth: 1
- name: SPECIFIC-REVISION | check HEAD after update with refspec
command: git rev-parse HEAD
args:
chdir: "{{ checkout_dir }}"
register: git_result
- assert:
that:
- 'git_result.stdout == "5473e343e33255f2da0b160f53135c56921d875c"'
- name: SPECIFIC-REVISION | try to access other commit
shell: git checkout 0ce1096
register: checkout_shallow
failed_when: False
args:
chdir: "{{ checkout_dir }}"
- name: SPECIFIC-REVISION | "make sure the old commit was not fetched, task is 'forced success'"
assert:
that:
- checkout_shallow.rc != 0
- checkout_shallow is successful
when: git_version.stdout is version(git_version_supporting_depth, '>=')
- name: SPECIFIC-REVISION | clear checkout_dir
file:
state: absent
path: "{{ checkout_dir }}"
- name: SPECIFIC-REVISION | clone to revision by specifying the refspec
git:
repo: https://github.com/ansible/ansible-examples.git
dest: "{{ checkout_dir }}"
version: 5473e343e33255f2da0b160f53135c56921d875c
refspec: refs/pull/7/merge
- name: SPECIFIC-REVISION | check HEAD after update with refspec
command: git rev-parse HEAD
args:
chdir: "{{ checkout_dir }}"
register: git_result
- assert:
that:
- 'git_result.stdout == "5473e343e33255f2da0b160f53135c56921d875c"'
# Test that a forced shallow checkout referincing branch only always fetches latest head
- name: SPECIFIC-REVISION | clear checkout_dir
file:
state: absent
path: "{{ item }}"
with_items:
- "{{ checkout_dir }}"
- "{{ checkout_dir }}.copy"
- name: SPECIFIC-REVISION | create original repo dir
file:
state: directory
path: "{{ checkout_dir }}"
- name: SPECIFIC-REVISION | prepare origina repo
shell: git init; echo "1" > a; git add a; git commit -m "1"
args:
chdir: "{{ checkout_dir }}"
- name: SPECIFIC-REVISION | clone example repo locally
git:
repo: "{{ checkout_dir }}"
dest: "{{ checkout_dir }}.copy"
- name: SPECIFIC-REVISION | create branch in original
command: git checkout -b test/branch
args:
chdir: "{{ checkout_dir }}"
- name: SPECIFIC-REVISION | get commit for HEAD on new branch
command: git rev-parse HEAD
args:
chdir: "{{ checkout_dir }}.copy"
register: originaltip0
- name: SPECIFIC-REVISION | shallow force checkout new branch in copy
git:
repo: "{{ checkout_dir }}"
dest: "{{ checkout_dir }}.copy"
version: test/branch
depth: 1
force: yes
- name: SPECIFIC-REVISION | create new commit in original
shell: git init; echo "2" > b; git add b; git commit -m "2"
args:
chdir: "{{ checkout_dir }}"
- name: SPECIFIC-REVISION | get commit for new HEAD on original branch
command: git rev-parse HEAD
args:
chdir: "{{ checkout_dir }}"
register: originaltip1
- name: SPECIFIC-REVISION | get commit for HEAD on new branch
command: git rev-parse HEAD
args:
chdir: "{{ checkout_dir }}.copy"
register: newtip
- name: SPECIFIC-REVISION | assert that copy is still pointing at previous tip
assert:
that:
- newtip.stdout == originaltip0.stdout
- name: SPECIFIC-REVISION | create a local modification in the copy
shell: echo "3" > c
args:
chdir: "{{ checkout_dir }}.copy"
- name: SPECIFIC-REVISION | shallow force checkout new branch in copy (again)
git:
repo: "{{ checkout_dir }}"
dest: "{{ checkout_dir }}.copy"
version: test/branch
depth: 1
force: yes
- name: SPECIFIC-REVISION | get commit for HEAD on new branch
command: git rev-parse HEAD
args:
chdir: "{{ checkout_dir }}.copy"
register: newtip
- name: SPECIFIC-REVISION | make sure copy tip is not pointing at previous sha and that new tips match
assert:
that:
- newtip.stdout != originaltip0.stdout
- newtip.stdout == originaltip1.stdout
|