mirror of
https://gitea.com/gitea/tea.git
synced 2026-10-26 11:01:25 +01:00
feat(pr): merge with the repository's defaults, ready, gh flags and ✓ lines for pr mutations
pr merge takes the method from the repository's default merge style instead of always merging (D22), accepts gh's --merge, --squash and --rebase next to -s/--method, refuses methods the repository disables, and adds -d/--delete-branch (defaulting to the repository setting), --auto, -t, -b, -F and -e. On a terminal it asks for the method and branch deletion with the defaults preselected, without a picker when the current branch has a pull request. It reports "✓ Squashed and merged pull request alice/x#3 (title)", the deleted remote branch, and switches off and deletes the local head branch; --json returns the merged pull request. Merged, closed and draft pull requests are reported before anything is asked. -s without a value points at --squash. pr checkout names the local branch after the head branch when that name is free or already at the head, falling back to OWNER/BRANCH for forks and pr/NUMBER (D13), fetches and switches quietly, reports "✓ Checked out #1 into feat/one", and has the alias co. pr clean reports what it deleted and that a remote branch was already gone. pr create asks for the title and body, then "What's next?": submit, submit as a draft, add metadata or change the branches, without the AGit question up front or a final confirmation. It pushes an unpushed head with --set-upstream --quiet ("✓ Pushed feat/one to origin"), prints "✓ Created pull request alice/x#9 (title)" and the URL, and adds --fill, --web, the alias new, the gh shorthands, and milestones by title. New tea pr ready [--undo]. pr close and reopen take -c/--comment, close takes -d/--delete-branch, and both say when the pull request already is in that state. pr edit reports "✓ Edited", takes the singular gh reviewer flags (the plurals still work), milestones by title and --remove-milestone. pr diff is colored and paged on a terminal and byte-exact when piped, with --name-only, --color and --web. Every pull request argument accepts #N, URLs and branch names and defaults to the current branch's pull request. Signed-off-by: bircni <bircni@icloud.com>
This commit is contained in:
28 files changed
+1169
-504
No files matched your search
@@ -111,7 +111,7 @@ func CheckoutPull(ctx context.Context, runner Runner, options CheckoutOptions) (
|
||||
tracking = options.HeadRemote + "/" + options.HeadBranch
|
||||
}
|
||||
fetchArgs := append([]string{}, options.CredentialArgs...)
|
||||
fetchArgs = append(fetchArgs, "fetch", "--no-tags", "--", fetchRemote, fetchRef)
|
||||
fetchArgs = append(fetchArgs, "fetch", "--quiet", "--no-tags", "--", fetchRemote, fetchRef)
|
||||
if _, err := run(fetchArgs...); err != nil {
|
||||
return CheckoutResult{}, err
|
||||
}
|
||||
@@ -136,11 +136,11 @@ func CheckoutPull(ctx context.Context, runner Runner, options CheckoutOptions) (
|
||||
}
|
||||
}
|
||||
}
|
||||
switchArgs := []string{"switch", "--detach", commit}
|
||||
switchArgs := []string{"switch", "--quiet", "--detach", commit}
|
||||
if !options.Detached {
|
||||
switchArgs = []string{"switch", "--create", options.Branch, commit}
|
||||
switchArgs = []string{"switch", "--quiet", "--create", options.Branch, commit}
|
||||
if existing {
|
||||
switchArgs = []string{"switch", options.Branch}
|
||||
switchArgs = []string{"switch", "--quiet", options.Branch}
|
||||
}
|
||||
}
|
||||
if _, err := run(switchArgs...); err != nil {
|
||||
|
||||
@@ -68,7 +68,7 @@ func TestPullCheckoutValidatesBeforeChangingGitState(t *testing.T) {
|
||||
result, err := CheckoutPull(context.Background(), runner, options)
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, CheckoutResult{Branch: "pr/7", Commit: "abc123", Remote: "origin"}, result)
|
||||
require.Equal(t, []string{"rev-parse --is-inside-work-tree", "check-ref-format --branch pr/7", "status --porcelain=v1 --untracked-files=normal", "for-each-ref --format=%(refname) refs/heads/", "fetch --no-tags -- origin refs/pull/7/head", "rev-parse --verify FETCH_HEAD^{commit}", "switch --create pr/7 abc123", "config branch.pr/7.tea-pr 7", "config branch.pr/7.tea-base-remote origin"}, runner.calls)
|
||||
require.Equal(t, []string{"rev-parse --is-inside-work-tree", "check-ref-format --branch pr/7", "status --porcelain=v1 --untracked-files=normal", "for-each-ref --format=%(refname) refs/heads/", "fetch --quiet --no-tags -- origin refs/pull/7/head", "rev-parse --verify FETCH_HEAD^{commit}", "switch --quiet --create pr/7 abc123", "config branch.pr/7.tea-pr 7", "config branch.pr/7.tea-base-remote origin"}, runner.calls)
|
||||
}
|
||||
|
||||
func TestPullCheckoutRejectsChangedHead(t *testing.T) {
|
||||
@@ -89,7 +89,7 @@ func TestPullCheckoutScopesCredentialArgumentsToFetch(t *testing.T) {
|
||||
for _, call := range runner.calls {
|
||||
if strings.HasPrefix(call, "-c ") {
|
||||
credentialCalls++
|
||||
require.Equal(t, "-c credential.https://example.test.helper=!tea-helper fetch --no-tags -- origin refs/pull/7/head", call)
|
||||
require.Equal(t, "-c credential.https://example.test.helper=!tea-helper fetch --quiet --no-tags -- origin refs/pull/7/head", call)
|
||||
}
|
||||
}
|
||||
require.Equal(t, 1, credentialCalls)
|
||||
@@ -101,7 +101,7 @@ func TestDetachedCheckoutDoesNotCreateOrChangeBranches(t *testing.T) {
|
||||
result, err := CheckoutPull(context.Background(), runner, CheckoutOptions{Directory: "/work", Remote: "origin", Number: 7, Detached: true, ExpectedCommit: "abc123"})
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, CheckoutResult{Detached: true, Commit: "abc123", Remote: "origin"}, result)
|
||||
require.Equal(t, "switch --detach abc123", runner.calls[len(runner.calls)-1])
|
||||
require.Equal(t, "switch --quiet --detach abc123", runner.calls[len(runner.calls)-1])
|
||||
for _, call := range runner.calls {
|
||||
require.False(t, strings.HasPrefix(call, "config "))
|
||||
require.False(t, strings.HasPrefix(call, "for-each-ref"))
|
||||
@@ -127,7 +127,7 @@ func TestPullCheckoutReusesMatchingBranch(t *testing.T) {
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, "abc123", result.Commit)
|
||||
require.Contains(t, runner.calls, "rev-parse --verify refs/heads/pr/7^{commit}")
|
||||
require.Equal(t, "switch pr/7", runner.calls[len(runner.calls)-3])
|
||||
require.Equal(t, "switch --quiet pr/7", runner.calls[len(runner.calls)-3])
|
||||
runner = &checkoutRunner{collision: true}
|
||||
_, err = CheckoutPull(context.Background(), runner, CheckoutOptions{Directory: "/work", Remote: "origin", Number: 7, Branch: "pr/7", ExpectedCommit: "different"})
|
||||
require.ErrorContains(t, err, "already exists with a different commit")
|
||||
@@ -150,7 +150,7 @@ func TestPullCheckoutUpdatesOnlyByFastForward(t *testing.T) {
|
||||
}
|
||||
} else {
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, []string{"switch pr/7", "merge --ff-only --no-edit abc123"}, runner.calls[len(runner.calls)-4:len(runner.calls)-2])
|
||||
require.Equal(t, []string{"switch --quiet pr/7", "merge --ff-only --no-edit abc123"}, runner.calls[len(runner.calls)-4:len(runner.calls)-2])
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -164,7 +164,7 @@ func TestPullCheckoutTracksHeadBranch(t *testing.T) {
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, CheckoutResult{Branch: "pr/7", Commit: "abc123", Remote: "pulls/bob", Tracking: "pulls/bob/feature"}, result)
|
||||
require.Contains(t, runner.calls, "check-ref-format --branch feature")
|
||||
require.Contains(t, runner.calls, "fetch --no-tags -- pulls/bob refs/heads/feature")
|
||||
require.Contains(t, runner.calls, "fetch --quiet --no-tags -- pulls/bob refs/heads/feature")
|
||||
require.Contains(t, runner.calls, "config branch.pr/7.remote pulls/bob")
|
||||
require.Contains(t, runner.calls, "config branch.pr/7.merge refs/heads/feature")
|
||||
require.Equal(t, []string{"config branch.pr/7.tea-pr 7", "config branch.pr/7.tea-base-remote origin"}, runner.calls[len(runner.calls)-2:])
|
||||
|
||||
@@ -185,7 +185,7 @@ func CleanPull(ctx context.Context, runner Runner, opts CleanOptions) (CleanResu
|
||||
}
|
||||
current, err := run("symbolic-ref", "--short", "HEAD")
|
||||
if err == nil && current == opts.LocalBranch {
|
||||
if _, err := run("switch", "--", opts.DefaultBranch); err != nil {
|
||||
if _, err := run("switch", "--quiet", "--", opts.DefaultBranch); err != nil {
|
||||
return CleanResult{}, fmt.Errorf("could not switch to %s before deleting %s: %w", opts.DefaultBranch, opts.LocalBranch, err)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -122,7 +122,7 @@ func TestCleanPullDeletesLocalAndRemoteBranches(t *testing.T) {
|
||||
})
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, CleanResult{LocalBranch: "feature", Remote: "origin", RemoteBranch: "feature", DefaultBranch: "main", RemoteDeleted: true}, result)
|
||||
require.Contains(t, runner.calls, "switch -- main")
|
||||
require.Contains(t, runner.calls, "switch --quiet -- main")
|
||||
require.Contains(t, runner.calls, "branch -D -- feature")
|
||||
require.Contains(t, runner.calls, "-c credential.helper=tea push --delete -- origin feature")
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user