diff options
author | zeripath <art27@cantab.net> | 2021-12-23 13:44:00 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-12-23 21:44:00 +0800 |
commit | ffc08c1914fbe6a5a5ebe9c8571b790ac6024d71 (patch) | |
tree | 78e95e6dbf82d25e0fa9c534cab61fb8d266cc9f /modules/git/repo_compare_test.go | |
parent | e0cf3d86c44fde99b49f12c7a1386cbf433a0207 (diff) | |
download | gitea-ffc08c1914fbe6a5a5ebe9c8571b790ac6024d71.tar.gz gitea-ffc08c1914fbe6a5a5ebe9c8571b790ac6024d71.zip |
Do not read or write git reference files directly (#18079)
Git will and can pack references into packfiles and therefore if you write/read the
files directly you will get false results. Instead you should use update-ref and
show-ref. To that end I have created three new functions in git/repo_commit.go that
will do this correctly.
Related #17191
Signed-off-by: Andrew Thornton <art27@cantab.net>
Diffstat (limited to 'modules/git/repo_compare_test.go')
-rw-r--r-- | modules/git/repo_compare_test.go | 15 |
1 files changed, 7 insertions, 8 deletions
diff --git a/modules/git/repo_compare_test.go b/modules/git/repo_compare_test.go index 4790170d10..301e085aae 100644 --- a/modules/git/repo_compare_test.go +++ b/modules/git/repo_compare_test.go @@ -8,7 +8,6 @@ import ( "bytes" "io" "path/filepath" - "strings" "testing" "code.gitea.io/gitea/modules/util" @@ -63,18 +62,18 @@ func TestReadWritePullHead(t *testing.T) { assert.NoError(t, err) defer repo.Close() // Try to open non-existing Pull - _, err = repo.ReadPullHead(0) + _, err = repo.GetRefCommitID(PullPrefix + "0/head") assert.Error(t, err) // Write a fake sha1 with only 40 zeros - newCommit := strings.Repeat("0", 40) - err = repo.WritePullHead(1, newCommit) + newCommit := "feaf4ba6bc635fec442f46ddd4512416ec43c2c2" + err = repo.SetReference(PullPrefix+"1/head", newCommit) assert.NoError(t, err) - headFile := filepath.Join(repo.Path, "refs/pull/1/head") // Remove file after the test - defer util.Remove(headFile) - assert.FileExists(t, headFile) + defer func() { + _ = repo.RemoveReference(PullPrefix + "1/head") + }() // Read the file created - headContents, err := repo.ReadPullHead(1) + headContents, err := repo.GetRefCommitID(PullPrefix + "1/head") assert.NoError(t, err) assert.Len(t, string(headContents), 40) assert.True(t, string(headContents) == newCommit) |