Skip to content
Open
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
32 changes: 21 additions & 11 deletions git.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -74,12 +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)
}
if err := g.command("git", "config", "url.https://.insteadOf", "git://").Run(); err != nil {
return fmt.Errorf("failed to configure github url: %s", err)
}
return nil
}

Expand All @@ -104,6 +103,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.
Expand All @@ -114,8 +119,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)
}
}
Expand Down Expand Up @@ -147,6 +151,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.
Expand All @@ -166,7 +176,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)
}
}
Expand All @@ -181,7 +191,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)
}
}
Expand All @@ -196,7 +206,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)
}
}
Expand Down