diff options
author | Stan Hu <stanhu@gmail.com> | 2023-01-20 18:34:58 +0300 |
---|---|---|
committer | Stan Hu <stanhu@gmail.com> | 2023-01-20 18:35:19 +0300 |
commit | 98b0027d4791b4e9d3c87f36e80436dc65245de9 (patch) | |
tree | 6e83f1cd6735c49782f53d83ffefe5cdf4bd4dc9 | |
parent | 169dc65a41588477a983c3b17e638bd26d25bc9e (diff) |
conflicts: Fix nil pointer access when conflict has no ancestor
If the conflict resolver is unable to parse the diff with conflict
markers and the conflict had no ancestor, previously the git2go
process would crash due to a nil pointer access. Since the ancestor
may not exist for this file, just use the `our` path instead.
Relates to https://gitlab.com/gitlab-org/gitaly/-/issues/4720
Changelog: fixed
-rw-r--r-- | internal/gitaly/service/conflicts/resolve_conflicts_test.go | 29 |
1 files changed, 25 insertions, 4 deletions
diff --git a/internal/gitaly/service/conflicts/resolve_conflicts_test.go b/internal/gitaly/service/conflicts/resolve_conflicts_test.go index f4a89660c..5efe7f6b9 100644 --- a/internal/gitaly/service/conflicts/resolve_conflicts_test.go +++ b/internal/gitaly/service/conflicts/resolve_conflicts_test.go @@ -283,6 +283,7 @@ func TestResolveConflictsLineEndings(t *testing.T) { theirContent string resolutions []map[string]interface{} expectedContents string + expectedError string }{ { desc: "only newline", @@ -336,6 +337,21 @@ func TestResolveConflictsLineEndings(t *testing.T) { }, expectedContents: "A\nB", }, + { + desc: "conflict with existing conflict markers", + ourContent: "<<<<<<< HEAD\nA\nB\n=======", + theirContent: "X\nB", + resolutions: []map[string]interface{}{ + { + "old_path": "file.txt", + "new_path": "file.txt", + "sections": map[string]string{ + "5436437fa01a7d3e41d46741da54b451446774ca_1_1": "head", + }, + }, + }, + expectedError: `resolve: parse conflict for "file.txt": unexpected conflict delimiter`, + }, } { t.Run(tc.desc, func(t *testing.T) { ourOID := gittest.WriteBlob(t, cfg, repoPath, []byte(tc.ourContent)) @@ -381,11 +397,16 @@ func TestResolveConflictsLineEndings(t *testing.T) { })) response, err := stream.CloseAndRecv() - require.NoError(t, err) - require.Empty(t, response.GetResolutionError()) - oursFile := gittest.Exec(t, cfg, "-C", repoPath, "cat-file", "-p", "refs/heads/ours:file.txt") - require.Equal(t, []byte(tc.expectedContents), oursFile) + if tc.expectedError == "" { + require.NoError(t, err) + require.Empty(t, response.GetResolutionError()) + + oursFile := gittest.Exec(t, cfg, "-C", repoPath, "cat-file", "-p", "refs/heads/ours:file.txt") + require.Equal(t, []byte(tc.expectedContents), oursFile) + } else { + require.Equal(t, status.Error(codes.Internal, tc.expectedError), err) + } }) } } |