Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

git: repository, Move isBare to CloneOptions. #1076

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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: 1 addition & 1 deletion _examples/azure_devops/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ func main() {
capability.ThinPack,
}

r, err := git.PlainClone(directory, false, &git.CloneOptions{
r, err := git.PlainClone(directory, &git.CloneOptions{
Auth: &http.BasicAuth{
Username: username,
Password: password,
Expand Down
12 changes: 4 additions & 8 deletions _examples/blame/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,10 @@ func main() {

// Clone the given repository.
Info("git clone %s %s", url, tmp)
r, err := git.PlainClone(
tmp,
false,
&git.CloneOptions{
URL: url,
Tags: git.NoTags,
},
)
r, err := git.PlainClone(tmp, &git.CloneOptions{
URL: url,
Tags: git.NoTags,
})
CheckIfError(err)

// Retrieve the branch's HEAD, to then get the HEAD commit.
Expand Down
2 changes: 1 addition & 1 deletion _examples/branch/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ func main() {

// Clone the given repository to the given directory
Info("git clone %s %s", url, directory)
r, err := git.PlainClone(directory, false, &git.CloneOptions{
r, err := git.PlainClone(directory, &git.CloneOptions{
URL: url,
})
CheckIfError(err)
Expand Down
2 changes: 1 addition & 1 deletion _examples/checkout-branch/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ func main() {

// Clone the given repository to the given directory
Info("git clone %s %s", url, directory)
r, err := git.PlainClone(directory, false, &git.CloneOptions{
r, err := git.PlainClone(directory, &git.CloneOptions{
URL: url,
})
CheckIfError(err)
Expand Down
2 changes: 1 addition & 1 deletion _examples/checkout/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ func main() {

// Clone the given repository to the given directory
Info("git clone %s %s", url, directory)
r, err := git.PlainClone(directory, false, &git.CloneOptions{
r, err := git.PlainClone(directory, &git.CloneOptions{
URL: url,
})

Expand Down
2 changes: 1 addition & 1 deletion _examples/clone/auth/basic/access_token/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ func main() {
// Clone the given repository to the given directory
Info("git clone %s %s", url, directory)

r, err := git.PlainClone(directory, false, &git.CloneOptions{
r, err := git.PlainClone(directory, &git.CloneOptions{
// The intended use of a GitHub personal access token is in replace of your password
// because access tokens can easily be revoked.
// https://help.github.com/articles/creating-a-personal-access-token-for-the-command-line/
Expand Down
2 changes: 1 addition & 1 deletion _examples/clone/auth/basic/username_password/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ func main() {
// Clone the given repository to the given directory
Info("git clone %s %s", url, directory)

r, err := git.PlainClone(directory, false, &git.CloneOptions{
r, err := git.PlainClone(directory, &git.CloneOptions{
Auth: &http.BasicAuth{
Username: username,
Password: password,
Expand Down
2 changes: 1 addition & 1 deletion _examples/clone/auth/ssh/private_key/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ func main() {
return
}

r, err := git.PlainClone(directory, false, &git.CloneOptions{
r, err := git.PlainClone(directory, &git.CloneOptions{
Auth: publicKeys,
URL: url,
Progress: os.Stdout,
Expand Down
2 changes: 1 addition & 1 deletion _examples/clone/auth/ssh/ssh_agent/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ func main() {
// Clone the given repository to the given directory
Info("git clone %s ", url)

r, err := git.PlainClone(directory, false, &git.CloneOptions{
r, err := git.PlainClone(directory, &git.CloneOptions{
Auth: authMethod,
URL: url,
Progress: os.Stdout,
Expand Down
2 changes: 1 addition & 1 deletion _examples/clone/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ func main() {
// Clone the given repository to the given directory
Info("git clone %s %s --recursive", url, directory)

r, err := git.PlainClone(directory, false, &git.CloneOptions{
r, err := git.PlainClone(directory, &git.CloneOptions{
URL: url,
RecurseSubmodules: git.DefaultSubmoduleRecursionDepth,
})
Expand Down
2 changes: 1 addition & 1 deletion _examples/context/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ func main() {

// Using PlainCloneContext we can provide to a context, if the context
// is cancelled, the clone operation stops gracefully.
_, err := git.PlainCloneContext(ctx, directory, false, &git.CloneOptions{
_, err := git.PlainCloneContext(ctx, directory, &git.CloneOptions{
URL: url,
Progress: os.Stdout,
})
Expand Down
2 changes: 1 addition & 1 deletion _examples/progress/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ func main() {
// Clone the given repository to the given directory
Info("git clone %s %s", url, directory)

_, err := git.PlainClone(directory, false, &git.CloneOptions{
_, err := git.PlainClone(directory, &git.CloneOptions{
URL: url,
Depth: 1,

Expand Down
2 changes: 1 addition & 1 deletion _examples/showcase/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ func main() {
// and fetching the objects, exactly as:
Info("git clone %s %s", url, path)

r, err := git.PlainClone(path, false, &git.CloneOptions{URL: url})
r, err := git.PlainClone(path, &git.CloneOptions{URL: url})
CheckIfError(err)

// Getting the latest commit on the current branch
Expand Down
2 changes: 1 addition & 1 deletion _examples/submodule/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ func main() {
// Clone the given repository to the given directory
Info("git clone %s %s --recursive", url, directory)

r, err := git.PlainClone(directory, false, &git.CloneOptions{
r, err := git.PlainClone(directory, &git.CloneOptions{
URL: url,
RecurseSubmodules: git.DefaultSubmoduleRecursionDepth,
})
Expand Down
2 changes: 1 addition & 1 deletion _examples/tag-create-push/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ func cloneRepo(url, dir, publicKeyPath string) (*git.Repository, error) {
}

Info("git clone %s", url)
r, err := git.PlainClone(dir, false, &git.CloneOptions{
r, err := git.PlainClone(dir, &git.CloneOptions{
Progress: os.Stdout,
URL: url,
Auth: auth,
Expand Down
6 changes: 3 additions & 3 deletions example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ func ExamplePlainClone() {
defer os.RemoveAll(dir) // clean up

// Clones the repository into the given dir, just as a normal git clone does
_, err = git.PlainClone(dir, false, &git.CloneOptions{
_, err = git.PlainClone(dir, &git.CloneOptions{
URL: "https://github.com/git-fixtures/basic.git",
})

Expand Down Expand Up @@ -79,7 +79,7 @@ func ExamplePlainClone_usernamePassword() {
defer os.RemoveAll(dir) // clean up

// Clones the repository into the given dir, just as a normal git clone does
_, err = git.PlainClone(dir, false, &git.CloneOptions{
_, err = git.PlainClone(dir, &git.CloneOptions{
URL: "https://github.com/git-fixtures/basic.git",
Auth: &http.BasicAuth{
Username: "username",
Expand All @@ -102,7 +102,7 @@ func ExamplePlainClone_accessToken() {
defer os.RemoveAll(dir) // clean up

// Clones the repository into the given dir, just as a normal git clone does
_, err = git.PlainClone(dir, false, &git.CloneOptions{
_, err = git.PlainClone(dir, &git.CloneOptions{
URL: "https://github.com/git-fixtures/basic.git",
Auth: &http.BasicAuth{
Username: "abc123", // anything except an empty string
Expand Down
2 changes: 2 additions & 0 deletions options.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ type CloneOptions struct {
ReferenceName plumbing.ReferenceName
// Fetch only ReferenceName if true.
SingleBranch bool
// Bare defines if the repository will have worktree (non-bare) or not (bare).
Bare bool
// Mirror clones the repository as a mirror.
//
// Compared to a bare clone, mirror not only maps local branches of the
Expand Down
77 changes: 46 additions & 31 deletions remote_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -753,8 +753,9 @@ func (s *RemoteSuite) TestPushDeleteReference(c *C) {
url, clean := s.TemporalDir()
defer clean()

r, err := PlainClone(url, true, &CloneOptions{
URL: fs.Root(),
r, err := PlainClone(url, &CloneOptions{
URL: fs.Root(),
Bare: true,
})
c.Assert(err, IsNil)

Expand All @@ -780,8 +781,9 @@ func (s *RemoteSuite) TestForcePushDeleteReference(c *C) {
url, clean := s.TemporalDir()
defer clean()

r, err := PlainClone(url, true, &CloneOptions{
URL: fs.Root(),
r, err := PlainClone(url, &CloneOptions{
URL: fs.Root(),
Bare: true,
})
c.Assert(err, IsNil)

Expand All @@ -808,8 +810,9 @@ func (s *RemoteSuite) TestPushRejectNonFastForward(c *C) {
url, clean := s.TemporalDir()
defer clean()

r, err := PlainClone(url, true, &CloneOptions{
URL: fs.Root(),
r, err := PlainClone(url, &CloneOptions{
URL: fs.Root(),
Bare: true,
})
c.Assert(err, IsNil)

Expand Down Expand Up @@ -1020,16 +1023,18 @@ func (s *RemoteSuite) TestPushPrune(c *C) {
url, clean := s.TemporalDir()
defer clean()

server, err := PlainClone(url, true, &CloneOptions{
URL: fs.Root(),
server, err := PlainClone(url, &CloneOptions{
URL: fs.Root(),
Bare: true,
})
c.Assert(err, IsNil)

dir, clean := s.TemporalDir()
defer clean()

r, err := PlainClone(dir, true, &CloneOptions{
URL: url,
r, err := PlainClone(dir, &CloneOptions{
URL: url,
Bare: true,
})
c.Assert(err, IsNil)

Expand Down Expand Up @@ -1083,16 +1088,18 @@ func (s *RemoteSuite) TestPushNewReference(c *C) {
url, clean := s.TemporalDir()
defer clean()

server, err := PlainClone(url, true, &CloneOptions{
URL: fs.Root(),
server, err := PlainClone(url, &CloneOptions{
URL: fs.Root(),
Bare: true,
})
c.Assert(err, IsNil)

dir, clean := s.TemporalDir()
defer clean()

r, err := PlainClone(dir, true, &CloneOptions{
URL: url,
r, err := PlainClone(dir, &CloneOptions{
URL: url,
Bare: true,
})
c.Assert(err, IsNil)

Expand Down Expand Up @@ -1122,16 +1129,18 @@ func (s *RemoteSuite) TestPushNewReferenceAndDeleteInBatch(c *C) {
url, clean := s.TemporalDir()
defer clean()

server, err := PlainClone(url, true, &CloneOptions{
URL: fs.Root(),
server, err := PlainClone(url, &CloneOptions{
URL: fs.Root(),
Bare: true,
})
c.Assert(err, IsNil)

dir, clean := s.TemporalDir()
defer clean()

r, err := PlainClone(dir, true, &CloneOptions{
URL: url,
r, err := PlainClone(dir, &CloneOptions{
URL: url,
Bare: true,
})
c.Assert(err, IsNil)

Expand Down Expand Up @@ -1450,16 +1459,18 @@ func (s *RemoteSuite) TestFetchPrune(c *C) {
url, clean := s.TemporalDir()
defer clean()

_, err := PlainClone(url, true, &CloneOptions{
URL: fs.Root(),
_, err := PlainClone(url, &CloneOptions{
URL: fs.Root(),
Bare: true,
})
c.Assert(err, IsNil)

dir, clean := s.TemporalDir()
defer clean()

r, err := PlainClone(dir, true, &CloneOptions{
URL: url,
r, err := PlainClone(dir, &CloneOptions{
URL: url,
Bare: true,
})
c.Assert(err, IsNil)

Expand All @@ -1477,8 +1488,9 @@ func (s *RemoteSuite) TestFetchPrune(c *C) {
dirSave, clean := s.TemporalDir()
defer clean()

rSave, err := PlainClone(dirSave, true, &CloneOptions{
URL: url,
rSave, err := PlainClone(dirSave, &CloneOptions{
URL: url,
Bare: true,
})
c.Assert(err, IsNil)

Expand Down Expand Up @@ -1507,16 +1519,18 @@ func (s *RemoteSuite) TestFetchPruneTags(c *C) {
url, clean := s.TemporalDir()
defer clean()

_, err := PlainClone(url, true, &CloneOptions{
URL: fs.Root(),
_, err := PlainClone(url, &CloneOptions{
URL: fs.Root(),
Bare: true,
})
c.Assert(err, IsNil)

dir, clean := s.TemporalDir()
defer clean()

r, err := PlainClone(dir, true, &CloneOptions{
URL: url,
r, err := PlainClone(dir, &CloneOptions{
URL: url,
Bare: true,
})
c.Assert(err, IsNil)

Expand All @@ -1534,8 +1548,9 @@ func (s *RemoteSuite) TestFetchPruneTags(c *C) {
dirSave, clean := s.TemporalDir()
defer clean()

rSave, err := PlainClone(dirSave, true, &CloneOptions{
URL: url,
rSave, err := PlainClone(dirSave, &CloneOptions{
URL: url,
Bare: true,
})
c.Assert(err, IsNil)

Expand Down Expand Up @@ -1623,7 +1638,7 @@ func (s *RemoteSuite) TestFetchAfterShallowClone(c *C) {
_ = CommitNewFile(c, remote, "File2")

// Clone the repo with a depth of 1
repo, err := PlainClone(repoDir, false, &CloneOptions{
repo, err := PlainClone(repoDir, &CloneOptions{
URL: remoteUrl,
Depth: 1,
Tags: NoTags,
Expand Down
13 changes: 5 additions & 8 deletions repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -453,10 +453,8 @@ func dotGitCommonDirectory(fs billy.Filesystem) (commonDir billy.Filesystem, err
// PlainClone a repository into the path with the given options, isBare defines
// if the new repository will be bare or normal. If the path is not empty
// ErrRepositoryAlreadyExists is returned.
//
// TODO(mcuadros): move isBare to CloneOptions in v5
func PlainClone(path string, isBare bool, o *CloneOptions) (*Repository, error) {
return PlainCloneContext(context.Background(), path, isBare, o)
func PlainClone(path string, o *CloneOptions) (*Repository, error) {
return PlainCloneContext(context.Background(), path, o)
}

// PlainCloneContext a repository into the path with the given options, isBare
Expand All @@ -467,18 +465,17 @@ func PlainClone(path string, isBare bool, o *CloneOptions) (*Repository, error)
// operation is complete, an error is returned. The context only affects the
// transport operations.
//
// TODO(mcuadros): move isBare to CloneOptions in v5
// TODO(smola): refuse upfront to clone on a non-empty directory in v5, see #1027
func PlainCloneContext(ctx context.Context, path string, isBare bool, o *CloneOptions) (*Repository, error) {
func PlainCloneContext(ctx context.Context, path string, o *CloneOptions) (*Repository, error) {
cleanup, cleanupParent, err := checkIfCleanupIsNeeded(path)
if err != nil {
return nil, err
}

if o.Mirror {
isBare = true
o.Bare = true
}
r, err := PlainInit(path, isBare)
r, err := PlainInit(path, o.Bare)
if err != nil {
return nil, err
}
Expand Down
Loading
Loading