tenseleyflow/shithub / e9c5337

Browse files

fix(git): inherit os.Environ in subprocess so hooks see SHITHUB_DATABASE_URL

Authored by espadonne
SHA
e9c5337975d4bc0e910f1cbfdbe2cb13a94284ed
Parents
4b5a1f6
Tree
af7dea5

1 changed file

StatusFile+-
M internal/git/protocol/exec.go 8 1
internal/git/protocol/exec.gomodified
@@ -7,6 +7,7 @@ import (
77
 	"context"
88
 	"errors"
99
 	"io"
10
+	"os"
1011
 	"os/exec"
1112
 	"sync"
1213
 	"time"
@@ -46,7 +47,13 @@ func Cmd(ctx context.Context, svc Service, gitDir string, advertiseRefs bool, ex
4647
 	args = append(args, gitDir)
4748
 	//nolint:gosec // G204: svc is an enum from a fixed set; gitDir is constructed via storage.RepoFS path validation.
4849
 	cmd := exec.CommandContext(ctx, string(svc), args...)
49
-	cmd.Env = extraEnv
50
+	// Append, don't replace. The pre-receive / post-receive hooks
51
+	// re-invoke shithubd, which reads SHITHUB_DATABASE_URL etc. from
52
+	// the environment via config.Load. Without inheriting os.Environ
53
+	// the hook fails with "DB URL not set" on every push. Later
54
+	// entries win in Go's exec.Cmd, so the SHITHUB_USER_ID / etc.
55
+	// values in extraEnv override any conflicting parent-env keys.
56
+	cmd.Env = append(os.Environ(), extraEnv...)
5057
 	cmd.WaitDelay = 250 * time.Millisecond
5158
 	return cmd
5259
 }