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

Commit 591aed1

Browse files
committed
Support for clone without checkout
1 parent e9247ce commit 591aed1

File tree

3 files changed

+25
-1
lines changed

3 files changed

+25
-1
lines changed

options.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@ type CloneOptions struct {
4141
ReferenceName plumbing.ReferenceName
4242
// Fetch only ReferenceName if true.
4343
SingleBranch bool
44+
// No checkout of HEAD after clone if true.
45+
NoCheckout bool
4446
// Limit fetching to the specified number of commits.
4547
Depth int
4648
// RecurseSubmodules after the clone is created, initialize all submodules

repository.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -449,7 +449,7 @@ func (r *Repository) clone(ctx context.Context, o *CloneOptions) error {
449449
return err
450450
}
451451

452-
if r.wt != nil {
452+
if r.wt != nil && !o.NoCheckout {
453453
w, err := r.Worktree()
454454
if err != nil {
455455
return err

repository_test.go

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -448,6 +448,28 @@ func (s *RepositorySuite) TestPlainCloneWithRecurseSubmodules(c *C) {
448448
c.Assert(cfg.Submodules, HasLen, 2)
449449
}
450450

451+
func (s *RepositorySuite) TestPlainCloneNoCheckout(c *C) {
452+
dir, err := ioutil.TempDir("", "plain-clone-no-checkout")
453+
c.Assert(err, IsNil)
454+
defer os.RemoveAll(dir)
455+
456+
path := fixtures.ByTag("submodule").One().Worktree().Root()
457+
r, err := PlainClone(dir, false, &CloneOptions{
458+
URL: path,
459+
NoCheckout: true,
460+
RecurseSubmodules: DefaultSubmoduleRecursionDepth,
461+
})
462+
c.Assert(err, IsNil)
463+
464+
h, err := r.Head()
465+
c.Assert(err, IsNil)
466+
c.Assert(h.Hash().String(), Equals, "b685400c1f9316f350965a5993d350bc746b0bf4")
467+
468+
fi, err := osfs.New(dir).ReadDir("")
469+
c.Assert(err, IsNil)
470+
c.Assert(fi, HasLen, 1) // .git
471+
}
472+
451473
func (s *RepositorySuite) TestFetch(c *C) {
452474
r, _ := Init(memory.NewStorage(), nil)
453475
_, err := r.CreateRemote(&config.RemoteConfig{

0 commit comments

Comments
 (0)