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.<default>.pushRemote=origin so pushes go to the fork.

Signed-off-by: bircni <bircni@icloud.com>
This commit is contained in:
bircni committed 2026-10-11 21:44:44 +02:00
1 parent b3dc3f47cb
commit 59bae60926
2 files changed
+8 -6

No files matched your search

+3 -1
View File
@@ -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())
}
+5 -5
View File
@@ -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)
}
}
}
}