diff options
-rw-r--r-- | cmd/gitaly-git2go/conflicts.go | 8 | ||||
-rw-r--r-- | cmd/gitaly-git2go/conflicts_test.go | 15 | ||||
-rw-r--r-- | internal/git2go/conflicts.go | 2 | ||||
-rw-r--r-- | internal/git2go/conflicts_test.go | 4 |
4 files changed, 15 insertions, 14 deletions
diff --git a/cmd/gitaly-git2go/conflicts.go b/cmd/gitaly-git2go/conflicts.go index adce23d60..ba892067e 100644 --- a/cmd/gitaly-git2go/conflicts.go +++ b/cmd/gitaly-git2go/conflicts.go @@ -32,7 +32,7 @@ func conflictEntryFromIndex(entry *git.IndexEntry) git2go.ConflictEntry { } } -func conflictContent(repo *git.Repository, conflict git.IndexConflict) (string, error) { +func conflictContent(repo *git.Repository, conflict git.IndexConflict) ([]byte, error) { var ancestor, our, their git.MergeFileInput for entry, input := range map[*git.IndexEntry]*git.MergeFileInput{ @@ -46,7 +46,7 @@ func conflictContent(repo *git.Repository, conflict git.IndexConflict) (string, blob, err := repo.LookupBlob(entry.Id) if err != nil { - return "", fmt.Errorf("could not get conflicting blob: %w", err) + return nil, fmt.Errorf("could not get conflicting blob: %w", err) } input.Path = entry.Path @@ -56,10 +56,10 @@ func conflictContent(repo *git.Repository, conflict git.IndexConflict) (string, merge, err := git.MergeFile(ancestor, our, their, nil) if err != nil { - return "", fmt.Errorf("could not compute conflicts: %w", err) + return nil, fmt.Errorf("could not compute conflicts: %w", err) } - return string(merge.Contents), nil + return merge.Contents, nil } // Run performs a merge and prints resulting conflicts to stdout. diff --git a/cmd/gitaly-git2go/conflicts_test.go b/cmd/gitaly-git2go/conflicts_test.go index 36d49bddc..4cef16c12 100644 --- a/cmd/gitaly-git2go/conflicts_test.go +++ b/cmd/gitaly-git2go/conflicts_test.go @@ -48,7 +48,7 @@ func TestConflicts(t *testing.T) { Ancestor: git2go.ConflictEntry{Path: "file", Mode: 0100644}, Our: git2go.ConflictEntry{Path: "file", Mode: 0100644}, Their: git2go.ConflictEntry{Path: "file", Mode: 0100644}, - Content: "<<<<<<< file\nb\n=======\nc\n>>>>>>> file\n", + Content: []byte("<<<<<<< file\nb\n=======\nc\n>>>>>>> file\n"), }, }, }, @@ -71,7 +71,7 @@ func TestConflicts(t *testing.T) { Ancestor: git2go.ConflictEntry{Path: "file-2", Mode: 0100644}, Our: git2go.ConflictEntry{Path: "file-2", Mode: 0100644}, Their: git2go.ConflictEntry{Path: "file-2", Mode: 0100644}, - Content: "<<<<<<< file-2\nb\n=======\nc\n>>>>>>> file-2\n", + Content: []byte("<<<<<<< file-2\nb\n=======\nc\n>>>>>>> file-2\n"), }, }, }, @@ -94,13 +94,13 @@ func TestConflicts(t *testing.T) { Ancestor: git2go.ConflictEntry{Path: "file-1", Mode: 0100644}, Our: git2go.ConflictEntry{Path: "file-1", Mode: 0100644}, Their: git2go.ConflictEntry{Path: "file-1", Mode: 0100644}, - Content: "<<<<<<< file-1\nb\n=======\nc\n>>>>>>> file-1\n", + Content: []byte("<<<<<<< file-1\nb\n=======\nc\n>>>>>>> file-1\n"), }, { Ancestor: git2go.ConflictEntry{Path: "file-2", Mode: 0100644}, Our: git2go.ConflictEntry{Path: "file-2", Mode: 0100644}, Their: git2go.ConflictEntry{Path: "file-2", Mode: 0100644}, - Content: "<<<<<<< file-2\nb\n=======\nc\n>>>>>>> file-2\n", + Content: []byte("<<<<<<< file-2\nb\n=======\nc\n>>>>>>> file-2\n"), }, }, }, @@ -120,7 +120,7 @@ func TestConflicts(t *testing.T) { Ancestor: git2go.ConflictEntry{Path: "file", Mode: 0100644}, Our: git2go.ConflictEntry{Path: "file", Mode: 0100644}, Their: git2go.ConflictEntry{}, - Content: "<<<<<<< file\nchanged\n=======\n>>>>>>> \n", + Content: []byte("<<<<<<< file\nchanged\n=======\n>>>>>>> \n"), }, }, }, @@ -143,18 +143,19 @@ func TestConflicts(t *testing.T) { Ancestor: git2go.ConflictEntry{Path: "file", Mode: 0100644}, Our: git2go.ConflictEntry{}, Their: git2go.ConflictEntry{}, + Content: []byte{}, }, { Ancestor: git2go.ConflictEntry{}, Our: git2go.ConflictEntry{Path: "renamed-1", Mode: 0100644}, Their: git2go.ConflictEntry{}, - Content: "a\nb\nc\nd\ne\nf\ng\n", + Content: []byte("a\nb\nc\nd\ne\nf\ng\n"), }, { Ancestor: git2go.ConflictEntry{}, Our: git2go.ConflictEntry{}, Their: git2go.ConflictEntry{Path: "renamed-2", Mode: 0100644}, - Content: "a\nb\nc\nd\ne\nf\ng\n", + Content: []byte("a\nb\nc\nd\ne\nf\ng\n"), }, }, }, diff --git a/internal/git2go/conflicts.go b/internal/git2go/conflicts.go index 1b2d2658b..79f732be5 100644 --- a/internal/git2go/conflicts.go +++ b/internal/git2go/conflicts.go @@ -36,7 +36,7 @@ type Conflict struct { // Their is the conflict entry of theirs. Their ConflictEntry `json:"their"` // Content contains the conflicting merge results. - Content string `json:"content"` + Content []byte `json:"content"` } // ConflictsResult contains all conflicts resulting from a merge. diff --git a/internal/git2go/conflicts_test.go b/internal/git2go/conflicts_test.go index fe1268445..4061598bf 100644 --- a/internal/git2go/conflicts_test.go +++ b/internal/git2go/conflicts_test.go @@ -89,7 +89,7 @@ func TestConflictsResult_Serialization(t *testing.T) { Ancestor: ConflictEntry{Path: "dir/ancestor", Mode: 0100644}, Our: ConflictEntry{Path: "dir/our", Mode: 0100644}, Their: ConflictEntry{Path: "dir/their", Mode: 0100644}, - Content: "content", + Content: []byte("content"), }, }, }), @@ -99,7 +99,7 @@ func TestConflictsResult_Serialization(t *testing.T) { Ancestor: ConflictEntry{Path: "dir/ancestor", Mode: 0100644}, Our: ConflictEntry{Path: "dir/our", Mode: 0100644}, Their: ConflictEntry{Path: "dir/their", Mode: 0100644}, - Content: "content", + Content: []byte("content"), }, }, }, |