From 1ea1becf23a09bf8208ff26370e1064596faba4d Mon Sep 17 00:00:00 2001 From: Miyurz Date: Tue, 28 Mar 2017 18:11:25 +0530 Subject: [PATCH] =?UTF-8?q?Fixes=20bug=20https://github.com/ansible/ansibl?= =?UTF-8?q?e/issues/22455=20-=20Git=20reset=E2=80=A6=20(#22502)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Fixes bug https://github.com/ansible/ansible/issues/22455 - Git reset fails when file with the name 'origin' is present in the repository * #22455 Integration test for git module to test if it clones a repository with a file named origin * Fixed yaml errors for test/integration/roles/test_git_clone/tasks/main.yml * Removed the newly added target git and moved the code to test/integration/targets/git * Reorganised code structure as per comments * Fixed playbook name * Added code that didn't make it to the playbook before. * No longer need git.yml * Remove non tasks specific code from tasks file and use existing variables * Removed msg var from the vars.yml --- lib/ansible/modules/source_control/git.py | 2 +- test/integration/targets/git/tasks/main.yml | 1 + .../targets/git/tasks/reset-origin.yml | 27 +++++++++++++++++++ 3 files changed, 29 insertions(+), 1 deletion(-) create mode 100644 test/integration/targets/git/tasks/reset-origin.yml diff --git a/lib/ansible/modules/source_control/git.py b/lib/ansible/modules/source_control/git.py index 91bc93cfee0..2a58f0d0f6d 100644 --- a/lib/ansible/modules/source_control/git.py +++ b/lib/ansible/modules/source_control/git.py @@ -816,7 +816,7 @@ def switch_version(git_path, module, dest, remote, version, verify_commit, depth if rc != 0: module.fail_json(msg="Failed to checkout branch %s" % branch, stdout=out, stderr=err, rc=rc) - cmd = "%s reset --hard %s" % (git_path, remote) + cmd = "%s reset --hard %s --" % (git_path, remote) else: # FIXME check for local_branch first, should have been fetched already if is_remote_branch(git_path, module, dest, remote, version): diff --git a/test/integration/targets/git/tasks/main.yml b/test/integration/targets/git/tasks/main.yml index c8ac11a1dbb..0f3687f21e8 100644 --- a/test/integration/targets/git/tasks/main.yml +++ b/test/integration/targets/git/tasks/main.yml @@ -29,3 +29,4 @@ - include: checkout-new-tag.yml - include: tag-verification.yml - include: localmods.yml +- include: reset-origin.yml diff --git a/test/integration/targets/git/tasks/reset-origin.yml b/test/integration/targets/git/tasks/reset-origin.yml new file mode 100644 index 00000000000..383c02baed5 --- /dev/null +++ b/test/integration/targets/git/tasks/reset-origin.yml @@ -0,0 +1,27 @@ +--- + +- name: Clean up the directories + file: + state: absent + path: "{{ item }}" + with_items: + - "{{ repo_dir }}/origin" + - "{{ checkout_dir }}" + +- name: Create a directory + file: + name: "{{ repo_dir }}/origin" + state: directory + +- name: Initialise the repo with a file named origin,see github.com/ansible/ansible/pull/22502 + shell: git init; echo "PR 22502" > origin; git add origin; git commit -m "PR 22502" + args: + chdir: "{{ repo_dir }}/origin" + +- name: Clone a git repo with file named origin + git: + repo: "{{ repo_dir }}/origin" + dest: "{{ checkout_dir }}" + remote: origin + update: no + register: status