Skip to content

Commit a4c1c79

Browse files
authored
Add arbitrary options to git clone commands (#176)
1 parent a0ed7a2 commit a4c1c79

File tree

2 files changed

+32
-4
lines changed

2 files changed

+32
-4
lines changed

command/git/commands.go

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,24 @@ func (g *Git) Init() *command.Model {
1010
}
1111

1212
// Clone a repository into a new directory.
13-
func (g *Git) Clone(repo string) *command.Model {
14-
return g.command("clone", repo, ".")
13+
func (g *Git) Clone(repo string, opts ...string) *command.Model {
14+
args := []string{"clone"}
15+
args = append(args, opts...)
16+
args = append(args, repo)
17+
args = append(args, ".")
18+
return g.command(args...)
1519
}
1620

1721
// CloneTagOrBranch is recursively clones a tag or branch.
18-
func (g *Git) CloneTagOrBranch(repo, tagOrBranch string) *command.Model {
19-
return g.command("clone", "--recursive", "--branch", tagOrBranch, repo, ".")
22+
func (g *Git) CloneTagOrBranch(repo, tagOrBranch string, opts ...string) *command.Model {
23+
args := []string{"clone"}
24+
args = append(args, "--recursive")
25+
args = append(args, []string{"--branch", tagOrBranch}...)
26+
args = append(args, opts...)
27+
args = append(args, repo)
28+
args = append(args, ".")
29+
30+
return g.command(args...)
2031
}
2132

2233
// RemoteList shows a list of existing remote urls with remote names.

command/git/commands_test.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,23 @@ func TestGitCommands(t *testing.T) {
3636
command: (&Git{}).Log("%H", "refs/head/hcnarb"),
3737
want: `git "log" "-1" "--format=%H" "refs/head/hcnarb"`,
3838
},
39+
// Clone
40+
{
41+
command: (&Git{}).Clone("https://github.com/bitrise-io/go-utils.git"),
42+
want: `git "clone" "https://github.com/bitrise-io/go-utils.git" "."`,
43+
},
44+
{
45+
command: (&Git{}).Clone("https://github.com/bitrise-io/go-utils.git", "--depth=1"),
46+
want: `git "clone" "--depth=1" "https://github.com/bitrise-io/go-utils.git" "."`,
47+
},
48+
{
49+
command: (&Git{}).CloneTagOrBranch("https://github.com/bitrise-io/go-utils.git", "v1"),
50+
want: `git "clone" "--recursive" "--branch" "v1" "https://github.com/bitrise-io/go-utils.git" "."`,
51+
},
52+
{
53+
command: (&Git{}).CloneTagOrBranch("https://github.com/bitrise-io/go-utils.git", "v1", "--depth=1"),
54+
want: `git "clone" "--recursive" "--branch" "v1" "--depth=1" "https://github.com/bitrise-io/go-utils.git" "."`,
55+
},
3956
}
4057

4158
for _, testCase := range testCases {

0 commit comments

Comments
 (0)