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

Support for clone without checkout (git clone -n) #721

Merged
merged 1 commit into from
Jan 18, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions options.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ type CloneOptions struct {
ReferenceName plumbing.ReferenceName
// Fetch only ReferenceName if true.
SingleBranch bool
// No checkout of HEAD after clone if true.
NoCheckout bool
// Limit fetching to the specified number of commits.
Depth int
// RecurseSubmodules after the clone is created, initialize all submodules
Expand Down
2 changes: 1 addition & 1 deletion repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -449,7 +449,7 @@ func (r *Repository) clone(ctx context.Context, o *CloneOptions) error {
return err
}

if r.wt != nil {
if r.wt != nil && !o.NoCheckout {
w, err := r.Worktree()
if err != nil {
return err
Expand Down
22 changes: 22 additions & 0 deletions repository_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -448,6 +448,28 @@ func (s *RepositorySuite) TestPlainCloneWithRecurseSubmodules(c *C) {
c.Assert(cfg.Submodules, HasLen, 2)
}

func (s *RepositorySuite) TestPlainCloneNoCheckout(c *C) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we ensure that HEAD is pointing to the commit should be pointing?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mcuadros Take a look now - I've added a HEAD check

dir, err := ioutil.TempDir("", "plain-clone-no-checkout")
c.Assert(err, IsNil)
defer os.RemoveAll(dir)

path := fixtures.ByTag("submodule").One().Worktree().Root()
r, err := PlainClone(dir, false, &CloneOptions{
URL: path,
NoCheckout: true,
RecurseSubmodules: DefaultSubmoduleRecursionDepth,
})
c.Assert(err, IsNil)

h, err := r.Head()
c.Assert(err, IsNil)
c.Assert(h.Hash().String(), Equals, "b685400c1f9316f350965a5993d350bc746b0bf4")

fi, err := osfs.New(dir).ReadDir("")
c.Assert(err, IsNil)
c.Assert(fi, HasLen, 1) // .git
}

func (s *RepositorySuite) TestFetch(c *C) {
r, _ := Init(memory.NewStorage(), nil)
_, err := r.CreateRemote(&config.RemoteConfig{
Expand Down