[git] Fix switching branch of shallow clone (#18728)

* [git] Fix fetching branch of shallow clone

* Use absolute file:// paths to make sure git uses shallow clones

* Improve tests

* Fix sanity errors
* Match style according to other (depth) tests

* Improve tests

Now they will fail without the fix of this PR
This commit is contained in:
Maarten Bezemer
2018-02-08 00:07:02 +01:00
committed by Ryan Brown
parent 098eac076d
commit 7225839bef
3 changed files with 62 additions and 3 deletions

View File

@@ -171,3 +171,54 @@
file:
state: absent
path: "{{ checkout_dir }}"
#
# 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 }}"