Skip to content

Commit

Permalink
Fix GetCommitFileStatus on merge commit
Browse files Browse the repository at this point in the history
Add new test repo repo6_merge
  • Loading branch information
tdesveaux committed May 14, 2023
1 parent 116f8e1 commit 637125c
Show file tree
Hide file tree
Showing 25 changed files with 50 additions and 1 deletion.
2 changes: 1 addition & 1 deletion modules/git/commit.go
Original file line number Diff line number Diff line change
Expand Up @@ -521,7 +521,7 @@ func GetCommitFileStatus(ctx context.Context, repoPath, commitID string) (*Commi
}()

stderr := new(bytes.Buffer)
err := NewCommand(ctx, "log", "--name-status", "-c", "--pretty=format:", "--parents", "--no-renames", "-z", "-1").AddDynamicArguments(commitID).Run(&RunOpts{
err := NewCommand(ctx, "log", "--name-status", "-m", "--pretty=format:", "--first-parent", "--no-renames", "-z", "-1").AddDynamicArguments(commitID).Run(&RunOpts{
Dir: repoPath,
Stdout: w,
Stderr: stderr,
Expand Down
23 changes: 23 additions & 0 deletions modules/git/commit_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -255,3 +255,26 @@ func TestParseCommitFileStatus(t *testing.T) {
assert.Equal(t, kase.modified, fileStatus.Modified)
}
}

func TestGetCommitFileStatusMerges(t *testing.T) {
bareRepo1Path := filepath.Join(testReposDir, "repo6_merge")

commitFileStatus, err := GetCommitFileStatus(DefaultContext, bareRepo1Path, "022f4ce6214973e018f02bf363bf8a2e3691f699")
assert.NoError(t, err)

expected := CommitFileStatus{
[]string{
"add_file.txt",
},
[]string{
"to_remove.txt",
},
[]string{
"to_modify.txt",
},
}

assert.Equal(t, commitFileStatus.Added, expected.Added)
assert.Equal(t, commitFileStatus.Removed, expected.Removed)
assert.Equal(t, commitFileStatus.Modified, expected.Modified)
}
1 change: 1 addition & 0 deletions modules/git/tests/repos/repo6_merge/HEAD
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ref: refs/heads/main
5 changes: 5 additions & 0 deletions modules/git/tests/repos/repo6_merge/config
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[core]
repositoryformatversion = 0
filemode = false
bare = true
ignorecase = true
1 change: 1 addition & 0 deletions modules/git/tests/repos/repo6_merge/description
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Unnamed repository; edit this file 'description' to name the repository.
6 changes: 6 additions & 0 deletions modules/git/tests/repos/repo6_merge/info/exclude
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# git ls-files --others --exclude-from=.git/info/exclude
# Lines that start with '#' are comments.
# For a project mostly in C, the following would be a good set of
# exclude patterns (uncomment them if you want to use them):
# *.[oa]
# *~
Binary file not shown.
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
x��M
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�
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
x��M
�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����>�
Expand Down
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
x��M
1 @a�=E���?i�*m��Ǒ�xO���=x�.�l��O��R�Z80��\[�*�%�b
�&q��� �I��Ț�灝
7��ԋF쨜�w�c�u���zx?����0�
�1 :�m���6L�S���>&
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
1 change: 1 addition & 0 deletions modules/git/tests/repos/repo6_merge/refs/heads/main
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
022f4ce6214973e018f02bf363bf8a2e3691f699
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ae4b035e7c4afbc000576cee3f713ea0c2f1e1e2
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
d1792641396ff7630d35fbb0b74b86b0c71bca77
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
38ec3e0cdc88bde01014bda4a5dd9fc835f41439

0 comments on commit 637125c

Please sign in to comment.