Skip to content

Commit 0d8e6f7

Browse files
arschlesAaron Schlesinger
authored andcommitted
fix(build.go): run appropriate commands inside the repo
1 parent 16b80a1 commit 0d8e6f7

1 file changed

Lines changed: 21 additions & 17 deletions

File tree

pkg/gitreceive/build.go

Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,12 @@ func (e errGitShaTooShort) Error() string {
2828
return fmt.Sprintf("git sha %s was too short", e.sha)
2929
}
3030

31+
func repoCmd(repoDir, first string, others ...string) *exec.Cmd {
32+
cmd := exec.Command(first, others...)
33+
cmd.Dir = repoDir
34+
return cmd
35+
}
36+
3137
func build(conf *Config, builderKey, gitSha string) error {
3238
// HTTP_PREFIX="http"
3339
// REMOTE_STORAGE="0"
@@ -147,20 +153,18 @@ func build(conf *Config, builderKey, gitSha string) error {
147153
// cd $REPO_DIR
148154
// # use Procfile if provided, otherwise try default process types from ./release
149155
// git archive --format=tar.gz ${GIT_SHA} > ${APP_NAME}.tar.gz
150-
cmd := exec.Command("git", "archive", "--format=tar.gz", fmt.Sprintf("%s > %s.tar.gz", gitSha, appName))
151-
cmd.Dir = repoDir
152-
cmd.Stdout = os.Stdout
153-
cmd.Stderr = os.Stderr
154-
if err := cmd.Run(); err != nil {
155-
return fmt.Errorf("running %s (%s)", strings.Join(cmd.Args, " "), err)
156+
gitArchiveCmd := repoCmd(repoDir, "git", "archive", "--format=tar.gz", fmt.Sprintf("%s > %s.tar.gz", gitSha, appName))
157+
gitArchiveCmd.Stdout = os.Stdout
158+
gitArchiveCmd.Stderr = os.Stderr
159+
if err := gitArchiveCmd.Run(); err != nil {
160+
return fmt.Errorf("running %s (%s)", strings.Join(gitArchiveCmd.Args, " "), err)
156161
}
157162
// tar -xzf ${APP_NAME}.tar.gz -C $TMP_DIR/
158-
tarCmd := exec.Command("tar", "-xzf", fmt.Sprintf("%s.tar.gz", appName), "-C", fmt.Sprintf("%s/", tmpDir))
159-
tarCmd.Dir = repoDir
163+
tarCmd := repoCmd("tar", "-xzf", fmt.Sprintf("%s.tar.gz", appName), "-C", fmt.Sprintf("%s/", tmpDir))
160164
tarCmd.Stdout = os.Stdout
161165
tarCmd.Stderr = os.Stderr
162166
if err := tarCmd.Run(); err != nil {
163-
return fmt.Errorf("running %s", strings.Join(cmd.Args, " "))
167+
return fmt.Errorf("running %s", strings.Join(tarCmd.Args, " "))
164168
}
165169

166170
// USING_DOCKERFILE=true
@@ -251,12 +255,12 @@ func build(conf *Config, builderKey, gitSha string) error {
251255
//
252256
// git archive --format=tar.gz ${GIT_SHA} > ${APP_NAME}.tar.gz
253257

254-
gitArchiveCmd := exec.Command("git", "archive", "--format=tar.gz", fmt.Sprintf("%s > %s.tar.gz", gitSha, appName))
255-
gitArchiveCmd.Dir = repoDir
256-
gitArchiveCmd.Stdout = os.Stdout
257-
gitArchiveCmd.Stderr = os.Stderr
258-
if err := gitArchiveCmd.Run(); err != nil {
259-
return fmt.Errorf("running %s (%s)", strings.Join(cmd.Args, " "), err)
258+
// TODO: same command is done above, is this one necessary at all?
259+
gitArchiveCmd2 := repoCmd("git", "archive", "--format=tar.gz", fmt.Sprintf("%s > %s.tar.gz", gitSha, appName))
260+
gitArchiveCmd2.Stdout = os.Stdout
261+
gitArchiveCmd2.Stderr = os.Stderr
262+
if err := gitArchiveCmd2.Run(); err != nil {
263+
return fmt.Errorf("running %s (%s)", strings.Join(gitArchiveCmd2.Args, " "), err)
260264
}
261265

262266
//
@@ -299,6 +303,7 @@ func build(conf *Config, builderKey, gitSha string) error {
299303
"mb",
300304
fmt.Sprintf("%s://%s:%s/git", storage.schema(), storage.host(), storage.port()),
301305
)
306+
302307
// Don't look for errors here. Buckets may already exist
303308
makeBucketCmd.Run()
304309

@@ -491,8 +496,7 @@ func build(conf *Config, builderKey, gitSha string) error {
491496
// cd $REPO_DIR
492497
// git gc &>/dev/null
493498

494-
gcCmd := exec.Command("git", "gc")
495-
gcCmd.Dir = repoDir
499+
gcCmd := repoCmd("git", "gc")
496500
if err := gcCmd.Run(); err != nil {
497501
return fmt.Errorf("cleaning up the repository with %s (%s)", strings.Join(gcCmd.Args, " "), err)
498502
// TODO: is it ok not to exit even if the repo was not cleaned up

0 commit comments

Comments
 (0)