snapshot of https://github.com/go-gitea/gitea.git (main, 2026-09-15; blobs > 131072B omitted)
Some checks failed
cache-seeder / prune (push) Has been skipped
cache-seeder / frontend (push) Failing after 3s
cache-seeder / python (push) Failing after 3s
cache-seeder / gobuild (push) Failing after 4s
cache-seeder / lint (bindata, lint-backend) (push) Failing after 3s
giteabot backport / giteabot (push) Has been skipped
giteabot / giteabot (push) Has been skipped
cache-prune / prune (push) Has been skipped
release-nightly-snapcraft / build-and-publish (ubuntu-24.04) (push) Has been cancelled
release-nightly-snapcraft / build-and-publish (ubuntu-24.04-arm) (push) Has been cancelled
release-nightly / nightly-binary (push) Has been cancelled
release-nightly / nightly-container (push) Has been cancelled
cron-renovate / cron-renovate (push) Has been skipped
Some checks failed
cache-seeder / prune (push) Has been skipped
cache-seeder / frontend (push) Failing after 3s
cache-seeder / python (push) Failing after 3s
cache-seeder / gobuild (push) Failing after 4s
cache-seeder / lint (bindata, lint-backend) (push) Failing after 3s
giteabot backport / giteabot (push) Has been skipped
giteabot / giteabot (push) Has been skipped
cache-prune / prune (push) Has been skipped
release-nightly-snapcraft / build-and-publish (ubuntu-24.04) (push) Has been cancelled
release-nightly-snapcraft / build-and-publish (ubuntu-24.04-arm) (push) Has been cancelled
release-nightly / nightly-binary (push) Has been cancelled
release-nightly / nightly-container (push) Has been cancelled
cron-renovate / cron-renovate (push) Has been skipped
This commit is contained in:
60
modules/git/ref_test.go
Normal file
60
modules/git/ref_test.go
Normal file
@@ -0,0 +1,60 @@
|
||||
// Copyright 2020 The Gitea Authors. All rights reserved.
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
package git
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestRefName(t *testing.T) {
|
||||
// Test branch names (with and without slash).
|
||||
assert.Equal(t, "foo", RefName("refs/heads/foo").BranchName())
|
||||
assert.Equal(t, "feature/foo", RefName("refs/heads/feature/foo").BranchName())
|
||||
|
||||
// Test tag names (with and without slash).
|
||||
assert.Equal(t, "foo", RefName("refs/tags/foo").TagName())
|
||||
assert.Equal(t, "release/foo", RefName("refs/tags/release/foo").TagName())
|
||||
|
||||
// Test pull names
|
||||
pullIndex, ok := RefName("refs/pull/1/head").PullIndex()
|
||||
assert.True(t, ok)
|
||||
assert.EqualValues(t, 1, pullIndex)
|
||||
assert.True(t, RefName("refs/pull/1/head").IsPull())
|
||||
assert.True(t, RefName("refs/pull/1/merge").IsPull())
|
||||
assert.Equal(t, "my/pull", RefName("refs/pull/my/pull/head").ShortName())
|
||||
|
||||
// Test for branch names
|
||||
assert.Equal(t, "main", RefName("refs/for/main").ForBranchName())
|
||||
assert.Equal(t, "my/branch", RefName("refs/for/my/branch").ForBranchName())
|
||||
|
||||
// Test commit hashes.
|
||||
assert.Equal(t, "c0ffee", RefName("c0ffee").ShortName())
|
||||
}
|
||||
|
||||
func TestRefWebLinkPath(t *testing.T) {
|
||||
assert.Equal(t, "branch/foo", RefName("refs/heads/foo").RefWebLinkPath())
|
||||
assert.Equal(t, "tag/foo", RefName("refs/tags/foo").RefWebLinkPath())
|
||||
assert.Equal(t, "commit/c0ffee", RefName("c0ffee").RefWebLinkPath())
|
||||
}
|
||||
|
||||
func TestParseRefSuffix(t *testing.T) {
|
||||
cases := []struct {
|
||||
ref, name, suffix string
|
||||
}{
|
||||
{"main", "main", ""},
|
||||
{"main^", "main", "^"},
|
||||
{"main^2", "main", "^2"},
|
||||
{"main~3", "main", "~3"},
|
||||
{"main@{yesterday}", "main", "@{yesterday}"},
|
||||
{"main~2^", "main", "~2^"},
|
||||
{"main^~2", "main", "^~2"},
|
||||
}
|
||||
for _, c := range cases {
|
||||
name, suffix := ParseRefSuffix(c.ref)
|
||||
assert.Equal(t, c.name, name, "ref: %s", c.ref)
|
||||
assert.Equal(t, c.suffix, suffix, "ref: %s", c.ref)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user