forked from forgejo/forgejo
Backport #26290 by @Zettat123
Fixes #26270.
Co-Author: @wxiaoguang
Thanks @lunny for providing this solution
As
https://github.com/go-gitea/gitea/issues/26270#issuecomment-1661695151
said, at present we cannot get the names of changed files correctly when
the `OldCommitID` is `EmptySHA`. In this PR, the `GetCommitFilesChanged`
method is added and will be used to get the changed files by commit ID.
References:
- https://stackoverflow.com/a/424142
Co-authored-by: Zettat123 <zettat123@gmail.com>
Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
(cherry picked from commit a57568bad7
)
This commit is contained in:
parent
b97dbf7a9e
commit
db326835e6
3 changed files with 50 additions and 3 deletions
|
@ -119,3 +119,42 @@ func TestReadWritePullHead(t *testing.T) {
|
|||
err = repo.RemoveReference(PullPrefix + "1/head")
|
||||
assert.NoError(t, err)
|
||||
}
|
||||
|
||||
func TestGetCommitFilesChanged(t *testing.T) {
|
||||
bareRepo1Path := filepath.Join(testReposDir, "repo1_bare")
|
||||
repo, err := openRepositoryWithDefaultContext(bareRepo1Path)
|
||||
assert.NoError(t, err)
|
||||
defer repo.Close()
|
||||
|
||||
testCases := []struct {
|
||||
base, head string
|
||||
files []string
|
||||
}{
|
||||
{
|
||||
EmptySHA,
|
||||
"95bb4d39648ee7e325106df01a621c530863a653",
|
||||
[]string{"file1.txt"},
|
||||
},
|
||||
{
|
||||
EmptySHA,
|
||||
"8d92fc957a4d7cfd98bc375f0b7bb189a0d6c9f2",
|
||||
[]string{"file2.txt"},
|
||||
},
|
||||
{
|
||||
"95bb4d39648ee7e325106df01a621c530863a653",
|
||||
"8d92fc957a4d7cfd98bc375f0b7bb189a0d6c9f2",
|
||||
[]string{"file2.txt"},
|
||||
},
|
||||
{
|
||||
EmptyTreeSHA,
|
||||
"8d92fc957a4d7cfd98bc375f0b7bb189a0d6c9f2",
|
||||
[]string{"file1.txt", "file2.txt"},
|
||||
},
|
||||
}
|
||||
|
||||
for _, tc := range testCases {
|
||||
changedFiles, err := repo.GetFilesChangedBetween(tc.base, tc.head)
|
||||
assert.NoError(t, err)
|
||||
assert.ElementsMatch(t, tc.files, changedFiles)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue