Skip to content

Commit 637125c

Browse files
committed
Fix GetCommitFileStatus on merge commit
Add new test repo repo6_merge
1 parent 116f8e1 commit 637125c

25 files changed

+50
-1
lines changed

modules/git/commit.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -521,7 +521,7 @@ func GetCommitFileStatus(ctx context.Context, repoPath, commitID string) (*Commi
521521
}()
522522

523523
stderr := new(bytes.Buffer)
524-
err := NewCommand(ctx, "log", "--name-status", "-c", "--pretty=format:", "--parents", "--no-renames", "-z", "-1").AddDynamicArguments(commitID).Run(&RunOpts{
524+
err := NewCommand(ctx, "log", "--name-status", "-m", "--pretty=format:", "--first-parent", "--no-renames", "-z", "-1").AddDynamicArguments(commitID).Run(&RunOpts{
525525
Dir: repoPath,
526526
Stdout: w,
527527
Stderr: stderr,

modules/git/commit_test.go

+23
Original file line numberDiff line numberDiff line change
@@ -255,3 +255,26 @@ func TestParseCommitFileStatus(t *testing.T) {
255255
assert.Equal(t, kase.modified, fileStatus.Modified)
256256
}
257257
}
258+
259+
func TestGetCommitFileStatusMerges(t *testing.T) {
260+
bareRepo1Path := filepath.Join(testReposDir, "repo6_merge")
261+
262+
commitFileStatus, err := GetCommitFileStatus(DefaultContext, bareRepo1Path, "022f4ce6214973e018f02bf363bf8a2e3691f699")
263+
assert.NoError(t, err)
264+
265+
expected := CommitFileStatus{
266+
[]string{
267+
"add_file.txt",
268+
},
269+
[]string{
270+
"to_remove.txt",
271+
},
272+
[]string{
273+
"to_modify.txt",
274+
},
275+
}
276+
277+
assert.Equal(t, commitFileStatus.Added, expected.Added)
278+
assert.Equal(t, commitFileStatus.Removed, expected.Removed)
279+
assert.Equal(t, commitFileStatus.Modified, expected.Modified)
280+
}
+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
ref: refs/heads/main
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
[core]
2+
repositoryformatversion = 0
3+
filemode = false
4+
bare = true
5+
ignorecase = true
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Unnamed repository; edit this file 'description' to name the repository.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# git ls-files --others --exclude-from=.git/info/exclude
2+
# Lines that start with '#' are comments.
3+
# For a project mostly in C, the following would be a good set of
4+
# exclude patterns (uncomment them if you want to use them):
5+
# *.[oa]
6+
# *~
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
x��M
2+
1 �a�=E��$��LAī�'���i��R���g�~_��u1��N��@mZ)g�2�D�j��*_�f��s �4��a�m�np>�����>!��#���1�;p]�x��uyIw�N4�

modules/git/tests/repos/repo6_merge/objects/38/ec3e0cdc88bde01014bda4a5dd9fc835f41439

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
x��M
2+
�0�a�9����M2 �U�� ��=���yv/��� ��0:@��$��UѬ�.�[�>� �l��I�s�x ��8'T��R�ĤS,��$x. ֚�=n[��נ��u�s!+9���BGv�f�m���u���r����>�
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
x��M
2+
1 @a�=E���?i�*m��Ǒ�xO���=x�.�l��O��R�Z80��\[�*�%�b
3+
�&q��� �I��Ț�灝
4+
7��ԋF쨜�w�c�u���zx?����0�
5+
�1 :�m���6L�S���>&
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
022f4ce6214973e018f02bf363bf8a2e3691f699
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
ae4b035e7c4afbc000576cee3f713ea0c2f1e1e2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
d1792641396ff7630d35fbb0b74b86b0c71bca77
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
38ec3e0cdc88bde01014bda4a5dd9fc835f41439

0 commit comments

Comments
 (0)