Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix git commit hash ignored #2537

Merged
merged 2 commits into from
May 27, 2020
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
27 changes: 15 additions & 12 deletions api/internal/git/cloner.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
package git

import (
"bytes"
"log"
"os/exec"

Expand Down Expand Up @@ -34,34 +33,38 @@ func ClonerUsingGitExec(repoSpec *RepoSpec) error {
cmd := exec.Command(
gitProgram,
"clone",
"--depth=1",
repoSpec.CloneSpec(),
"-b",
repoSpec.Ref,
repoSpec.Dir.String())
var out bytes.Buffer
cmd.Stdout = &out
cmd.Stderr = &out
err = cmd.Run()
out, err := cmd.CombinedOutput()
if err != nil {
log.Printf("Error cloning git repo: %s", out.String())
log.Printf("Error cloning git repo: %s", out)
return errors.Wrapf(
err,
"trouble cloning git repo %v in %s",
repoSpec.CloneSpec(), repoSpec.Dir.String())
}

cmd = exec.Command(
gitProgram,
"checkout",
repoSpec.Ref)
cmd.Dir = repoSpec.Dir.String()
out, err = cmd.CombinedOutput()
if err != nil {
log.Printf("Error checking out ref: %s", out)
return errors.Wrapf(err, "trouble checking out %s", repoSpec.Ref)
}

cmd = exec.Command(
gitProgram,
"submodule",
"update",
"--init",
"--recursive")
cmd.Stdout = &out
cmd.Stderr = &out
cmd.Dir = repoSpec.Dir.String()
err = cmd.Run()
out, err = cmd.CombinedOutput()
if err != nil {
log.Printf("Error fetching submodules: %s", out)
return errors.Wrapf(err, "trouble fetching submodules for %s", repoSpec.CloneSpec())
}

Expand Down
2 changes: 2 additions & 0 deletions api/loader/getter.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ func getRemoteTarget(rs *remoteTargetSpec) error {
return err
}

rs.Dir = filesys.ConfirmedDir(rs.Dir.Join("repo"))

// Get the pwd
pwd, err := os.Getwd()
if err != nil {
Expand Down