Skip to content
Prev Previous commit
Next Next commit
placate lint
Signed-off-by: Andrew Thornton <[email protected]>
  • Loading branch information
zeripath committed Dec 17, 2021
commit 507ede427474cdede80e7cac7a4320da4407580e
20 changes: 13 additions & 7 deletions services/pull/patch.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"fmt"
"io"
"os"
"path/filepath"
"strings"

"code.gitea.io/gitea/models"
Expand Down Expand Up @@ -164,19 +165,26 @@ func attemptMerge(ctx context.Context, file *unmergedFile, tmpBasePath string, g
return fmt.Errorf("unable to get root object: %s at path: %s for merging. Error: %w", file.stage1.sha, file.stage1.path, err)
}
root = strings.TrimSpace(root)
defer util.Remove(root)
defer func() {
_ = util.Remove(filepath.Join(tmpBasePath, root))
}()

base, err := git.NewCommandContext(ctx, "unpack-file", file.stage2.sha).RunInDir(tmpBasePath)
if err != nil {
return fmt.Errorf("unable to get base object: %s at path: %s for merging. Error: %w", file.stage2.sha, file.stage2.path, err)
}
base = strings.TrimSpace(base)
defer util.Remove(base)
base = strings.TrimSpace(filepath.Join(tmpBasePath, base))
defer func() {
_ = util.Remove(base)
}()
head, err := git.NewCommandContext(ctx, "unpack-file", file.stage3.sha).RunInDir(tmpBasePath)
if err != nil {
return fmt.Errorf("unable to get head object:%s at path: %s for merging. Error: %w", file.stage3.sha, file.stage3.path, err)
}
head = strings.TrimSpace(head)
defer util.Remove(head)
defer func() {
_ = util.Remove(filepath.Join(tmpBasePath, head))
}()

// now git merge-file annoyingly takes a different order to the merge-tree ...
_, conflictErr := git.NewCommandContext(ctx, "merge-file", base, root, head).RunInDir(tmpBasePath)
Expand All @@ -199,8 +207,6 @@ func attemptMerge(ctx context.Context, file *unmergedFile, tmpBasePath string, g
markConflict(file.stage2.path)
} else if file.stage3 != nil {
markConflict(file.stage2.path)
} else {
// This shouldn't happen!
}
}
return nil
Expand Down Expand Up @@ -273,7 +279,7 @@ func checkConflicts(pr *models.PullRequest, gitRepo *git.Repository, tmpBasePath
return false, nil
}

// OK read-tree has failed so we need to try a different thing - this might actually suceed where the above fails due to whitespace handling.
// OK read-tree has failed so we need to try a different thing - this might actually succeed where the above fails due to whitespace handling.

// 1. Create a plain patch from head to base
tmpPatchFile, err := os.CreateTemp("", "patch")
Expand Down
2 changes: 1 addition & 1 deletion services/pull/patch_unmerged.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ func unmergedFiles(ctx context.Context, tmpBasePath string, unmerged chan *unmer
// stages are always emitted 1,2,3 but sometimes 1, 2 or 3 are dropped
switch line.stage {
case 0:
// Should not happen as this represents succesfully merged file - we will tolerate and ignore though
// Should not happen as this represents successfully merged file - we will tolerate and ignore though
case 1:
if next.stage1 != nil {
// We need to handle the unstaged file stage1,stage2,stage3
Expand Down