aboutsummaryrefslogtreecommitdiffstats
path: root/modules/git
diff options
context:
space:
mode:
authorLunny Xiao <xiaolunwen@gmail.com>2024-01-16 15:13:07 +0800
committerGitHub <noreply@github.com>2024-01-16 08:13:07 +0100
commit930e38d010d59281550aeee5feac58e0b6085569 (patch)
treee3f3dd913f637429c6a7284bac004260f0623ed5 /modules/git
parent5374d29aa9644a979d8d6e8e100bb4e77641d74f (diff)
downloadgitea-930e38d010d59281550aeee5feac58e0b6085569.tar.gz
gitea-930e38d010d59281550aeee5feac58e0b6085569.zip
Use refname:strip-2 instead of refname:short when syncing tags (#28797)
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
Diffstat (limited to 'modules/git')
-rw-r--r--modules/git/foreachref/format_test.go4
-rw-r--r--modules/git/repo_tag.go6
-rw-r--r--modules/git/repo_tag_test.go18
3 files changed, 15 insertions, 13 deletions
diff --git a/modules/git/foreachref/format_test.go b/modules/git/foreachref/format_test.go
index 392a95a4e6..8ff239323c 100644
--- a/modules/git/foreachref/format_test.go
+++ b/modules/git/foreachref/format_test.go
@@ -49,9 +49,9 @@ func TestFormat_Flag(t *testing.T) {
{
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",
},
}
diff --git a/modules/git/repo_tag.go b/modules/git/repo_tag.go
index 698b9b41f3..af9a75b29c 100644
--- a/modules/git/repo_tag.go
+++ b/modules/git/repo_tag.go
@@ -112,7 +112,9 @@ func (repo *Repository) GetTagWithID(idStr, name string) (*Tag, error) {
// GetTagInfos returns all tag infos of the repository.
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()
defer stdoutReader.Close()
@@ -162,7 +164,7 @@ func (repo *Repository) GetTagInfos(page, pageSize int) ([]*Tag, int, error) {
func parseTagRef(objectFormat ObjectFormat, ref map[string]string) (tag *Tag, err error) {
tag = &Tag{
Type: ref["objecttype"],
- Name: ref["refname:short"],
+ Name: ref["refname:lstrip=2"],
}
tag.ID, err = NewIDFromString(ref["objectname"])
diff --git a/modules/git/repo_tag_test.go b/modules/git/repo_tag_test.go
index 6b9df1746f..da7b1455a8 100644
--- a/modules/git/repo_tag_test.go
+++ b/modules/git/repo_tag_test.go
@@ -208,8 +208,8 @@ func TestRepository_parseTagRef(t *testing.T) {
name: "lightweight tag",
givenRef: map[string]string{
- "objecttype": "commit",
- "refname:short": "v1.9.1",
+ "objecttype": "commit",
+ "refname:lstrip=2": "v1.9.1",
// object will be empty for lightweight tags
"object": "",
"objectname": "ab23e4b7f4cd0caafe0174c0e7ef6d651ba72889",
@@ -237,8 +237,8 @@ func TestRepository_parseTagRef(t *testing.T) {
name: "annotated tag",
givenRef: map[string]string{
- "objecttype": "tag",
- "refname:short": "v0.0.1",
+ "objecttype": "tag",
+ "refname:lstrip=2": "v0.0.1",
// object will refer to commit hash for annotated tag
"object": "3325fd8a973321fd59455492976c042dde3fd1ca",
"objectname": "8c68a1f06fc59c655b7e3905b159d761e91c53c9",
@@ -266,11 +266,11 @@ func TestRepository_parseTagRef(t *testing.T) {
name: "annotated tag with signature",
givenRef: map[string]string{
- "objecttype": "tag",
- "refname:short": "v0.0.1",
- "object": "3325fd8a973321fd59455492976c042dde3fd1ca",
- "objectname": "8c68a1f06fc59c655b7e3905b159d761e91c53c9",
- "creator": "Foo Bar <foo@bar.com> 1565789218 +0300",
+ "objecttype": "tag",
+ "refname:lstrip=2": "v0.0.1",
+ "object": "3325fd8a973321fd59455492976c042dde3fd1ca",
+ "objectname": "8c68a1f06fc59c655b7e3905b159d761e91c53c9",
+ "creator": "Foo Bar <foo@bar.com> 1565789218 +0300",
"contents": `Add changelog of v1.9.1 (#7859)
* add changelog of v1.9.1