diff options
-rw-r--r-- | options.go | 2 | ||||
-rw-r--r-- | repository.go | 2 | ||||
-rw-r--r-- | repository_test.go | 22 |
3 files changed, 25 insertions, 1 deletions
@@ -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 diff --git a/repository.go b/repository.go index 8a966c6..24d025d 100644 --- a/repository.go +++ b/repository.go @@ -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 diff --git a/repository_test.go b/repository_test.go index cf0805a..ef37e37 100644 --- a/repository_test.go +++ b/repository_test.go @@ -448,6 +448,28 @@ func (s *RepositorySuite) TestPlainCloneWithRecurseSubmodules(c *C) { c.Assert(cfg.Submodules, HasLen, 2) } +func (s *RepositorySuite) TestPlainCloneNoCheckout(c *C) { + 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{ |