diff --git a/lib/ansible/modules/source_control/git.py b/lib/ansible/modules/source_control/git.py index 3bff95a0b83..e1bab75e8ef 100644 --- a/lib/ansible/modules/source_control/git.py +++ b/lib/ansible/modules/source_control/git.py @@ -590,7 +590,7 @@ def is_local_branch(git_path, module, dest, branch): def is_not_a_branch(git_path, module, dest): branches = get_branches(git_path, module, dest) for branch in branches: - if branch.startswith('* ') and ('no branch' in branch or 'detached from' in branch): + if branch.startswith('* ') and ('no branch' in branch or 'detached from' in branch or 'detached at' in branch): return True return False diff --git a/test/integration/targets/git/tasks/specific-revision.yml b/test/integration/targets/git/tasks/specific-revision.yml index 53f608bf672..26fa7cf3389 100644 --- a/test/integration/targets/git/tasks/specific-revision.yml +++ b/test/integration/targets/git/tasks/specific-revision.yml @@ -42,6 +42,17 @@ that: - 'git_result.stdout == "4e739a34719654db7b04896966e2354e1256ea5d"' +- name: SPECIFIC-REVISION | update to HEAD from detached HEAD state + git: + repo: "{{ repo_dir }}/format1" + dest: "{{ checkout_dir }}" + version: HEAD + register: git_result + +- assert: + that: + - git_result is changed + # Test a revision not available under refs/heads/ or refs/tags/ - name: SPECIFIC-REVISION | attempt to get unavailable revision