Skip to content
This repository was archived by the owner on Sep 11, 2020. It is now read-only.

git: added Clone.NoCheckout option #705

Closed
Nhoya opened this issue Jan 1, 2018 · 7 comments
Closed

git: added Clone.NoCheckout option #705

Nhoya opened this issue Jan 1, 2018 · 7 comments

Comments

@Nhoya
Copy link

Nhoya commented Jan 1, 2018

Hi, i was wondering if was possible to reproduce the -n option of git clone

@mcuadros
Copy link
Contributor

Should be that easy as skip this line: https://github.com/src-d/go-git/blob/v4.0.0/worktree.go#L181

@rykov
Copy link
Contributor

rykov commented Jan 15, 2018

@mcuadros I didn't find where Repository's clone func calls Checkout on the worktree that you've linked.

Do you think that it could be implemented by adding a flag to CloneOptions that would disable this section of Repository's clone even if r.wt != nil?

https://github.com/src-d/go-git/blob/v4.0.0/repository.go#L452-L478

@rykov
Copy link
Contributor

rykov commented Jan 15, 2018

Something like this: master...rykov:master

@rykov
Copy link
Contributor

rykov commented Jan 16, 2018

@mcuadros I've taken another look at the documentation for git-clone and I think the changes that I've made on my fork follow the functionality closer than putting a condition just around Reset.

Here's what the docs say for --recurse-submodules:

This option is ignored if the cloned repository does not have a worktree/checkout (i.e. if any of --no-checkout/-n, --bare, or --mirror is given)

https://git-scm.com/docs/git-clone#git-clone---recurse-submodulesltpathspec

I'll add some tests and submit this as a PR

@Nhoya
Copy link
Author

Nhoya commented Jan 16, 2018

Pretty interesting, can you please provide an example usage?

@rykov
Copy link
Contributor

rykov commented Jan 17, 2018

@Nhoya So the behavior is similar to git clone --bare, in that the worktree is not created. However, with -n option, the metadata is still placed under the .git subdirectory, rather than in root.

Here's a modification of the basic example from the README with this flag enabled:

Info("git clone -n https://github.com/src-d/go-git")

_, err := git.PlainClone("/tmp/foo", false, &git.CloneOptions{
    URL:        "https://github.com/src-d/go-git",
    Progress:   os.Stdout,
    NoCheckout: true,
})

CheckIfError(err)

@Nhoya
Copy link
Author

Nhoya commented Jan 17, 2018

Hi and thanks for the answer

So retrieving commits with

r, _ := git.Clone(memory.NewStorage(), nil, &git.CloneOptions{
    URL:        "https://github.com/src-d/go-git",
    Progress:   os.Stdout,
    NoCheckout: true,
})
ref, _ := r.Head()
cIter, _ := r.Log(&git.LogOptions{From: ref.Hash()})

commits := ""
_ = cIter.ForEach(func(c *object.Commit) error {
    commits += fmt.Sprintf("%s", c.Author)
    return nil
})

is still possible?

@mcuadros mcuadros changed the title git clone -n git: added Clone.NoCheckout option Feb 17, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants