diff --git a/changelogs/fragments/75608-git-fix-submodule-path.yml b/changelogs/fragments/75608-git-fix-submodule-path.yml new file mode 100644 index 00000000000..13c229f55e7 --- /dev/null +++ b/changelogs/fragments/75608-git-fix-submodule-path.yml @@ -0,0 +1,2 @@ +bugfixes: + - git - Fix git path used when .git file is present (https://github.com/ansible/ansible/issues/75608). diff --git a/lib/ansible/modules/git.py b/lib/ansible/modules/git.py index 8418cda611c..dd0223b117e 100644 --- a/lib/ansible/modules/git.py +++ b/lib/ansible/modules/git.py @@ -757,7 +757,8 @@ def get_repo_path(dest, bare): if os.path.isabs(gitdir): repo_path = gitdir else: - repo_path = os.path.join(repo_path.split('.git')[0], gitdir) + # Use original destination directory with data from .git file. + repo_path = os.path.join(dest, gitdir) if not os.path.isdir(repo_path): raise ValueError('%s is not a directory' % repo_path) return repo_path diff --git a/test/integration/targets/git/tasks/submodules.yml b/test/integration/targets/git/tasks/submodules.yml index 647d1e23b4e..0b311e7984d 100644 --- a/test/integration/targets/git/tasks/submodules.yml +++ b/test/integration/targets/git/tasks/submodules.yml @@ -122,3 +122,29 @@ - name: SUBMODULES | Enusre submodule2 is at the appropriate commit assert: that: '{{ submodule2.stdout_lines | length }} == 4' + +- name: SUBMODULES | clear checkout_dir + file: + state: absent + path: "{{ checkout_dir }}" + + +- name: SUBMODULES | Clone main submodule repository + git: + repo: "{{ repo_submodules }}" + dest: "{{ checkout_dir }}/test.gitdir" + version: 45c6c07ef10fd9e453d90207e63da1ce5bd3ae1e + recursive: yes + +- name: SUBMODULES | Test that cloning submodule with .git in directory name works + git: + repo: "{{ repo_submodule1 }}" + dest: "{{ checkout_dir }}/test.gitdir/submodule1" + +- name: SUBMODULES | List submodule1 + command: 'ls -1a {{ checkout_dir }}/test.gitdir/submodule1' + register: submodule1 + +- name: SUBMODULES | Ensure submodule1 is at the appropriate commit + assert: + that: '{{ submodule1.stdout_lines | length }} == 4'