1
0
Fork 0
mirror of https://codeberg.org/forgejo/forgejo.git synced 2024-11-26 09:09:36 -05:00

Use refname:strip-2 instead of refname:short when syncing tags (#28797) (#28811)

Backport #28797 by @lunny

Fix #28694 

Generally, `refname:short` should be equal to `refname:lstrip=2` except
`core.warnAmbiguousRefs is used to select the strict abbreviation mode.`

ref:
https://git-scm.com/docs/git-for-each-ref#Documentation/git-for-each-ref.txt-refname

Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com>
This commit is contained in:
Giteabot 2024-01-16 15:33:33 +08:00 committed by GitHub
parent 022552d5b6
commit 4746291b08
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 15 additions and 13 deletions

View file

@ -49,9 +49,9 @@ func TestFormat_Flag(t *testing.T) {
{ {
name: "multiple fields", name: "multiple fields",
givenFormat: foreachref.NewFormat("refname:short", "objecttype", "objectname"), givenFormat: foreachref.NewFormat("refname:lstrip=2", "objecttype", "objectname"),
wantFlag: "refname:short %(refname:short)%00objecttype %(objecttype)%00objectname %(objectname)%00%00", wantFlag: "refname:lstrip=2 %(refname:lstrip=2)%00objecttype %(objecttype)%00objectname %(objectname)%00%00",
}, },
} }

View file

@ -112,7 +112,9 @@ func (repo *Repository) GetTagWithID(idStr, name string) (*Tag, error) {
// GetTagInfos returns all tag infos of the repository. // GetTagInfos returns all tag infos of the repository.
func (repo *Repository) GetTagInfos(page, pageSize int) ([]*Tag, int, error) { func (repo *Repository) GetTagInfos(page, pageSize int) ([]*Tag, int, error) {
forEachRefFmt := foreachref.NewFormat("objecttype", "refname:short", "object", "objectname", "creator", "contents", "contents:signature") // Generally, refname:short should be equal to refname:lstrip=2 except core.warnAmbiguousRefs is used to select the strict abbreviation mode.
// https://git-scm.com/docs/git-for-each-ref#Documentation/git-for-each-ref.txt-refname
forEachRefFmt := foreachref.NewFormat("objecttype", "refname:lstrip=2", "object", "objectname", "creator", "contents", "contents:signature")
stdoutReader, stdoutWriter := io.Pipe() stdoutReader, stdoutWriter := io.Pipe()
defer stdoutReader.Close() defer stdoutReader.Close()
@ -162,7 +164,7 @@ func (repo *Repository) GetTagInfos(page, pageSize int) ([]*Tag, int, error) {
func parseTagRef(ref map[string]string) (tag *Tag, err error) { func parseTagRef(ref map[string]string) (tag *Tag, err error) {
tag = &Tag{ tag = &Tag{
Type: ref["objecttype"], Type: ref["objecttype"],
Name: ref["refname:short"], Name: ref["refname:lstrip=2"],
} }
tag.ID, err = NewIDFromString(ref["objectname"]) tag.ID, err = NewIDFromString(ref["objectname"])

View file

@ -210,7 +210,7 @@ func TestRepository_parseTagRef(t *testing.T) {
givenRef: map[string]string{ givenRef: map[string]string{
"objecttype": "commit", "objecttype": "commit",
"refname:short": "v1.9.1", "refname:lstrip=2": "v1.9.1",
// object will be empty for lightweight tags // object will be empty for lightweight tags
"object": "", "object": "",
"objectname": "ab23e4b7f4cd0caafe0174c0e7ef6d651ba72889", "objectname": "ab23e4b7f4cd0caafe0174c0e7ef6d651ba72889",
@ -239,7 +239,7 @@ func TestRepository_parseTagRef(t *testing.T) {
givenRef: map[string]string{ givenRef: map[string]string{
"objecttype": "tag", "objecttype": "tag",
"refname:short": "v0.0.1", "refname:lstrip=2": "v0.0.1",
// object will refer to commit hash for annotated tag // object will refer to commit hash for annotated tag
"object": "3325fd8a973321fd59455492976c042dde3fd1ca", "object": "3325fd8a973321fd59455492976c042dde3fd1ca",
"objectname": "8c68a1f06fc59c655b7e3905b159d761e91c53c9", "objectname": "8c68a1f06fc59c655b7e3905b159d761e91c53c9",
@ -268,7 +268,7 @@ func TestRepository_parseTagRef(t *testing.T) {
givenRef: map[string]string{ givenRef: map[string]string{
"objecttype": "tag", "objecttype": "tag",
"refname:short": "v0.0.1", "refname:lstrip=2": "v0.0.1",
"object": "3325fd8a973321fd59455492976c042dde3fd1ca", "object": "3325fd8a973321fd59455492976c042dde3fd1ca",
"objectname": "8c68a1f06fc59c655b7e3905b159d761e91c53c9", "objectname": "8c68a1f06fc59c655b7e3905b159d761e91c53c9",
"creator": "Foo Bar <foo@bar.com> 1565789218 +0300", "creator": "Foo Bar <foo@bar.com> 1565789218 +0300",