on the git module and its initial clone

I was browsing the git module code, and noticed that this module, when used initially on an empty target, performs a simple clone.

It basically just does this:


    cmd = "git clone %s %s" % (repo, dest)

In other words, it doesn not take into account the other module parameters, ‘version’ and ‘remote’.

Is there a specific reason for this? I’d expect the clone statement to take

“-o remote -b version”

when given?

or am I missing something?

Serge

After the initial clone, the git module then checks out the requested version, whether that is branch, tag, or SHA1. See switch_version(). Is something not working as expected?

sf

So if I understand this correctly, the initial clone will create a remote with the default name of ‘origin’?

How does that set the given ‘remote’ name afterwards?

Serge

After the initial clone, the git module then checks out the requested version, whether that is branch, tag, or SHA1. See switch_version(). Is something not working as expected?

So if I understand this correctly, the initial clone will create a remote with the default name of ‘origin’?

Yes.

How does that set the given ‘remote’ name afterwards?

If it is something you cloned via the git module, you can’t. If it is something the git module is taking over management of, you can then specify it here.

Do you need the ability to specify a different remote name for the clone? Can you describe what you’re trying to accomplish?

Thanks,
sf

Hi Stephen,

FYI -- the only PR that makes sense is to ansible/ansible.

I'm still not understanding why we need alternate remote names though.

If you are using this for deployment, you should not be working inside
that checkout.

Help me understand why?

I certain circustances we need to (manually) add other remotes. Having decent remote names helps.

I don’t understand why having the ‘remote’ name parameter if you can’t set it at the initial clone?

Serge

Help me understand why?

I certain circustances we need to (manually) add other remotes. Having decent remote names helps.

I don’t understand why having the ‘remote’ name parameter if you can’t set it at the initial clone?

Also: say I have a task like this:

  • git: repo=git://github.com/ansible/ansible.git dest=/opt/ansible/ansible-0.8/ version=release-0.8 force=yes remote=upstream

  • First clone will have a remote ‘origin’

  • on the next run it will error on the not exisiting remote ‘upstream’

I just tested that, and it fails:

TASK: [git repo=git://github.com/ansible/ansible.git dest=/opt/ansible/ansible-devel/ version=devel force=yes remote=upstream] *********************
failed: [ansible-pr-1] => {“failed”: true, “msg”: “fatal: ‘upstream’ does not appear to be a git repository\nfatal: The remote end hung up unexpectedly\n”}

Serge

Add support to name the remote at initial clone:

https://github.com/ansible/ansible/pull/1558

Serge

Hi

Has this been solved? I am stuck on the same problem…

git: repo=git://github.com/ansible/ansible.git dest=/var/www/my-project/ version=prod

I get the error:

failed: [ec2-54-242-237-165.compute-1.amazonaws.com] => {“cmd”: “git checkout --force prod”, “failed”: true, “rc”: 1}
stderr: error: pathspec ‘prod’ did not match any file(s) known to git.

msg: error: pathspec ‘prod’ did not match any file(s) known to git.

I have a remote branch on git named prod which i am trying to clone, but it is not letting me… any solutions to this?

Thanks,
Donald

ansible --version please?

@donald, which version of ansible? I believe this is fixed in current devel, give that a try.