-
-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Improve editing a commit #4090
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Improve editing a commit #4090
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
ea03ae5
Cleanup: remove a no-op Focus() call
stefanhaller 4624d49
Add test for editing the last commit of a branch in a stack
stefanhaller 0766b14
Add test to auto-amend a commit after pressing `e` on it
stefanhaller 016d465
Add test for editing several commits right after a merge commit
stefanhaller 17bb397
Filter out merge commits when generating todo changes in InteractiveR…
stefanhaller d849868
Extract helper methods
stefanhaller debfe1a
Improve editing a commit
stefanhaller File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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
55 changes: 55 additions & 0 deletions
55
pkg/integration/tests/interactive_rebase/edit_and_auto_amend.go
This file contains hidden or 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,55 @@ | ||
| package interactive_rebase | ||
|
|
||
| import ( | ||
| "github.com/jesseduffield/lazygit/pkg/config" | ||
| . "github.com/jesseduffield/lazygit/pkg/integration/components" | ||
| ) | ||
|
|
||
| var EditAndAutoAmend = NewIntegrationTest(NewIntegrationTestArgs{ | ||
| Description: "Edit a commit, make a change and stage it, then continue the rebase to auto-amend the commit", | ||
| ExtraCmdArgs: []string{}, | ||
| Skip: false, | ||
| SetupConfig: func(config *config.AppConfig) {}, | ||
| SetupRepo: func(shell *Shell) { | ||
| shell. | ||
| CreateNCommits(3) | ||
| }, | ||
| Run: func(t *TestDriver, keys config.KeybindingConfig) { | ||
| t.Views().Commits(). | ||
| Focus(). | ||
| Lines( | ||
| Contains("commit 03"), | ||
| Contains("commit 02"), | ||
| Contains("commit 01"), | ||
| ). | ||
| NavigateToLine(Contains("commit 02")). | ||
| Press(keys.Universal.Edit). | ||
| Lines( | ||
| Contains("commit 03"), | ||
| MatchesRegexp("YOU ARE HERE.*commit 02").IsSelected(), | ||
| Contains("commit 01"), | ||
| ) | ||
|
|
||
| t.Shell().CreateFile("fixup-file", "fixup content") | ||
| t.Views().Files(). | ||
| Focus(). | ||
| Press(keys.Files.RefreshFiles). | ||
| Lines( | ||
| Contains("??").Contains("fixup-file").IsSelected(), | ||
| ). | ||
| PressPrimaryAction() | ||
|
|
||
| t.Common().ContinueRebase() | ||
|
|
||
| t.Views().Commits(). | ||
| Focus(). | ||
| Lines( | ||
| Contains("commit 03"), | ||
| Contains("commit 02").IsSelected(), | ||
| Contains("commit 01"), | ||
| ) | ||
|
|
||
| t.Views().Main(). | ||
| Content(Contains("fixup content")) | ||
| }, | ||
| }) |
74 changes: 74 additions & 0 deletions
74
pkg/integration/tests/interactive_rebase/edit_last_commit_of_stacked_branch.go
This file contains hidden or 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,74 @@ | ||
| package interactive_rebase | ||
|
|
||
| import ( | ||
| "github.com/jesseduffield/lazygit/pkg/config" | ||
| . "github.com/jesseduffield/lazygit/pkg/integration/components" | ||
| ) | ||
|
|
||
| var EditLastCommitOfStackedBranch = NewIntegrationTest(NewIntegrationTestArgs{ | ||
| Description: "Edit and amend the last commit of a branch in a stack of branches, and ensure that it doesn't break the stack", | ||
| ExtraCmdArgs: []string{}, | ||
| Skip: false, | ||
| GitVersion: AtLeast("2.38.0"), | ||
| SetupConfig: func(config *config.AppConfig) { | ||
| config.GetUserConfig().Git.MainBranches = []string{"master"} | ||
| config.GetAppState().GitLogShowGraph = "never" | ||
| }, | ||
| SetupRepo: func(shell *Shell) { | ||
| shell. | ||
| CreateNCommits(1). | ||
| NewBranch("branch1"). | ||
| CreateNCommitsStartingAt(2, 2). | ||
| NewBranch("branch2"). | ||
| CreateNCommitsStartingAt(2, 4) | ||
|
|
||
| shell.SetConfig("rebase.updateRefs", "true") | ||
| }, | ||
| Run: func(t *TestDriver, keys config.KeybindingConfig) { | ||
| t.Views().Commits(). | ||
| Focus(). | ||
| Lines( | ||
| Contains("CI commit 05").IsSelected(), | ||
| Contains("CI commit 04"), | ||
| Contains("CI * commit 03"), | ||
| Contains("CI commit 02"), | ||
| Contains("CI commit 01"), | ||
| ). | ||
| NavigateToLine(Contains("commit 03")). | ||
| Press(keys.Universal.Edit). | ||
| Lines( | ||
| Contains("pick").Contains("CI commit 05"), | ||
| Contains("pick").Contains("CI commit 04"), | ||
| Contains("update-ref").Contains("branch1"), | ||
| Contains("<-- YOU ARE HERE --- * commit 03").IsSelected(), | ||
| Contains("CI commit 02"), | ||
| Contains("CI commit 01"), | ||
| ) | ||
|
|
||
| t.Shell().CreateFile("fixup-file", "fixup content") | ||
| t.Views().Files(). | ||
| Focus(). | ||
| Press(keys.Files.RefreshFiles). | ||
| Lines( | ||
| Contains("??").Contains("fixup-file").IsSelected(), | ||
| ). | ||
| PressPrimaryAction(). | ||
| Press(keys.Files.AmendLastCommit) | ||
| t.ExpectPopup().Confirmation(). | ||
| Title(Equals("Amend last commit")). | ||
| Content(Contains("Are you sure you want to amend last commit?")). | ||
| Confirm() | ||
|
|
||
| t.Common().ContinueRebase() | ||
|
|
||
| t.Views().Commits(). | ||
| Focus(). | ||
| Lines( | ||
| Contains("CI commit 05"), | ||
| Contains("CI commit 04"), | ||
| Contains("CI * commit 03"), | ||
| Contains("CI commit 02"), | ||
| Contains("CI commit 01"), | ||
| ) | ||
| }, | ||
| }) |
43 changes: 43 additions & 0 deletions
43
pkg/integration/tests/interactive_rebase/edit_range_select_down_to_merge_outside_rebase.go
This file contains hidden or 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,43 @@ | ||
| package interactive_rebase | ||
|
|
||
| import ( | ||
| "github.com/jesseduffield/lazygit/pkg/config" | ||
| . "github.com/jesseduffield/lazygit/pkg/integration/components" | ||
| "github.com/jesseduffield/lazygit/pkg/integration/tests/shared" | ||
| ) | ||
|
|
||
| var EditRangeSelectDownToMergeOutsideRebase = NewIntegrationTest(NewIntegrationTestArgs{ | ||
| Description: "Select a range of commits (the last one being a merge commit) to edit outside of a rebase", | ||
| ExtraCmdArgs: []string{}, | ||
| Skip: false, | ||
| GitVersion: AtLeast("2.22.0"), // first version that supports the --rebase-merges option | ||
| SetupConfig: func(config *config.AppConfig) {}, | ||
| SetupRepo: func(shell *Shell) { | ||
| shared.CreateMergeCommit(shell) | ||
| shell.CreateNCommits(2) | ||
| }, | ||
| Run: func(t *TestDriver, keys config.KeybindingConfig) { | ||
| t.Views().Commits(). | ||
| Focus(). | ||
| TopLines( | ||
| Contains("CI ◯ commit 02").IsSelected(), | ||
| Contains("CI ◯ commit 01"), | ||
| Contains("Merge branch 'second-change-branch' into first-change-branch"), | ||
| ). | ||
| Press(keys.Universal.RangeSelectDown). | ||
| Press(keys.Universal.RangeSelectDown). | ||
| Press(keys.Universal.Edit). | ||
| Lines( | ||
| Contains("edit CI commit 02").IsSelected(), | ||
| Contains("edit CI commit 01").IsSelected(), | ||
| Contains(" CI ⏣─╮ <-- YOU ARE HERE --- Merge branch 'second-change-branch' into first-change-branch").IsSelected(), | ||
| Contains(" CI │ ◯ * second-change-branch unrelated change"), | ||
| Contains(" CI │ ◯ second change"), | ||
| Contains(" CI ◯ │ first change"), | ||
| Contains(" CI ◯─╯ * original"), | ||
| Contains(" CI ◯ three"), | ||
| Contains(" CI ◯ two"), | ||
| Contains(" CI ◯ one"), | ||
| ) | ||
| }, | ||
| }) |
This file contains hidden or 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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think if we can't find the original start/end, we should exit the range select mode (assuming it's actually possible to end up in that situation).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think it's possible to end up in that situation, I was just being extra defensive. But I wouldn't feel good about adding logic that I don't know how to write a test for.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No worries