fix(git): inherit os.Environ in subprocess so hooks see SHITHUB_DATABASE_URL
- SHA
e9c5337975d4bc0e910f1cbfdbe2cb13a94284ed- Parents
-
4b5a1f6 - Tree
af7dea5
e9c5337
e9c5337975d4bc0e910f1cbfdbe2cb13a94284ed4b5a1f6
af7dea5| Status | File | + | - |
|---|---|---|---|
| M |
internal/git/protocol/exec.go
|
8 | 1 |
internal/git/protocol/exec.gomodified@@ -7,6 +7,7 @@ import ( | ||
| 7 | 7 | "context" |
| 8 | 8 | "errors" |
| 9 | 9 | "io" |
| 10 | + "os" | |
| 10 | 11 | "os/exec" |
| 11 | 12 | "sync" |
| 12 | 13 | "time" |
@@ -46,7 +47,13 @@ func Cmd(ctx context.Context, svc Service, gitDir string, advertiseRefs bool, ex | ||
| 46 | 47 | args = append(args, gitDir) |
| 47 | 48 | //nolint:gosec // G204: svc is an enum from a fixed set; gitDir is constructed via storage.RepoFS path validation. |
| 48 | 49 | 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...) | |
| 50 | 57 | cmd.WaitDelay = 250 * time.Millisecond |
| 51 | 58 | return cmd |
| 52 | 59 | } |