-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix custom patch operations on added files
Several custom patch commands on parts of an added file would fail with the confusing error message "error: new file XXX depends on old contents". These were dropping the custom patch from the original commit, moving the patch to a new commit, moving it to a later commit, or moving it to the index. We fix this by converting the patch header from an added file to a diff against an empty file. We do this not just for the purpose of applying the patch, but also for rendering it and copying it to the clip board. I'm not sure it matters much in these cases, but it does feel more correct for a filtered patch to be presented this way.
- Loading branch information
1 parent
3f336d2
commit 65d4614
Showing
10 changed files
with
297 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
96 changes: 96 additions & 0 deletions
96
pkg/integration/tests/patch_building/move_to_index_from_added_file_with_conflict.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
package patch_building | ||
|
||
import ( | ||
"github.com/jesseduffield/lazygit/pkg/config" | ||
. "github.com/jesseduffield/lazygit/pkg/integration/components" | ||
) | ||
|
||
var MoveToIndexFromAddedFileWithConflict = NewIntegrationTest(NewIntegrationTestArgs{ | ||
Description: "Move a patch from a file that was added in a commit to the index, causing a conflict", | ||
ExtraCmdArgs: []string{}, | ||
Skip: false, | ||
SetupConfig: func(config *config.AppConfig) {}, | ||
SetupRepo: func(shell *Shell) { | ||
shell.EmptyCommit("first commit") | ||
|
||
shell.CreateFileAndAdd("file1", "1st line\n2nd line\n3rd line\n") | ||
shell.Commit("commit to move from") | ||
shell.UpdateFileAndAdd("file1", "1st line\n2nd line changed\n3rd line\n") | ||
shell.Commit("conflicting change") | ||
}, | ||
Run: func(t *TestDriver, keys config.KeybindingConfig) { | ||
t.Views().Commits(). | ||
Focus(). | ||
Lines( | ||
Contains("conflicting change").IsSelected(), | ||
Contains("commit to move from"), | ||
Contains("first commit"), | ||
). | ||
SelectNextItem(). | ||
PressEnter() | ||
|
||
t.Views().CommitFiles(). | ||
IsFocused(). | ||
Lines( | ||
Contains("file1").IsSelected(), | ||
). | ||
PressEnter() | ||
|
||
t.Views().PatchBuilding(). | ||
IsFocused(). | ||
SelectNextItem(). | ||
PressPrimaryAction() | ||
|
||
t.Views().Information().Content(Contains("Building patch")) | ||
|
||
t.Common().SelectPatchOption(Contains("Move patch out into index")) | ||
|
||
t.Common().AcknowledgeConflicts() | ||
|
||
t.Views().Files(). | ||
IsFocused(). | ||
Lines( | ||
Contains("UU").Contains("file1"), | ||
). | ||
PressEnter() | ||
|
||
t.Views().MergeConflicts(). | ||
IsFocused(). | ||
ContainsLines( | ||
Contains("1st line"), | ||
Contains("<<<<<<< HEAD"), | ||
Contains("======="), | ||
Contains("2nd line changed"), | ||
Contains(">>>>>>>"), | ||
Contains("3rd line"), | ||
). | ||
SelectNextItem(). | ||
PressPrimaryAction() | ||
|
||
t.Common().ContinueOnConflictsResolved() | ||
|
||
t.ExpectPopup().Alert(). | ||
Title(Equals("Error")). | ||
Content(Contains("Applied patch to 'file1' with conflicts")). | ||
Confirm() | ||
|
||
t.Views().Files(). | ||
IsFocused(). | ||
Lines( | ||
Contains("UU").Contains("file1"), | ||
). | ||
PressEnter() | ||
|
||
t.Views().MergeConflicts(). | ||
TopLines( | ||
Contains("1st line"), | ||
Contains("<<<<<<< ours"), | ||
Contains("2nd line changed"), | ||
Contains("======="), | ||
Contains("2nd line"), | ||
Contains(">>>>>>> theirs"), | ||
Contains("3rd line"), | ||
). | ||
IsFocused() | ||
}, | ||
}) |
88 changes: 88 additions & 0 deletions
88
pkg/integration/tests/patch_building/move_to_new_commit_from_added_file.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
package patch_building | ||
|
||
import ( | ||
"github.com/jesseduffield/lazygit/pkg/config" | ||
. "github.com/jesseduffield/lazygit/pkg/integration/components" | ||
) | ||
|
||
var MoveToNewCommitFromAddedFile = NewIntegrationTest(NewIntegrationTestArgs{ | ||
Description: "Move a patch from a file that was added in a commit to a new commit", | ||
ExtraCmdArgs: []string{}, | ||
Skip: false, | ||
SetupConfig: func(config *config.AppConfig) {}, | ||
SetupRepo: func(shell *Shell) { | ||
shell.EmptyCommit("first commit") | ||
|
||
shell.CreateFileAndAdd("file1", "1st line\n2nd line\n3rd line\n") | ||
shell.Commit("commit to move from") | ||
}, | ||
Run: func(t *TestDriver, keys config.KeybindingConfig) { | ||
t.Views().Commits(). | ||
Focus(). | ||
Lines( | ||
Contains("commit to move from").IsSelected(), | ||
Contains("first commit"), | ||
). | ||
PressEnter() | ||
|
||
t.Views().CommitFiles(). | ||
IsFocused(). | ||
Lines( | ||
Contains("file1").IsSelected(), | ||
). | ||
PressEnter() | ||
|
||
t.Views().PatchBuilding(). | ||
IsFocused(). | ||
SelectNextItem(). | ||
PressPrimaryAction() | ||
|
||
t.Views().Information().Content(Contains("Building patch")) | ||
|
||
t.Common().SelectPatchOption(Contains("Move patch into new commit")) | ||
|
||
t.ExpectPopup().CommitMessagePanel(). | ||
InitialText(Equals("")). | ||
Type("new commit").Confirm() | ||
|
||
t.Views().Commits(). | ||
IsFocused(). | ||
Lines( | ||
Contains("new commit").IsSelected(), | ||
Contains("commit to move from"), | ||
Contains("first commit"), | ||
). | ||
PressEnter() | ||
|
||
t.Views().CommitFiles(). | ||
IsFocused(). | ||
Lines( | ||
Contains("M file1").IsSelected(), | ||
). | ||
Tap(func() { | ||
t.Views().Main().ContainsLines( | ||
Equals(" 1st line"), | ||
Equals("+2nd line"), | ||
Equals(" 3rd line"), | ||
) | ||
}). | ||
PressEscape() | ||
|
||
t.Views().Commits(). | ||
IsFocused(). | ||
NavigateToLine(Contains("commit to move from")). | ||
PressEnter() | ||
|
||
t.Views().CommitFiles(). | ||
IsFocused(). | ||
Lines( | ||
Contains("A file1").IsSelected(), | ||
). | ||
Tap(func() { | ||
t.Views().Main().ContainsLines( | ||
Equals("+1st line"), | ||
Equals("+3rd line"), | ||
) | ||
}) | ||
}, | ||
}) |
Oops, something went wrong.