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

Reduce time required for cloning remote bases #857

Merged
merged 1 commit into from
Mar 7, 2019
Merged
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
47 changes: 42 additions & 5 deletions pkg/git/cloner.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,24 +41,61 @@ func ClonerUsingGitExec(repoSpec *RepoSpec) error {
}
cmd := exec.Command(
gitProgram,
"clone",
repoSpec.CloneSpec(),
"init",
repoSpec.cloneDir.String())
var out bytes.Buffer
cmd.Stdout = &out
err = cmd.Run()
if err != nil {
return errors.Wrapf(err, "trouble cloning %s", repoSpec.raw)
return errors.Wrapf(
err,
"trouble initializing empty git repo in %s",
repoSpec.cloneDir.String())
}

cmd = exec.Command(
gitProgram,
"remote",
"add",
"origin",
repoSpec.CloneSpec())
cmd.Stdout = &out
cmd.Dir = repoSpec.cloneDir.String()
err = cmd.Run()
if err != nil {
return errors.Wrapf(
err,
"trouble adding remote %s",
repoSpec.CloneSpec())
}

if repoSpec.ref == "" {
return nil
}
cmd = exec.Command(gitProgram, "checkout", repoSpec.ref)
cmd = exec.Command(
gitProgram,
"fetch",
"--depth=1",
"origin",
repoSpec.ref)
cmd.Stdout = &out
cmd.Dir = repoSpec.cloneDir.String()
err = cmd.Run()
if err != nil {
return errors.Wrapf(err, "trouble fetching %s", repoSpec.ref)
}

cmd = exec.Command(
gitProgram,
"reset",
"--hard",
"FETCH_HEAD")
cmd.Stdout = &out
cmd.Dir = repoSpec.cloneDir.String()
err = cmd.Run()
if err != nil {
return errors.Wrapf(
err, "trouble checking out href %s", repoSpec.ref)
err, "trouble hard resetting empty repository to %s", repoSpec.ref)
}
return nil
}
Expand Down