loop: set upstream tracking for sketch branches on outie
Fixes boldsoftware/sketch#143
Co-Authored-By: sketch <hello@sketch.dev>
Change-ID: s782ec3188bf0856ak
diff --git a/dockerimg/dockerimg.go b/dockerimg/dockerimg.go
index 19d90cf..94ba815 100644
--- a/dockerimg/dockerimg.go
+++ b/dockerimg/dockerimg.go
@@ -207,8 +207,15 @@
// errCh receives errors from operations that this function calls in separate goroutines.
errCh := make(chan error)
+ var upstream string
+ if out, err := combinedOutput(ctx, "git", "branch", "--show-current"); err != nil {
+ slog.DebugContext(ctx, "git branch --show-current failed (continuing)", "error", err)
+ } else {
+ upstream = strings.TrimSpace(string(out))
+ }
+
// Start the git server
- gitSrv, err := newGitServer(gitRoot, config.PassthroughUpstream)
+ gitSrv, err := newGitServer(gitRoot, config.PassthroughUpstream, upstream)
if err != nil {
return fmt.Errorf("failed to start git server: %w", err)
}
@@ -241,12 +248,6 @@
commit = strings.TrimSpace(string(out))
}
- var upstream string
- if out, err := combinedOutput(ctx, "git", "branch", "--show-current"); err != nil {
- slog.DebugContext(ctx, "git branch --show-current failed (continuing)", "error", err)
- } else {
- upstream = strings.TrimSpace(string(out))
- }
if out, err := combinedOutput(ctx, "git", "config", "http.receivepack", "true"); err != nil {
return fmt.Errorf("git config http.receivepack true: %s: %w", out, err)
}
@@ -488,7 +489,7 @@
return gs.srv.Serve(gs.gitLn)
}
-func newGitServer(gitRoot string, configureUpstreamPassthrough bool) (*gitServer, error) {
+func newGitServer(gitRoot string, configureUpstreamPassthrough bool, upstream string) (*gitServer, error) {
ret := &gitServer{
pass: rand.Text(),
}
@@ -509,7 +510,7 @@
var hooksDir string
if configureUpstreamPassthrough {
- hooksDir, err = setupHooksDir(gitRoot)
+ hooksDir, err = setupHooksDir(upstream)
if err != nil {
return nil, fmt.Errorf("failed to setup hooks directory: %w", err)
}