From 74cc74be93843587d33be0f874f1dd3db5ab7f53 Mon Sep 17 00:00:00 2001 From: Joe Hosteny Date: Tue, 28 Apr 2020 17:59:51 -0400 Subject: [PATCH 1/3] fix: ensure insteadOf gets picked up for submodules --- git.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/git.go b/git.go index 53f339d4..9609af33 100644 --- a/git.go +++ b/git.go @@ -74,10 +74,10 @@ func (g *GitClient) Init(branch string) error { if err := g.command("git", "config", "user.email", "concourse@local").Run(); err != nil { return fmt.Errorf("failed to configure git email: %s", err) } - if err := g.command("git", "config", "url.https://x-oauth-basic@github.com/.insteadOf", "git@github.com:").Run(); err != nil { + if err := g.command("git", "config", "--global", "url.https://x-oauth-basic@github.com/.insteadOf", "git@github.com:").Run(); err != nil { return fmt.Errorf("failed to configure github url: %s", err) } - if err := g.command("git", "config", "url.https://.insteadOf", "git://").Run(); err != nil { + if err := g.command("git", "config", "--global", "url.https://.insteadOf", "git://").Run(); err != nil { return fmt.Errorf("failed to configure github url: %s", err) } return nil From ea72560b517b92891daa09fdbc278650d51ad386 Mon Sep 17 00:00:00 2001 From: Joe Hosteny Date: Wed, 27 May 2020 20:46:57 -0400 Subject: [PATCH 2/3] fix: avoid global configuration for submodules --- git.go | 31 ++++++++++++++++++++++--------- 1 file changed, 22 insertions(+), 9 deletions(-) diff --git a/git.go b/git.go index 9609af33..21dad2e0 100644 --- a/git.go +++ b/git.go @@ -60,6 +60,11 @@ func (g *GitClient) command(name string, arg ...string) *exec.Cmd { return cmd } +func (g *GitClient) submoduleUpdateCommand(arg ...string) *exec.Cmd { + s := []string{"-c", "url.https://x-oauth-basic@github.com/.insteadOf=git@github.com:", "submodule", "update", "--init", "--recursive"} + return g.command("git", append(s, arg...)...) +} + // Init ... func (g *GitClient) Init(branch string) error { if err := g.command("git", "init").Run(); err != nil { @@ -74,10 +79,7 @@ func (g *GitClient) Init(branch string) error { if err := g.command("git", "config", "user.email", "concourse@local").Run(); err != nil { return fmt.Errorf("failed to configure git email: %s", err) } - if err := g.command("git", "config", "--global", "url.https://x-oauth-basic@github.com/.insteadOf", "git@github.com:").Run(); err != nil { - return fmt.Errorf("failed to configure github url: %s", err) - } - if err := g.command("git", "config", "--global", "url.https://.insteadOf", "git://").Run(); err != nil { + if err := g.command("git", "config", "url.https://x-oauth-basic@github.com/.insteadOf", "git@github.com:").Run(); err != nil { return fmt.Errorf("failed to configure github url: %s", err) } return nil @@ -104,6 +106,12 @@ func (g *GitClient) Pull(uri, branch string, depth int, submodules bool, fetchTa if submodules { args = append(args, "--recurse-submodules") } + + // This must be prepended to the command if submodules are pulled + if submodules { + s := []string{"-c", "url.https://x-oauth-basic@github.com/.insteadOf=git@github.com:"} + args = append(s, args...) + } cmd := g.command("git", args...) // Discard output to have zero chance of logging the access token. @@ -114,8 +122,7 @@ func (g *GitClient) Pull(uri, branch string, depth int, submodules bool, fetchTa return fmt.Errorf("pull failed: %s", cmd) } if submodules { - submodulesGet := g.command("git", "submodule", "update", "--init", "--recursive") - if err := submodulesGet.Run(); err != nil { + if err := g.submoduleUpdateCommand().Run(); err != nil { return fmt.Errorf("submodule update failed: %s", err) } } @@ -147,6 +154,12 @@ func (g *GitClient) Fetch(uri string, prNumber int, depth int, submodules bool) if submodules { args = append(args, "--recurse-submodules") } + + // This must be prepended to the command if submodules are fetched + if submodules { + s := []string{"-c", "url.https://x-oauth-basic@github.com/.insteadOf=git@github.com:"} + args = append(s, args...) + } cmd := g.command("git", args...) // Discard output to have zero chance of logging the access token. @@ -166,7 +179,7 @@ func (g *GitClient) Checkout(branch, sha string, submodules bool) error { } if submodules { - if err := g.command("git", "submodule", "update", "--init", "--recursive", "--checkout").Run(); err != nil { + if err := g.submoduleUpdateCommand("--checkout").Run(); err != nil { return fmt.Errorf("submodule update failed: %s", err) } } @@ -181,7 +194,7 @@ func (g *GitClient) Merge(sha string, submodules bool) error { } if submodules { - if err := g.command("git", "submodule", "update", "--init", "--recursive", "--merge").Run(); err != nil { + if err := g.submoduleUpdateCommand("--merge").Run(); err != nil { return fmt.Errorf("submodule update failed: %s", err) } } @@ -196,7 +209,7 @@ func (g *GitClient) Rebase(baseRef string, headSha string, submodules bool) erro } if submodules { - if err := g.command("git", "submodule", "update", "--init", "--recursive", "--rebase").Run(); err != nil { + if err := g.submoduleUpdateCommand("--rebase").Run(); err != nil { return fmt.Errorf("submodule update failed: %s", err) } } From 573e2ba709d1a4d520026f0ee9db8db4d2718edc Mon Sep 17 00:00:00 2001 From: Joe Hosteny Date: Mon, 2 Nov 2020 11:01:20 -0500 Subject: [PATCH 3/3] fix: remove unnecessary repo level config --- git.go | 3 --- 1 file changed, 3 deletions(-) diff --git a/git.go b/git.go index 21dad2e0..6858ccba 100644 --- a/git.go +++ b/git.go @@ -79,9 +79,6 @@ func (g *GitClient) Init(branch string) error { if err := g.command("git", "config", "user.email", "concourse@local").Run(); err != nil { return fmt.Errorf("failed to configure git email: %s", err) } - if err := g.command("git", "config", "url.https://x-oauth-basic@github.com/.insteadOf", "git@github.com:").Run(); err != nil { - return fmt.Errorf("failed to configure github url: %s", err) - } return nil }