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