From 59bae60926233e11eaea029f88db544c9d536450 Mon Sep 17 00:00:00 2001 From: bircni Date: Sun, 11 Oct 2026 21:44:44 +0200 Subject: [PATCH] fix(repo): keep pushes from a cloned fork on the fork Cloning a fork pointed the default branch at the upstream remote, so a plain `git push` targeted the parent repository. The branch still pulls from upstream, which keeps tea targeting the parent, but now sets branch..pushRemote=origin so pushes go to the fork. Signed-off-by: bircni --- internal/app/clone_test.go | 4 +++- internal/app/repo_mutations.go | 10 +++++----- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/internal/app/clone_test.go b/internal/app/clone_test.go index ffa7bf65..15d4f886 100644 --- a/internal/app/clone_test.go +++ b/internal/app/clone_test.go @@ -100,6 +100,7 @@ func TestCloneAddsUpstreamRemoteForForks(t *testing.T) { "remote add -- upstream " + parent: "", "config branch.main.remote upstream": "", "config branch.main.merge refs/heads/main": "", + "config branch.main.pushRemote origin": "", }} deps.Git = runner cwd := t.TempDir() @@ -109,9 +110,10 @@ func TestCloneAddsUpstreamRemoteForForks(t *testing.T) { "remote add -- upstream " + parent, "config branch.main.remote upstream", "config branch.main.merge refs/heads/main", + "config branch.main.pushRemote origin", }, runner.calls) clone := filepath.Join(cwd, "destination") - require.Equal(t, []string{cwd, clone, clone, clone}, runner.dirs) + require.Equal(t, []string{cwd, clone, clone, clone, clone}, runner.dirs) require.JSONEq(t, `{"id":8,"full_name":"bob/project","fork":true}`, out.String()) } diff --git a/internal/app/repo_mutations.go b/internal/app/repo_mutations.go index 07ff53bf..28f9b828 100644 --- a/internal/app/repo_mutations.go +++ b/internal/app/repo_mutations.go @@ -278,12 +278,12 @@ func (a *application) cloneRepository(cmd *cobra.Command, t target, item service if _, err := a.gitIn(cmd.Context(), clone, "remote", "add", "--", "upstream", upstream); err != nil { return fmt.Errorf("cloned the fork, but could not add the upstream remote: %w", err) } + // The default branch pulls from upstream, but pushes stay on the fork. if branch := item.Parent.DefaultBranch; branch != "" { - if _, err := a.gitIn(cmd.Context(), clone, "config", "branch."+branch+".remote", "upstream"); err != nil { - return fmt.Errorf("cloned the fork and added upstream, but could not configure branch tracking: %w", err) - } - if _, err := a.gitIn(cmd.Context(), clone, "config", "branch."+branch+".merge", "refs/heads/"+branch); err != nil { - return fmt.Errorf("cloned the fork and added upstream, but could not configure branch tracking: %w", err) + for _, setting := range [][2]string{{"remote", "upstream"}, {"merge", "refs/heads/" + branch}, {"pushRemote", "origin"}} { + if _, err := a.gitIn(cmd.Context(), clone, "config", "branch."+branch+"."+setting[0], setting[1]); err != nil { + return fmt.Errorf("cloned the fork and added upstream, but could not configure branch tracking: %w", err) + } } } }