|
@@ -32,7 +32,7 @@ func Clone(remoteURL string) (string, error) {
|
|
return cloneGitRepo(repo)
|
|
return cloneGitRepo(repo)
|
|
}
|
|
}
|
|
|
|
|
|
-func cloneGitRepo(repo gitRepo) (string, error) {
|
|
|
|
|
|
+func cloneGitRepo(repo gitRepo) (checkoutDir string, err error) {
|
|
fetch := fetchArgs(repo.remote, repo.ref)
|
|
fetch := fetchArgs(repo.remote, repo.ref)
|
|
|
|
|
|
root, err := ioutil.TempDir("", "docker-build-git")
|
|
root, err := ioutil.TempDir("", "docker-build-git")
|
|
@@ -40,6 +40,12 @@ func cloneGitRepo(repo gitRepo) (string, error) {
|
|
return "", err
|
|
return "", err
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ defer func() {
|
|
|
|
+ if err != nil {
|
|
|
|
+ os.RemoveAll(root)
|
|
|
|
+ }
|
|
|
|
+ }()
|
|
|
|
+
|
|
if out, err := gitWithinDir(root, "init"); err != nil {
|
|
if out, err := gitWithinDir(root, "init"); err != nil {
|
|
return "", errors.Wrapf(err, "failed to init repo at %s: %s", root, out)
|
|
return "", errors.Wrapf(err, "failed to init repo at %s: %s", root, out)
|
|
}
|
|
}
|
|
@@ -54,7 +60,7 @@ func cloneGitRepo(repo gitRepo) (string, error) {
|
|
return "", errors.Wrapf(err, "error fetching: %s", output)
|
|
return "", errors.Wrapf(err, "error fetching: %s", output)
|
|
}
|
|
}
|
|
|
|
|
|
- root, err = checkoutGit(root, repo.ref, repo.subdir)
|
|
|
|
|
|
+ checkoutDir, err = checkoutGit(root, repo.ref, repo.subdir)
|
|
if err != nil {
|
|
if err != nil {
|
|
return "", err
|
|
return "", err
|
|
}
|
|
}
|
|
@@ -66,7 +72,7 @@ func cloneGitRepo(repo gitRepo) (string, error) {
|
|
return "", errors.Wrapf(err, "error initializing submodules: %s", output)
|
|
return "", errors.Wrapf(err, "error initializing submodules: %s", output)
|
|
}
|
|
}
|
|
|
|
|
|
- return root, nil
|
|
|
|
|
|
+ return checkoutDir, nil
|
|
}
|
|
}
|
|
|
|
|
|
func parseRemoteURL(remoteURL string) (gitRepo, error) {
|
|
func parseRemoteURL(remoteURL string) (gitRepo, error) {
|