Move updateref and removeref to gitrepo and remove unnecessary open repository (#35511)

Extracted from #35077
`UpdateRef` and `RemoveRef` will call git commands even for gogit
version.
This commit is contained in:
Lunny Xiao
2025-09-19 08:04:18 -07:00
committed by GitHub
parent 9a0ec53ee3
commit 198f37e33c
11 changed files with 46 additions and 47 deletions

View File

@@ -9,6 +9,8 @@ import (
"path/filepath"
"testing"
"code.gitea.io/gitea/modules/git/gitcmd"
"github.com/stretchr/testify/assert"
)
@@ -99,7 +101,9 @@ func TestReadWritePullHead(t *testing.T) {
// Write a fake sha1 with only 40 zeros
newCommit := "feaf4ba6bc635fec442f46ddd4512416ec43c2c2"
err = repo.SetReference(PullPrefix+"1/head", newCommit)
_, _, err = gitcmd.NewCommand("update-ref").
AddDynamicArguments(PullPrefix+"1/head", newCommit).
RunStdString(t.Context(), &gitcmd.RunOpts{Dir: repo.Path})
if err != nil {
assert.NoError(t, err)
return
@@ -116,7 +120,9 @@ func TestReadWritePullHead(t *testing.T) {
assert.Equal(t, headContents, newCommit)
// Remove file after the test
err = repo.RemoveReference(PullPrefix + "1/head")
_, _, err = gitcmd.NewCommand("update-ref", "--no-deref", "-d").
AddDynamicArguments(PullPrefix+"1/head").
RunStdString(t.Context(), &gitcmd.RunOpts{Dir: repo.Path})
assert.NoError(t, err)
}