mirror of
https://gitea.com/gitea/tea.git
synced 2026-10-26 19:11:25 +01:00
fix(pr): keep targeting the base repository after a fork PR checkout
Repository discovery preferred the current branch's upstream remote, which for a fork pull request is the pulls/<owner>/<repo> remote that pr checkout adds, so every later command targeted the fork. pr checkout now records the pull request number and base remote in branch.<name>.tea-pr and branch.<name>.tea-base-remote, discovery honors the recorded base remote, and it skips pulls/* head remotes. Signed-off-by: bircni <bircni@icloud.com>
This commit is contained in:
5 files changed
+50
-7
No files matched your search
@@ -23,7 +23,7 @@ func (r discoverRunner) Output(_ context.Context, dir string, prompt bool, args
|
||||
}
|
||||
|
||||
func TestDiscoverRemote(t *testing.T) {
|
||||
const head, tracking = "symbolic-ref --short HEAD", "config --get branch.main.remote"
|
||||
const head, tracking, base = "symbolic-ref --short HEAD", "config --get branch.main.remote", "config --get branch.main.tea-base-remote"
|
||||
for _, test := range []struct {
|
||||
name string
|
||||
runner discoverRunner
|
||||
@@ -33,7 +33,10 @@ func TestDiscoverRemote(t *testing.T) {
|
||||
}{
|
||||
{name: "preferred", preferred: "fork", want: "fork"},
|
||||
{name: "branch upstream", runner: discoverRunner{head: "main", tracking: "fork", "remote": "origin\nfork"}, want: "fork"},
|
||||
{name: "branch upstream with slashes", runner: discoverRunner{head: "main", tracking: "pulls/bob/project", "remote": "origin\npulls/bob/project"}, want: "pulls/bob/project"},
|
||||
{name: "branch upstream with slashes", runner: discoverRunner{head: "main", tracking: "team/fork", "remote": "origin\nteam/fork"}, want: "team/fork"},
|
||||
{name: "pull head remote", runner: discoverRunner{head: "main", tracking: "pulls/bob/project", "remote": "origin\npulls/bob/project"}, want: "origin"},
|
||||
{name: "recorded pull base", runner: discoverRunner{head: "main", tracking: "fork", base: "upstream", "remote": "origin\nupstream\nfork"}, want: "upstream"},
|
||||
{name: "removed pull base", runner: discoverRunner{head: "main", tracking: "fork", base: "gone", "remote": "origin\nfork"}, want: "fork"},
|
||||
{name: "local branch upstream", runner: discoverRunner{head: "main", tracking: ".", "remote": "origin\nfork"}, want: "origin"},
|
||||
{name: "upstream remote", runner: discoverRunner{"remote": "origin\nupstream"}, want: "upstream"},
|
||||
{name: "origin remote", runner: discoverRunner{"remote": "fork\norigin"}, want: "origin"},
|
||||
|
||||
Reference in new issue
Block a user