mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-06-13 11:49:11 -07:00
[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:
parent
098eac076d
commit
7225839bef
3 changed files with 62 additions and 3 deletions
|
@ -716,8 +716,6 @@ def fetch(git_path, module, repo, dest, version, remote, depth, bare, refspec, g
|
||||||
# ensure that remote branch is available as both local and remote ref
|
# ensure that remote branch is available as both local and remote ref
|
||||||
refspecs.append('+refs/heads/%s:refs/heads/%s' % (version, version))
|
refspecs.append('+refs/heads/%s:refs/heads/%s' % (version, version))
|
||||||
refspecs.append('+refs/heads/%s:refs/remotes/%s/%s' % (version, remote, version))
|
refspecs.append('+refs/heads/%s:refs/remotes/%s/%s' % (version, remote, version))
|
||||||
else:
|
|
||||||
refspecs.append(version)
|
|
||||||
elif is_remote_tag(git_path, module, dest, repo, version):
|
elif is_remote_tag(git_path, module, dest, repo, version):
|
||||||
refspecs.append('+refs/tags/' + version + ':refs/tags/' + version)
|
refspecs.append('+refs/tags/' + version + ':refs/tags/' + version)
|
||||||
if refspecs:
|
if refspecs:
|
||||||
|
|
|
@ -171,3 +171,54 @@
|
||||||
file:
|
file:
|
||||||
state: absent
|
state: absent
|
||||||
path: "{{ checkout_dir }}"
|
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 }}"
|
||||||
|
|
|
@ -5,6 +5,7 @@
|
||||||
with_items:
|
with_items:
|
||||||
- "{{ repo_dir }}/minimal"
|
- "{{ repo_dir }}/minimal"
|
||||||
- "{{ repo_dir }}/shallow"
|
- "{{ repo_dir }}/shallow"
|
||||||
|
- "{{ repo_dir }}/shallow_branches"
|
||||||
|
|
||||||
- name: SETUP-LOCAL-REPOS | prepare minimal git repo
|
- name: SETUP-LOCAL-REPOS | prepare minimal git repo
|
||||||
shell: git init; echo "1" > a; git add a; git commit -m "1"
|
shell: git init; echo "1" > a; git add a; git commit -m "1"
|
||||||
|
@ -24,3 +25,12 @@
|
||||||
register: git_shallow_head_1
|
register: git_shallow_head_1
|
||||||
args:
|
args:
|
||||||
chdir: "{{ repo_dir }}/shallow"
|
chdir: "{{ repo_dir }}/shallow"
|
||||||
|
|
||||||
|
- name: prepare tmp git repo with two branches
|
||||||
|
shell: |
|
||||||
|
git init
|
||||||
|
echo "1" > a; git add a; git commit -m "1"
|
||||||
|
git checkout -b test_branch; echo "2" > a; git commit -m "2 on branch" a
|
||||||
|
git checkout -b new_branch; echo "3" > a; git commit -m "3 on new branch" a
|
||||||
|
args:
|
||||||
|
chdir: "{{ repo_dir }}/shallow_branches"
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue