Skip to content
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
19 changes: 15 additions & 4 deletions command/git/commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,24 @@ func (g *Git) Init() *command.Model {
}

// Clone a repository into a new directory.
func (g *Git) Clone(repo string) *command.Model {
return g.command("clone", repo, ".")
func (g *Git) Clone(repo string, opts ...string) *command.Model {
args := []string{"clone"}
args = append(args, opts...)
args = append(args, repo)
args = append(args, ".")
return g.command(args...)
}

// CloneTagOrBranch is recursively clones a tag or branch.
func (g *Git) CloneTagOrBranch(repo, tagOrBranch string) *command.Model {
return g.command("clone", "--recursive", "--branch", tagOrBranch, repo, ".")
func (g *Git) CloneTagOrBranch(repo, tagOrBranch string, opts ...string) *command.Model {
args := []string{"clone"}
args = append(args, "--recursive")
args = append(args, []string{"--branch", tagOrBranch}...)
args = append(args, opts...)
args = append(args, repo)
args = append(args, ".")

return g.command(args...)
}

// RemoteList shows a list of existing remote urls with remote names.
Expand Down
17 changes: 17 additions & 0 deletions command/git/commands_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,23 @@ func TestGitCommands(t *testing.T) {
command: (&Git{}).Log("%H", "refs/head/hcnarb"),
want: `git "log" "-1" "--format=%H" "refs/head/hcnarb"`,
},
// Clone
{
command: (&Git{}).Clone("https://github.com/bitrise-io/go-utils.git"),
want: `git "clone" "https://github.com/bitrise-io/go-utils.git" "."`,
},
{
command: (&Git{}).Clone("https://github.com/bitrise-io/go-utils.git", "--depth=1"),
want: `git "clone" "--depth=1" "https://github.com/bitrise-io/go-utils.git" "."`,
},
{
command: (&Git{}).CloneTagOrBranch("https://github.com/bitrise-io/go-utils.git", "v1"),
want: `git "clone" "--recursive" "--branch" "v1" "https://github.com/bitrise-io/go-utils.git" "."`,
},
{
command: (&Git{}).CloneTagOrBranch("https://github.com/bitrise-io/go-utils.git", "v1", "--depth=1"),
want: `git "clone" "--recursive" "--branch" "v1" "--depth=1" "https://github.com/bitrise-io/go-utils.git" "."`,
},
}

for _, testCase := range testCases {
Expand Down