From e81f14ab48c89717c59df4749c674823bc7da56d Mon Sep 17 00:00:00 2001 From: Robin Roth Date: Thu, 9 Jun 2016 18:33:57 +0200 Subject: [PATCH] Add git shallow fetch test (#16055) * add git shallow fetch test covers https://github.com/ansible/ansible-modules-core/issues/3782 updating a repo with depth=1 fails silently if version==HEAD * disable git shallow tests for old git versions Older git versions don't treat the --depth option correctly. While the git module tried to work around this and introduced subtle bugs, ansible/ansible-modules-core#3794 falls back to full checkouts. Don't run the tests then. --- .../integration/roles/test_git/tasks/main.yml | 48 +++++++++++++++++++ 1 file changed, 48 insertions(+) diff --git a/test/integration/roles/test_git/tasks/main.yml b/test/integration/roles/test_git/tasks/main.yml index 18eaeffdfe..2212e43aee 100644 --- a/test/integration/roles/test_git/tasks/main.yml +++ b/test/integration/roles/test_git/tasks/main.yml @@ -19,6 +19,7 @@ - name: set role facts set_fact: checkout_dir: '{{ output_dir }}/git' + repo_dir: '{{ output_dir }}/local_repos' repo_format1: 'https://github.com/jimi-c/test_role' repo_format2: 'git@github.com:jimi-c/test_role.git' repo_format3: 'ssh://git@github.com/jimi-c/test_role.git' @@ -44,6 +45,11 @@ shell: git --version | grep 'git version' | sed 's/git version //' register: git_version +- name: set dummy git config + shell: git config --global user.email "noreply@example.com"; git config --global user.name "Ansible Test Runner" + +- name: create repo_dir + file: path={{repo_dir}} state=directory # # Test repo=https://github.com/... @@ -595,6 +601,7 @@ dest: '{{ checkout_dir }}' depth: 1 version: master + when: git_version.stdout | version_compare("1.8.2", '>=') - name: switch to older branch with depth=1 (uses fetch) git: @@ -603,10 +610,51 @@ depth: 1 version: earlybranch register: git_fetch + when: git_version.stdout | version_compare("1.8.2", '>=') - name: ensure the fetch succeeded assert: that: git_fetch|success + when: git_version.stdout | version_compare("1.8.2", '>=') + +- name: clear checkout_dir + file: state=absent path={{ checkout_dir }} + +# test for https://github.com/ansible/ansible-modules-core/issues/3782 +# make sure shallow fetch works when no version is specified + +- name: prepare old git repo + shell: git init; echo "1" > a; git add a; git commit -m "1" + args: + chdir: "{{repo_dir}}" + +- name: checkout old repo + git: + repo: '{{ repo_dir }}' + dest: '{{ checkout_dir }}' + depth: 1 + +- name: "update repo" + shell: echo "2" > a; git commit -a -m "2" + args: + chdir: "{{repo_dir}}" + +- name: fetch updated repo + git: + repo: '{{ repo_dir }}' + dest: '{{ checkout_dir }}' + depth: 1 + register: git_fetch + ignore_errors: yes + +- name: read file + shell: cat {{ checkout_dir }}/a + +- name: check update arrived + assert: + that: + - "{{ lookup('file', checkout_dir+'/a' )}} == 2" + - git_fetch|changed - name: clear checkout_dir file: state=absent path={{ checkout_dir }}