Skip to content

Commit

Permalink
Merge pull request src-d#721 from rykov/clone-no-checkout
Browse files Browse the repository at this point in the history
Support for clone without checkout (git clone -n)
  • Loading branch information
mcuadros committed Jan 18, 2018
2 parents e9247ce + 591aed1 commit f6aca08
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 1 deletion.
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) {
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

0 comments on commit f6aca08

Please sign in to comment.