2017-01-06 22:38:53 +00:00
|
|
|
# Test the depth option and fetching revisions that were ignored first
|
|
|
|
|
2017-10-13 14:30:15 +00:00
|
|
|
- name: DEPTH | clear checkout_dir
|
|
|
|
file:
|
|
|
|
state: absent
|
|
|
|
path: "{{ checkout_dir }}"
|
2017-01-06 22:38:53 +00:00
|
|
|
|
2017-10-13 14:30:15 +00:00
|
|
|
- name: DEPTH | Clone example git repo with depth 1
|
2017-01-06 22:38:53 +00:00
|
|
|
git:
|
|
|
|
repo: 'file://{{ repo_dir|expanduser }}/shallow'
|
|
|
|
dest: '{{ checkout_dir }}'
|
|
|
|
depth: 1
|
|
|
|
|
2017-10-13 14:30:15 +00:00
|
|
|
- name: DEPTH | try to access earlier commit
|
2017-01-06 22:38:53 +00:00
|
|
|
command: "git checkout {{git_shallow_head_1.stdout}}"
|
|
|
|
register: checkout_early
|
|
|
|
failed_when: False
|
|
|
|
args:
|
|
|
|
chdir: '{{ checkout_dir }}'
|
|
|
|
|
2017-10-13 14:30:15 +00:00
|
|
|
- name: DEPTH | make sure the old commit was not fetched
|
2017-01-06 22:38:53 +00:00
|
|
|
assert:
|
|
|
|
that: 'checkout_early.rc != 0'
|
2017-11-27 22:58:08 +00:00
|
|
|
when: git_version.stdout is version(git_version_supporting_depth, '>=')
|
2017-01-06 22:38:53 +00:00
|
|
|
|
|
|
|
# tests https://github.com/ansible/ansible/issues/14954
|
2017-10-13 14:30:15 +00:00
|
|
|
- name: DEPTH | fetch repo again with depth=1
|
2017-01-06 22:38:53 +00:00
|
|
|
git:
|
|
|
|
repo: 'file://{{ repo_dir|expanduser }}/shallow'
|
|
|
|
dest: '{{ checkout_dir }}'
|
|
|
|
depth: 1
|
|
|
|
register: checkout2
|
|
|
|
|
|
|
|
- assert:
|
2017-11-27 22:58:08 +00:00
|
|
|
that: "checkout2 is not changed"
|
|
|
|
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: DEPTH | again try to access earlier commit
|
2017-01-06 22:38:53 +00:00
|
|
|
shell: "git checkout {{git_shallow_head_1.stdout}}"
|
|
|
|
register: checkout_early
|
|
|
|
failed_when: False
|
|
|
|
args:
|
|
|
|
chdir: '{{ checkout_dir }}'
|
|
|
|
|
2017-10-13 14:30:15 +00:00
|
|
|
- name: DEPTH | again make sure the old commit was not fetched
|
2017-01-06 22:38:53 +00:00
|
|
|
assert:
|
|
|
|
that: 'checkout_early.rc != 0'
|
2017-11-27 22:58:08 +00:00
|
|
|
when: git_version.stdout is version(git_version_supporting_depth, '>=')
|
2017-01-06 22:38:53 +00:00
|
|
|
|
|
|
|
# make sure we are still able to fetch other versions
|
2017-10-13 14:30:15 +00:00
|
|
|
- name: DEPTH | Clone same repo with older version
|
2017-01-06 22:38:53 +00:00
|
|
|
git:
|
|
|
|
repo: 'file://{{ repo_dir|expanduser }}/shallow'
|
|
|
|
dest: '{{ checkout_dir }}'
|
|
|
|
depth: 1
|
|
|
|
version: earlytag
|
|
|
|
register: cloneold
|
|
|
|
|
|
|
|
- assert:
|
2017-11-27 22:58:08 +00:00
|
|
|
that: cloneold is successful
|
2017-01-06 22:38:53 +00:00
|
|
|
|
2017-10-13 14:30:15 +00:00
|
|
|
- name: DEPTH | try to access earlier commit
|
2017-01-06 22:38:53 +00:00
|
|
|
shell: "git checkout {{git_shallow_head_1.stdout}}"
|
|
|
|
args:
|
|
|
|
chdir: '{{ checkout_dir }}'
|
|
|
|
|
2017-10-13 14:30:15 +00:00
|
|
|
- name: DEPTH | clear checkout_dir
|
2017-02-21 13:22:29 +00:00
|
|
|
file:
|
|
|
|
state: absent
|
|
|
|
path: "{{ checkout_dir }}"
|
|
|
|
|
|
|
|
# Test for https://github.com/ansible/ansible/issues/21316
|
2017-10-13 14:30:15 +00:00
|
|
|
- name: DEPTH | Shallow clone with tag
|
2017-02-21 13:22:29 +00:00
|
|
|
git:
|
|
|
|
repo: 'file://{{ repo_dir|expanduser }}/shallow'
|
|
|
|
dest: '{{ checkout_dir }}'
|
|
|
|
depth: 1
|
|
|
|
version: earlytag
|
|
|
|
register: cloneold
|
|
|
|
|
|
|
|
- assert:
|
2017-11-27 22:58:08 +00:00
|
|
|
that: cloneold is successful
|
2017-02-21 13:22:29 +00:00
|
|
|
|
2017-10-13 14:30:15 +00:00
|
|
|
- name: DEPTH | clear checkout_dir
|
2017-02-21 13:22:29 +00:00
|
|
|
file:
|
|
|
|
state: absent
|
|
|
|
path: "{{ checkout_dir }}"
|
|
|
|
|
2017-01-06 22:38:53 +00:00
|
|
|
|
|
|
|
# Test for https://github.com/ansible/ansible-modules-core/issues/3456
|
|
|
|
# clone a repo with depth and version specified
|
|
|
|
|
2017-10-13 14:30:15 +00:00
|
|
|
- name: DEPTH | clone repo with both version and depth specified
|
2017-01-06 22:38:53 +00:00
|
|
|
git:
|
|
|
|
repo: 'file://{{ repo_dir|expanduser }}/shallow'
|
|
|
|
dest: '{{ checkout_dir }}'
|
|
|
|
depth: 1
|
|
|
|
version: master
|
|
|
|
|
2017-10-13 14:30:15 +00:00
|
|
|
- name: DEPTH | run a second time (now fetch, not clone)
|
2017-01-06 22:38:53 +00:00
|
|
|
git:
|
|
|
|
repo: 'file://{{ repo_dir|expanduser }}/shallow'
|
|
|
|
dest: '{{ checkout_dir }}'
|
|
|
|
depth: 1
|
|
|
|
version: master
|
|
|
|
register: git_fetch
|
|
|
|
|
2017-10-13 14:30:15 +00:00
|
|
|
- name: DEPTH | ensure the fetch succeeded
|
2017-01-06 22:38:53 +00:00
|
|
|
assert:
|
2017-11-27 22:58:08 +00:00
|
|
|
that: git_fetch is successful
|
2017-01-06 22:38:53 +00:00
|
|
|
|
|
|
|
|
2017-10-13 14:30:15 +00:00
|
|
|
- name: DEPTH | clear checkout_dir
|
|
|
|
file:
|
|
|
|
state: absent
|
|
|
|
path: "{{ checkout_dir }}"
|
2017-01-06 22:38:53 +00:00
|
|
|
|
2017-10-13 14:30:15 +00:00
|
|
|
- name: DEPTH | clone repo with both version and depth specified
|
2017-01-06 22:38:53 +00:00
|
|
|
git:
|
|
|
|
repo: 'file://{{ repo_dir|expanduser }}/shallow'
|
|
|
|
dest: '{{ checkout_dir }}'
|
|
|
|
depth: 1
|
|
|
|
version: master
|
|
|
|
|
2017-10-13 14:30:15 +00:00
|
|
|
- name: DEPTH | switch to older branch with depth=1 (uses fetch)
|
2017-01-06 22:38:53 +00:00
|
|
|
git:
|
|
|
|
repo: 'file://{{ repo_dir|expanduser }}/shallow'
|
|
|
|
dest: '{{ checkout_dir }}'
|
|
|
|
depth: 1
|
|
|
|
version: earlybranch
|
|
|
|
register: git_fetch
|
|
|
|
|
2017-10-13 14:30:15 +00:00
|
|
|
- name: DEPTH | ensure the fetch succeeded
|
2017-01-06 22:38:53 +00:00
|
|
|
assert:
|
2017-11-27 22:58:08 +00:00
|
|
|
that: git_fetch is successful
|
2017-01-06 22:38:53 +00:00
|
|
|
|
2017-10-13 14:30:15 +00:00
|
|
|
- name: DEPTH | clear checkout_dir
|
|
|
|
file:
|
|
|
|
state: absent
|
|
|
|
path: "{{ checkout_dir }}"
|
2017-01-06 22:38:53 +00:00
|
|
|
|
|
|
|
# test for https://github.com/ansible/ansible-modules-core/issues/3782
|
|
|
|
# make sure shallow fetch works when no version is specified
|
|
|
|
|
2017-10-13 14:30:15 +00:00
|
|
|
- name: DEPTH | checkout old repo
|
2017-01-06 22:38:53 +00:00
|
|
|
git:
|
|
|
|
repo: 'file://{{ repo_dir|expanduser }}/shallow'
|
|
|
|
dest: '{{ checkout_dir }}'
|
|
|
|
depth: 1
|
|
|
|
|
2017-10-13 14:30:15 +00:00
|
|
|
- name: DEPTH | "update repo"
|
2017-01-06 22:38:53 +00:00
|
|
|
shell: echo "3" > a; git commit -a -m "3"
|
|
|
|
args:
|
2017-10-13 14:30:15 +00:00
|
|
|
chdir: "{{ repo_dir }}/shallow"
|
2017-01-06 22:38:53 +00:00
|
|
|
|
2017-10-13 14:30:15 +00:00
|
|
|
- name: DEPTH | fetch updated repo
|
2017-01-06 22:38:53 +00:00
|
|
|
git:
|
|
|
|
repo: 'file://{{ repo_dir|expanduser }}/shallow'
|
|
|
|
dest: '{{ checkout_dir }}'
|
|
|
|
depth: 1
|
|
|
|
register: git_fetch
|
|
|
|
ignore_errors: yes
|
|
|
|
|
2019-01-25 03:25:06 +00:00
|
|
|
- name: DEPTH | get "a" file
|
|
|
|
slurp:
|
|
|
|
src: '{{ checkout_dir }}/a'
|
|
|
|
register: a_file
|
|
|
|
|
2017-10-13 14:30:15 +00:00
|
|
|
- name: DEPTH | check update arrived
|
2017-01-06 22:38:53 +00:00
|
|
|
assert:
|
|
|
|
that:
|
2019-01-26 03:37:56 +00:00
|
|
|
- "{{ a_file.content | b64decode | trim }} == 3"
|
2017-11-27 22:58:08 +00:00
|
|
|
- git_fetch is changed
|
2017-01-06 22:38:53 +00:00
|
|
|
|
2017-10-13 14:30:15 +00:00
|
|
|
- name: DEPTH | clear checkout_dir
|
2017-01-06 22:38:53 +00:00
|
|
|
file:
|
|
|
|
state: absent
|
|
|
|
path: "{{ checkout_dir }}"
|
2018-02-07 23:07:02 +00:00
|
|
|
|
|
|
|
#
|
|
|
|
# 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 }}"
|