mirror of
https://github.com/jesseduffield/lazygit.git
synced 2026-11-21 04:46:29 +03:00
Users can copy commits from one repo to another with "git format-patch" and "git am", for example with custom commands. If "git am" stopped with a conflict, lazygit showed this as a rebase, because git am uses the rebase-apply directory too. The rebase options in the m menu didn't work either; git refuses to run "git rebase --continue" during an am. Recognize an am by the rebase-apply/applying file, and call this state "applying patches". The m menu then offers "git am --continue", "--abort" and "--skip". If "git am --continue" finds nothing to commit, it says "No changes - did you forget to use 'git add'?". Unlike for a rebase, don't skip the patch in that case. Without --3way, git am leaves the files alone if a patch doesn't apply, and skipping would lose the patch. If a lock error stops "git am --continue" or "--skip" after it has moved on to the next patch, don't run it again; this could skip that patch. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
38 lines
1.2 KiB
Go
38 lines
1.2 KiB
Go
package am
|
|
|
|
import (
|
|
. "github.com/jesseduffield/lazygit/pkg/integration/components"
|
|
)
|
|
|
|
// setUpConflictingAm creates two commits on a branch, turns them into patches,
|
|
// and applies these to master with "git am". The first patch conflicts. If
|
|
// secondPatchConflicts is true, the second one conflicts with the resolution of
|
|
// the first one too. With threeWay, "git am" gets the --3way option, so that
|
|
// the conflicts show up in the files; otherwise it leaves the files alone.
|
|
func setUpConflictingAm(shell *Shell, secondPatchConflicts bool, threeWay bool) {
|
|
shell.
|
|
CreateFileAndAdd("file", "original\n").
|
|
Commit("base").
|
|
NewBranch("source").
|
|
UpdateFileAndAdd("file", "source\n").
|
|
Commit("change file")
|
|
|
|
if secondPatchConflicts {
|
|
shell.UpdateFileAndAdd("file", "source again\n").Commit("change file again")
|
|
} else {
|
|
shell.CreateFileAndAdd("file2", "two\n").Commit("add file2")
|
|
}
|
|
|
|
shell.
|
|
RunShellCommand("git format-patch --stdout master..source > ../patches.mbox").
|
|
Checkout("master").
|
|
UpdateFileAndAdd("file", "master\n").
|
|
Commit("conflicting change")
|
|
|
|
amArgs := []string{"git", "am"}
|
|
if threeWay {
|
|
amArgs = append(amArgs, "--3way")
|
|
}
|
|
shell.RunCommandExpectError(append(amArgs, "../patches.mbox"))
|
|
}
|