Files
gitea-tea/internal/git/branch_test.go
T
bircni 1505df2bb1 feat(app): parse issue, pull request and run references
resolveRef accepts N, #N, [HOST/]OWNER/REPO#N and issue, pull request or run
URLs; a URL or qualified number selects its repository for the invocation and
must agree with --repo. resolveRefs does the same for several references.

pullSelector also accepts a head branch or OWNER:BRANCH and, without an
argument, finds the pull request of the checked-out branch: the one pr
checkout recorded in branch.<name>.tea-pr, else the open pull request whose
head is the branch's upstream in the upstream remote's repository, else one
whose head has the local branch's name, else N of a pr/N branch. This lets pr
commands find the pull request of a branch pr checkout created.

target.expandMe resolves @me in user-valued flags to the login tea acts as,
and git.CurrentBranchConfig reads the branch configuration involved.

Signed-off-by: bircni <bircni@icloud.com>
2026-10-11 22:48:50 +02:00

42 lines
1.7 KiB
Go

// Copyright 2026 The Gitea Authors. All rights reserved.
// SPDX-License-Identifier: MIT
package git
import (
"context"
"testing"
"github.com/stretchr/testify/require"
)
func TestCurrentBranchConfig(t *testing.T) {
const head = "symbolic-ref --short HEAD"
for _, test := range []struct {
name string
runner discoverRunner
want BranchConfig
err error
}{
{name: "detached", runner: discoverRunner{}, err: ErrNotOnBranch},
{name: "untracked", runner: discoverRunner{head: "topic"}, want: BranchConfig{Name: "topic"}},
{name: "tracking", runner: discoverRunner{
head: "feat/one", "config --get branch.feat/one.remote": "origin", "config --get branch.feat/one.merge": "refs/heads/feat/one",
}, want: BranchConfig{Name: "feat/one", Remote: "origin", Merge: "feat/one"}},
{name: "local upstream", runner: discoverRunner{
head: "topic", "config --get branch.topic.remote": ".", "config --get branch.topic.merge": "refs/heads/main",
}, want: BranchConfig{Name: "topic"}},
{name: "pr checkout", runner: discoverRunner{
head: "pr/17", "config --get branch.pr/17.remote": "pulls/bob/project", "config --get branch.pr/17.merge": "refs/heads/bob/fix",
"config --get branch.pr/17.tea-pr": "17", "config --get branch.pr/17.tea-base-remote": "origin",
}, want: BranchConfig{Name: "pr/17", Remote: "pulls/bob/project", Merge: "bob/fix", PullNumber: 17, BaseRemote: "origin"}},
{name: "malformed pull number", runner: discoverRunner{head: "x", "config --get branch.x.tea-pr": "seventeen"}, want: BranchConfig{Name: "x"}},
} {
t.Run(test.name, func(t *testing.T) {
config, err := CurrentBranchConfig(context.Background(), test.runner, "/work")
require.ErrorIs(t, err, test.err)
require.Equal(t, test.want, config)
})
}
}