# test for https://github.com/ansible/ansible-modules-core/pull/5505 - name: LOCALMODS | prepare old git repo shell: | set -eEu rm -rf localmods mkdir localmods cd localmods git init echo "1" > a git add a git commit -m "1" args: chdir: "{{repo_dir}}" - name: LOCALMODS | checkout old repo git: repo: '{{ repo_dir }}/localmods' dest: '{{ checkout_dir }}' - name: LOCALMODS | "update repo" shell: echo "2" > a; git commit -a -m "2" args: chdir: "{{repo_dir}}/localmods" - name: LOCALMODS | "add local mods" shell: echo "3" > a args: chdir: "{{ checkout_dir }}" - name: LOCALMODS | fetch with local mods without force (should fail) git: repo: '{{ repo_dir }}/localmods' dest: '{{ checkout_dir }}' register: git_fetch ignore_errors: yes - name: LOCALMODS | check fetch with localmods failed assert: that: - git_fetch is failed - name: LOCALMODS | fetch with local mods with force git: repo: '{{ repo_dir }}/localmods' dest: '{{ checkout_dir }}' force: True register: git_fetch_force ignore_errors: yes - name: LOCALMODS | get "a" file slurp: src: '{{ checkout_dir }}/a' register: a_file - name: LOCALMODS | check update arrived assert: that: - a_file.content | b64decode | int == 2 - git_fetch_force is changed - name: LOCALMODS | clear checkout_dir file: state=absent path={{ checkout_dir }} # localmods and shallow clone - name: LOCALMODS | prepare old git repo shell: | set -eEu rm -rf localmods mkdir localmods cd localmods git init echo "1" > a git add a git commit -m "1" args: chdir: "{{repo_dir}}" - name: LOCALMODS | checkout old repo git: repo: '{{ repo_dir }}/localmods' dest: '{{ checkout_dir }}' depth: 1 - name: LOCALMODS | "update repo" shell: echo "2" > a; git commit -a -m "2" args: chdir: "{{repo_dir}}/localmods" - name: LOCALMODS | "add local mods" shell: echo "3" > a args: chdir: "{{ checkout_dir }}" - name: LOCALMODS | 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: LOCALMODS | check fetch with localmods failed assert: that: - git_fetch is failed - name: LOCALMODS | 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: LOCALMODS | get "a" file slurp: src: '{{ checkout_dir }}/a' register: a_file - name: LOCALMODS | check update arrived assert: that: - a_file.content | b64decode | int == 2 - git_fetch_force is changed - name: LOCALMODS | clear checkout_dir file: state=absent path={{ checkout_dir }} # Regression test for https://github.com/ansible/ansible/issues/83367 - name: Check that commits aren't overwritten vars: branch: "testbranch" block: - name: LOCALMODS | create branch on remote shell: | git checkout -b {{ branch }} echo "remote" > c git add c git commit -m "remote branch" args: chdir: "{{ repo_dir }}/localmods" - name: LOCALMODS | checkout repo with branch git: repo: '{{ repo_dir }}/localmods' dest: '{{ checkout_dir }}' version: '{{ branch }}' - name: LOCALMODS | make local commit shell: | echo "local" > b git add b git commit -m "local" git rev-parse HEAD args: chdir: "{{ checkout_dir }}" register: local_commit - name: LOCALMODS | rerun git module without force (should fail) git: repo: '{{ repo_dir }}/localmods' dest: '{{ checkout_dir }}' version: '{{ branch }}' register: rerun_no_force ignore_errors: yes - name: LOCALMODS | assert task failed with local commits ahead assert: that: - rerun_no_force is failed - name: LOCALMODS | verify local commit still exists after failed run shell: git rev-parse HEAD args: chdir: "{{ checkout_dir }}" register: commit_after_fail - name: LOCALMODS | assert local commit preserved after failure assert: that: - local_commit.stdout_lines[-1] == commit_after_fail.stdout - name: LOCALMODS | rerun git module with force (should succeed and reset) git: repo: '{{ repo_dir }}/localmods' dest: '{{ checkout_dir }}' version: '{{ branch }}' force: yes register: rerun_with_force - name: LOCALMODS | get remote commit hash shell: git rev-parse origin/{{ branch }} args: chdir: "{{ checkout_dir }}" register: remote_commit - name: LOCALMODS | verify local commit was reset shell: git rev-parse HEAD args: chdir: "{{ checkout_dir }}" register: commit_after_force - name: LOCALMODS | assert force reset to remote assert: that: - local_commit.stdout_lines[-1] != commit_after_force.stdout - commit_after_force.stdout == remote_commit.stdout - rerun_with_force is changed - name: LOCALMODS | make remote commit to create diverged state shell: | echo "remote2" > d git add d git commit -m "remote commit 2" args: chdir: "{{ repo_dir }}/localmods" - name: LOCALMODS | make local commit to complete diverged state shell: | echo "local2" > e git add e git commit -m "local commit 2" git rev-parse HEAD args: chdir: "{{ checkout_dir }}" register: diverged_local_commit - name: LOCALMODS | rerun git module with diverged branches without force (should fail) git: repo: '{{ repo_dir }}/localmods' dest: '{{ checkout_dir }}' version: '{{ branch }}' register: diverged_no_force ignore_errors: yes - name: LOCALMODS | assert task failed with diverged branches assert: that: - diverged_no_force is failed - "'local commits will be lost' in diverged_no_force.msg" - name: LOCALMODS | verify local commit still exists after diverged failure shell: git rev-parse HEAD args: chdir: "{{ checkout_dir }}" register: commit_after_diverged_fail - name: LOCALMODS | assert local commit preserved after diverged failure assert: that: - diverged_local_commit.stdout_lines[-1] == commit_after_diverged_fail.stdout - name: LOCALMODS | rerun git module with diverged branches with force (should succeed) git: repo: '{{ repo_dir }}/localmods' dest: '{{ checkout_dir }}' version: '{{ branch }}' force: yes register: diverged_with_force - name: LOCALMODS | get remote commit after diverged force shell: git rev-parse origin/{{ branch }} args: chdir: "{{ checkout_dir }}" register: remote_after_diverged - name: LOCALMODS | verify diverged branch was reset with force shell: git rev-parse HEAD args: chdir: "{{ checkout_dir }}" register: commit_after_diverged_force - name: LOCALMODS | assert force reset diverged branch to remote assert: that: - diverged_local_commit.stdout_lines[-1] != commit_after_diverged_force.stdout - commit_after_diverged_force.stdout == remote_after_diverged.stdout - diverged_with_force is changed always: - name: LOCALMODS | cleanup checkout_dir file: state: absent path: "{{ checkout_dir }}"