Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

git - in Ansible 2.1 switching a shallow clone from tag to branch fails #19074

Closed
adamchainz opened this issue Dec 9, 2016 · 18 comments
Closed
Labels
affects_2.1 This issue/PR affects Ansible v2.1 bug This issue/PR relates to a bug. module This issue/PR relates to a module.

Comments

@adamchainz
Copy link
Contributor

From @adamchainz on June 1, 2016 14:54

ISSUE TYPE
  • Bug Report
COMPONENT NAME

git module

ANSIBLE VERSION
ansible 2.1.0.0
  config file =
  configured module search path = Default w/o overrides
CONFIGURATION

Vanilla

OS / ENVIRONMENT

Happens on both OS X and Ubuntu with different versions of git (1.8 and 1.9)

SUMMARY

Updating a shallow clone based on a tag to one based on a branch fails

STEPS TO REPRODUCE

Run this with ansible-playbook -i 127.0.0.1, ~/tmp/test.yml; rm /tmp/testclone

- hosts: 127.0.0.1
  connection: local
  gather_facts: no
  tasks:
    - name: initial clone from tag
      git:
        repo: git@github.com:adamchainz/nose-randomly.git
        dest: /tmp/testclone
        version: 1.2.0
        depth: 1

    - name: update to branch
      git:
        repo: git@github.com:adamchainz/nose-randomly.git
        dest: /tmp/testclone
        version: master
        depth: 1
EXPECTED RESULTS

On Ansible 2.0.2.0, it works fine:

PLAY [127.0.0.1] ***************************************************************

TASK [initial clone from tag] **************************************************
changed: [127.0.0.1]

TASK [update to branch] ********************************************************
changed: [127.0.0.1]

PLAY RECAP *********************************************************************
127.0.0.1                  : ok=2    changed=2    unreachable=0    failed=0
ACTUAL RESULTS

On Ansible 2.1.0.0, I get:

PLAY [127.0.0.1] ***************************************************************

TASK [initial clone from tag] **************************************************
changed: [127.0.0.1]

TASK [update to branch] ********************************************************
An 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'
fatal: [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}

NO MORE HOSTS LEFT *************************************************************
    to retry, use: --limit @/Users/adamj/tmp/test.retry

PLAY RECAP *********************************************************************
127.0.0.1                  : ok=1    changed=1    unreachable=0    failed=1

It 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:

        elif is_remote_branch(git_path, module, dest, repo, version):
            currenthead = get_head_branch(git_path, module, dest, remote)
            if currenthead != version:

or 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:

$ tree /tmp/testclone/.git/refs
/tmp/testclone/.git/refs
├── heads
└── tags

2 directories, 0 files

Copied from original issue: ansible/ansible-modules-core#3817

@adamchainz
Copy link
Contributor Author

From @alikins on June 6, 2016 17:57

Pinging @robinro

@adamchainz
Copy link
Contributor Author

From @robinro on June 7, 2016 9:9

@adamchainz thanks for the report. You already found the problem in the code: get_head_branch probably doesn't do what we need in fetch with depth.

I don't have much time for the next 2 weeks to work on issues. Maybe you can come up with a fix and open a PR? I'd be happy to review it.
Probably one can just leave out the if currenthead != version test and always fetch the new version info.

There is currently another bug open with changes to the same function: ansible/ansible-modules-core#3794
Please consider to also add a test case to help future refactoring.

@adamchainz
Copy link
Contributor Author

From @ansibot on July 30, 2016 16:36

@ansible, ping. This issue is still waiting on your response.
click here for bot help

@adamchainz
Copy link
Contributor Author

From @danwashusen on August 26, 2016 0:31

I think I'm also seeing the same just trying to update a shallow clone...
git: repo={{ git_url }} dest={{ path }} version={{ git_version }} depth=1 accept_hostkey=yes force=yes

@adamchainz
Copy link
Contributor Author

From @ansibot on August 26, 2016 0:33

@ansible, ping. This issue is still waiting on your response.
click here for bot help

@adamchainz
Copy link
Contributor Author

From @robinro on August 26, 2016 15:43

@danwashusen
I believe your issue is different from the originally posted one. It sounds like
ansible/ansible-modules-core#3782, which was fixed in 2.1.1. Please open a new issue if this fix does not cover your usage.

@adamchainz
Copy link
Contributor Author

From @ansibot on September 12, 2016 16:58

@ansible, ping. This issue is still waiting on your response.
click here for bot help

@adamchainz
Copy link
Contributor Author

From @ansibot on October 6, 2016 14:34

@ansible, ping. This issue is still waiting on your response.
click here for bot help

@adamchainz
Copy link
Contributor Author

From @ansibot on October 22, 2016 8:51

@ansible, ping. This issue is still waiting on your response.
click here for bot help

@adamchainz
Copy link
Contributor Author

From @ansibot on November 6, 2016 9:46

@ansible, ping. This issue is still waiting on your response.
click here for bot help

@adamchainz
Copy link
Contributor Author

From @ansibot on November 22, 2016 9:54

@ansible, ping. This issue is still waiting on your response.
click here for bot help

@adamchainz
Copy link
Contributor Author

From @veger on December 3, 2016 15:39

I am unable to reproduce this. Using Ansible 2.2.0/Ubuntu 16.04 the first task fails as the tag was not available locally. When I fixed this issue (PR #5814) the provided test.yml completed successfully.

@adamchainz
Copy link
Contributor Author

From @ansibot on December 9, 2016 15:38

This repository has been locked. All new issues and pull requests should be filed in https://github.com/ansible/ansible

Please read through the repomerge page in the dev guide. The guide contains links to tools which automatically move your issue or pull request to the ansible/ansible repo.

@robinro
Copy link
Contributor

robinro commented Mar 28, 2017

I believe this is
resolved_by_pr #21712

@adamchainz For me your example runs fine on the current devel version. Please close this issue if it works for you.

@adamchainz
Copy link
Contributor Author

Works for me 👌

@hezronobuchele
Copy link

I'm experiencing the same issue on ansible 2.1.5.0 when both switching a shallow cloned repo from tag to branch or switching a shallow cloned repo from tag to another tag.

The issue seems to be fixed in devel, is it going to be backported to 2.1 given this task is about 2.1?

@adamchainz
Copy link
Contributor Author

@hezbucho things don't tend to get backported but you can backport yourself by copying the git module to library/git.py next to your playbooks

@hezronobuchele
Copy link

OK, thanks 👌

@ansibot ansibot added bug This issue/PR relates to a bug. and removed bug_report labels Mar 7, 2018
@ansible ansible locked and limited conversation to collaborators Apr 25, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
affects_2.1 This issue/PR affects Ansible v2.1 bug This issue/PR relates to a bug. module This issue/PR relates to a module.
Projects
None yet
Development

No branches or pull requests

5 participants