Add --upstream-remote-name flag to gh replo clone (#5619)

This commit is contained in:
Ahmed Adan 2022-05-24 07:12:01 -04:00 committed by GitHub
parent eb4439d781
commit 31bee2e639
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 74 additions and 27 deletions

View file

@ -367,12 +367,12 @@ func RunClone(cloneURL string, args []string) (target string, err error) {
return
}
func AddUpstreamRemote(upstreamURL, cloneDir string, branches []string) error {
args := []string{"-C", cloneDir, "remote", "add"}
func AddNamedRemote(url, name, dir string, branches []string) error {
args := []string{"-C", dir, "remote", "add"}
for _, branch := range branches {
args = append(args, "-t", branch)
}
args = append(args, "-f", "upstream", upstreamURL)
args = append(args, "-f", name, url)
cloneCmd, err := GitCommand(args...)
if err != nil {
return err

View file

@ -181,37 +181,40 @@ func TestParseExtraCloneArgs(t *testing.T) {
}
}
func TestAddUpstreamRemote(t *testing.T) {
func TestAddNamedRemote(t *testing.T) {
tests := []struct {
name string
upstreamURL string
cloneDir string
branches []string
want string
title string
name string
url string
dir string
branches []string
want string
}{
{
name: "fetch all",
upstreamURL: "URL",
cloneDir: "DIRECTORY",
branches: []string{},
want: "git -C DIRECTORY remote add -f upstream URL",
title: "fetch all",
name: "test",
url: "URL",
dir: "DIRECTORY",
branches: []string{},
want: "git -C DIRECTORY remote add -f test URL",
},
{
name: "fetch specific branches only",
upstreamURL: "URL",
cloneDir: "DIRECTORY",
branches: []string{"master", "dev"},
want: "git -C DIRECTORY remote add -t master -t dev -f upstream URL",
title: "fetch specific branches only",
name: "test",
url: "URL",
dir: "DIRECTORY",
branches: []string{"trunk", "dev"},
want: "git -C DIRECTORY remote add -t trunk -t dev -f test URL",
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
t.Run(tt.title, func(t *testing.T) {
cs, cmdTeardown := run.Stub()
defer cmdTeardown(t)
cs.Register(tt.want, 0, "")
err := AddUpstreamRemote(tt.upstreamURL, tt.cloneDir, tt.branches)
err := AddNamedRemote(tt.url, tt.name, tt.dir, tt.branches)
if err != nil {
t.Fatalf("error running command `git remote add -f`: %v", err)
}