gitea源码

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. // Copyright 2024 The Gitea Authors. All rights reserved.
  2. // SPDX-License-Identifier: MIT
  3. package git
  4. import (
  5. "path/filepath"
  6. "testing"
  7. "github.com/stretchr/testify/assert"
  8. )
  9. func TestSubTree_Issue29101(t *testing.T) {
  10. repo, err := OpenRepository(t.Context(), filepath.Join(testReposDir, "repo1_bare"))
  11. assert.NoError(t, err)
  12. defer repo.Close()
  13. commit, err := repo.GetCommit("ce064814f4a0d337b333e646ece456cd39fab612")
  14. assert.NoError(t, err)
  15. // old code could produce a different error if called multiple times
  16. for range 10 {
  17. _, err = commit.SubTree("file1.txt")
  18. assert.Error(t, err)
  19. assert.True(t, IsErrNotExist(err))
  20. }
  21. }
  22. func Test_GetTreePathLatestCommit(t *testing.T) {
  23. repo, err := OpenRepository(t.Context(), filepath.Join(testReposDir, "repo6_blame"))
  24. assert.NoError(t, err)
  25. defer repo.Close()
  26. commitID, err := repo.GetBranchCommitID("master")
  27. assert.NoError(t, err)
  28. assert.Equal(t, "544d8f7a3b15927cddf2299b4b562d6ebd71b6a7", commitID)
  29. commit, err := repo.GetTreePathLatestCommit("master", "blame.txt")
  30. assert.NoError(t, err)
  31. assert.NotNil(t, commit)
  32. assert.Equal(t, "45fb6cbc12f970b04eacd5cd4165edd11c8d7376", commit.ID.String())
  33. }