* Add test for git with local modifications

(cherry picked from afca957396)

From PR: Fix UnboundLocalError remote_head in git (#19057)
This commit is contained in:
Toshio Kuratomi 2016-12-14 08:46:11 -08:00
parent 2639016847
commit 00378515e2

View file

@ -447,7 +447,7 @@
- name: clear checkout_dir - name: clear checkout_dir
file: state=absent path={{ checkout_dir }} file: state=absent path={{ checkout_dir }}
- name: Clone example git repo that we're going to modify - name: "Clone example git repo that we're going to modify"
git: git:
repo: '{{ repo_update_url_1 }}' repo: '{{ repo_update_url_1 }}'
dest: '{{ checkout_dir }}/repo' dest: '{{ checkout_dir }}/repo'
@ -652,9 +652,6 @@
register: git_fetch register: git_fetch
ignore_errors: yes ignore_errors: yes
- name: read file
shell: cat {{ checkout_dir }}/a
- name: check update arrived - name: check update arrived
assert: assert:
that: that:
@ -718,3 +715,109 @@
gpg_version.stdout and gpg_version.stdout and
(git_version.stdout | version_compare("2.1.0", '>=') or (git_version.stdout | version_compare("2.1.0", '>=') or
gpg_version.stdout | version_compare("1.4.16", '>=')) gpg_version.stdout | version_compare("1.4.16", '>='))
- name: clear checkout_dir
file: state=absent path={{ checkout_dir }}
# test for https://github.com/ansible/ansible-modules-core/pull/5505
- name: prepare old git repo
shell: rm -rf localmods; mkdir localmods; cd localmods; git init; echo "1" > a; git add a; git commit -m "1"
args:
chdir: "{{repo_dir}}"
- name: checkout old repo
git:
repo: '{{ repo_dir }}/localmods'
dest: '{{ checkout_dir }}'
- name: "update repo"
shell: echo "2" > a; git commit -a -m "2"
args:
chdir: "{{repo_dir}}/localmods"
- name: "add local mods"
shell: echo "3" > a
args:
chdir: "{{ checkout_dir }}"
- name: fetch with local mods without force (should fail)
git:
repo: '{{ repo_dir }}/localmods'
dest: '{{ checkout_dir }}'
register: git_fetch
ignore_errors: yes
- name: check fetch with localmods failed
assert:
that:
- git_fetch|failed
- name: fetch with local mods with force
git:
repo: '{{ repo_dir }}/localmods'
dest: '{{ checkout_dir }}'
force: True
register: git_fetch_force
ignore_errors: yes
- name: check update arrived
assert:
that:
- "{{ lookup('file', checkout_dir+'/a' )}} == 2"
- git_fetch_force|changed
- name: clear checkout_dir
file: state=absent path={{ checkout_dir }}
# localmods and shallow clone
- name: prepare old git repo
shell: rm -rf localmods; mkdir localmods; cd localmods; git init; echo "1" > a; git add a; git commit -m "1"
args:
chdir: "{{repo_dir}}"
- name: checkout old repo
git:
repo: '{{ repo_dir }}/localmods'
dest: '{{ checkout_dir }}'
depth: 1
- name: "update repo"
shell: echo "2" > a; git commit -a -m "2"
args:
chdir: "{{repo_dir}}/localmods"
- name: "add local mods"
shell: echo "3" > a
args:
chdir: "{{ checkout_dir }}"
- name: fetch with local mods without force (should fail)
git:
repo: '{{ repo_dir }}/localmods'
dest: '{{ checkout_dir }}'
depth: 1
register: git_fetch
ignore_errors: yes
- name: check fetch with localmods failed
assert:
that:
- git_fetch|failed
- name: fetch with local mods with force
git:
repo: '{{ repo_dir }}/localmods'
dest: '{{ checkout_dir }}'
depth: 1
force: True
register: git_fetch_force
ignore_errors: yes
- name: check update arrived
assert:
that:
- "{{ lookup('file', checkout_dir+'/a' )}} == 2"
- git_fetch_force|changed
- name: clear checkout_dir
file: state=absent path={{ checkout_dir }}