{"action":"created","issue":{"url":"https://api.github.com/repos/ansible/ansible/issues/19074","repository_url":"https://api.github.com/repos/ansible/ansible","labels_url":"https://api.github.com/repos/ansible/ansible/issues/19074/labels{/name}","comments_url":"https://api.github.com/repos/ansible/ansible/issues/19074/comments","events_url":"https://api.github.com/repos/ansible/ansible/issues/19074/events","html_url":"https://github.com/ansible/ansible/issues/19074","id":194626321,"number":19074,"title":"git - in Ansible 2.1 switching a shallow clone from tag to branch fails","user":{"login":"adamchainz","id":857609,"avatar_url":"https://avatars.githubusercontent.com/u/857609?v=3","gravatar_id":"","url":"https://api.github.com/users/adamchainz","html_url":"https://github.com/adamchainz","followers_url":"https://api.github.com/users/adamchainz/followers","following_url":"https://api.github.com/users/adamchainz/following{/other_user}","gists_url":"https://api.github.com/users/adamchainz/gists{/gist_id}","starred_url":"https://api.github.com/users/adamchainz/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/adamchainz/subscriptions","organizations_url":"https://api.github.com/users/adamchainz/orgs","repos_url":"https://api.github.com/users/adamchainz/repos","events_url":"https://api.github.com/users/adamchainz/events{/privacy}","received_events_url":"https://api.github.com/users/adamchainz/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":9,"created_at":"2016-12-09T15:40:22Z","updated_at":"2016-12-09T15:40:26Z","closed_at":null,"body":"_From @adamchainz on June 1, 2016 14:54_\n\n##### ISSUE TYPE\n- Bug Report\n##### COMPONENT NAME\n\ngit module\n##### ANSIBLE VERSION\n\n```\nansible 2.1.0.0\n  config file =\n  configured module search path = Default w/o overrides\n```\n##### CONFIGURATION\n\nVanilla\n##### OS / ENVIRONMENT\n\nHappens on both OS X and Ubuntu with different versions of git (1.8 and 1.9)\n##### SUMMARY\n\nUpdating a shallow clone based on a tag to one based on a branch fails\n##### STEPS TO REPRODUCE\n\nRun this with `ansible-playbook -i 127.0.0.1, ~/tmp/test.yml; rm /tmp/testclone`\n\n```\n- hosts: 127.0.0.1\n  connection: local\n  gather_facts: no\n  tasks:\n    - name: initial clone from tag\n      git:\n        repo: git@github.com:adamchainz/nose-randomly.git\n        dest: /tmp/testclone\n        version: 1.2.0\n        depth: 1\n\n    - name: update to branch\n      git:\n        repo: git@github.com:adamchainz/nose-randomly.git\n        dest: /tmp/testclone\n        version: master\n        depth: 1\n```\n##### EXPECTED RESULTS\n\nOn Ansible 2.0.2.0, it works fine:\n\n```\nPLAY [127.0.0.1] ***************************************************************\n\nTASK [initial clone from tag] **************************************************\nchanged: [127.0.0.1]\n\nTASK [update to branch] ********************************************************\nchanged: [127.0.0.1]\n\nPLAY RECAP *********************************************************************\n127.0.0.1                  : ok=2    changed=2    unreachable=0    failed=0\n```\n##### ACTUAL RESULTS\n\nOn Ansible 2.1.0.0, I get:\n\n```\nPLAY [127.0.0.1] ***************************************************************\n\nTASK [initial clone from tag] **************************************************\nchanged: [127.0.0.1]\n\nTASK [update to branch] ********************************************************\nAn exception occurred during task execution. To see the full traceback, use -vvv. The error was: IOError: [Errno 2] No such file or directory: '/tmp/testclone/.git/refs/remotes/origin/HEAD'\nfatal: [127.0.0.1]: FAILED! => {\"changed\": false, \"failed\": true, \"module_stderr\": \"Traceback (most recent call last):\\n  File \\\"/var/folders/_z/wpddpg7d5hd6fd2zjn_fct7m0000gn/T/ansible_vBeq0g/ansible_module_git.py\\\", line 877, in <module>\\n    main()\\n  File \\\"/var/folders/_z/wpddpg7d5hd6fd2zjn_fct7m0000gn/T/ansible_vBeq0g/ansible_module_git.py\\\", line 832, in main\\n    fetch(git_path, module, repo, dest, version, remote, depth, bare, refspec)\\n  File \\\"/var/folders/_z/wpddpg7d5hd6fd2zjn_fct7m0000gn/T/ansible_vBeq0g/ansible_module_git.py\\\", line 530, in fetch\\n    currenthead = get_head_branch(git_path, module, dest, remote)\\n  File \\\"/var/folders/_z/wpddpg7d5hd6fd2zjn_fct7m0000gn/T/ansible_vBeq0g/ansible_module_git.py\\\", line 498, in get_head_branch\\n    f = open(os.path.join(repo_path, 'refs', 'remotes', remote, 'HEAD'))\\nIOError: [Errno 2] No such file or directory: '/tmp/testclone/.git/refs/remotes/origin/HEAD'\\n\", \"module_stdout\": \"\", \"msg\": \"MODULE FAILURE\", \"parsed\": false}\n\nNO MORE HOSTS LEFT *************************************************************\n    to retry, use: --limit @/Users/adamj/tmp/test.retry\n\nPLAY RECAP *********************************************************************\n127.0.0.1                  : ok=1    changed=1    unreachable=0    failed=1\n```\n\nIt looks like `fetch` has started assuming that if we're updating to a remote branch, we must currently be on a branch, as per lines 530-532:\n\n``` py\n        elif is_remote_branch(git_path, module, dest, repo, version):\n            currenthead = get_head_branch(git_path, module, dest, remote)\n            if currenthead != version:\n```\n\nor that `get_head_branch` should work, but doesn't, when we're on a tag. N.B. this is the contents of the `.git` directory after the clone from tag:\n\n```\n$ tree /tmp/testclone/.git/refs\n/tmp/testclone/.git/refs\n├── heads\n└── tags\n\n2 directories, 0 files\n```\n\n\n_Copied from original issue: ansible/ansible-modules-core#3817_"},"comment":{"url":"https://api.github.com/repos/ansible/ansible/issues/comments/266044109","html_url":"https://github.com/ansible/ansible/issues/19074#issuecomment-266044109","issue_url":"https://api.github.com/repos/ansible/ansible/issues/19074","id":266044109,"user":{"login":"adamchainz","id":857609,"avatar_url":"https://avatars.githubusercontent.com/u/857609?v=3","gravatar_id":"","url":"https://api.github.com/users/adamchainz","html_url":"https://github.com/adamchainz","followers_url":"https://api.github.com/users/adamchainz/followers","following_url":"https://api.github.com/users/adamchainz/following{/other_user}","gists_url":"https://api.github.com/users/adamchainz/gists{/gist_id}","starred_url":"https://api.github.com/users/adamchainz/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/adamchainz/subscriptions","organizations_url":"https://api.github.com/users/adamchainz/orgs","repos_url":"https://api.github.com/users/adamchainz/repos","events_url":"https://api.github.com/users/adamchainz/events{/privacy}","received_events_url":"https://api.github.com/users/adamchainz/received_events","type":"User","site_admin":false},"created_at":"2016-12-09T15:40:26Z","updated_at":"2016-12-09T15:40:26Z","body":"_From @ansibot on November 6, 2016 9:46_\n\n@ansible, ping. This issue is still waiting on your response.\n[click here for bot help](https://github.com/ansible/ansibullbot/blob/master/ISSUE_HELP.md)\n\n<!--- boilerplate: issue_renotify_maintainer --->\n"}}
{"actor":{"display_login":"adamchainz"}}