Detect separate git dir and set git config path value appropriately

PR #38016

Co-authored-by: Sviatoslav Sydorenko <wk.cvs.github@sydorenko.org.ua>
This commit is contained in:
Senya
2018-05-22 22:33:22 +00:00
committed by Sviatoslav Sydorenko
parent 7d2012fdd7
commit 0a701ff746
3 changed files with 112 additions and 29 deletions

View File

@@ -36,3 +36,6 @@
- include_tasks: reset-origin.yml
- include_tasks: ambiguous-ref.yml
- include_tasks: archive.yml
- include_tasks: separate-git-dir.yml
when:
- git_version.stdout is version("1.7.5", '>=')

View File

@@ -0,0 +1,64 @@
# test code for repositories with separate git dir updating
# see https://github.com/ansible/ansible/pull/38016
# see https://github.com/ansible/ansible/issues/30034
- name: SEPARATE-GIT-DIR | clear checkout_dir
file:
state: absent
path: '{{ checkout_dir }}'
- name: create a tempdir for separate git dir
local_action: shell mktemp -du
register: tempdir
- name: SEPARATE-GIT-DIR | clone with a separate git dir
command: git clone {{ repo_format1 }} {{ checkout_dir }} --separate-git-dir={{ tempdir.stdout }}
- name: SEPARATE-GIT-DIR | update repo the usual way
git:
repo: "{{ repo_format1 }}"
dest: "{{ checkout_dir }}"
- name: SEPARATE-GIT-DIR | set git dir to non-existent dir
shell: "echo gitdir: /dev/null/non-existent-dir > .git"
args:
chdir: "{{ checkout_dir }}"
- name: SEPARATE-GIT-DIR | update repo the usual way
git:
repo: "{{ repo_format1 }}"
dest: "{{ checkout_dir }}"
ignore_errors: yes
register: result
- name: SEPARATE-GIT-DIR | check update has failed
assert:
that:
- result is failed
- name: SEPARATE-GIT-DIR | set .git file to bad format
shell: "echo some text gitdir: {{ checkout_dir }} > .git"
args:
chdir: "{{ checkout_dir }}"
- name: SEPARATE-GIT-DIR | update repo the usual way
git:
repo: "{{ repo_format1 }}"
dest: "{{ checkout_dir }}"
ignore_errors: yes
register: result
- name: SEPARATE-GIT-DIR | check update has failed
assert:
that:
- result is failed
- name: SEPARATE-GIT-DIR | clear separate git dir
file:
state: absent
path: "{{ tempdir.stdout }}"
- name: SEPARATE-GIT-DIR | clear checkout_dir
file:
state: absent
path: '{{ checkout_dir }}'