diff options
author | Jesse Duffield <jessedduffield@gmail.com> | 2023-08-04 09:15:07 +1000 |
---|---|---|
committer | Jesse Duffield <jessedduffield@gmail.com> | 2023-08-04 09:15:07 +1000 |
commit | f6af4c29d4bd4826b570af6ac72bb8bc50c6f16c (patch) | |
tree | 2c1f9e424d7875305e077cd3d21cf2afa549545d | |
parent | 996ad5bf263a253a527897accf53e3d198c0345c (diff) |
Add custom patch demo
-rw-r--r-- | README.md | 8 | ||||
-rw-r--r-- | pkg/integration/components/menu_driver.go | 6 | ||||
-rw-r--r-- | pkg/integration/tests/demo/custom_patch.go | 76 | ||||
-rw-r--r-- | pkg/integration/tests/test_list.go | 1 |
4 files changed, 91 insertions, 0 deletions
@@ -121,6 +121,14 @@ You can create worktrees to have multiple branches going at once without the nee ### Rebase magic (custom patches) +You can build a custom patch from an old commit and then remove the patch from the commit, split out a new commit, apply the patch in reverse to the index, and more. + +In this example we have a redundant comment that we want to remove from an old commit. We hit `<enter>` on the commit to view its files, then `<enter>` on a file to focus the patch, then `<space>` to add the comment line to our custom patch, and then `ctrl+p` to view the custom patch options; selecting to remove the patch from the current commit. + +Learn more in the [Rebase magic Youtube tutorial](https://youtu.be/4XaToVut_hs). + +![custom_patch](../assets/demo/custom_patch-compressed.gif) + ## Tutorials [<img src="https://i.imgur.com/sVEktDn.png">](https://youtu.be/CPLdltN7wgE) diff --git a/pkg/integration/components/menu_driver.go b/pkg/integration/components/menu_driver.go index 4e0b0f6da..34d081dfa 100644 --- a/pkg/integration/components/menu_driver.go +++ b/pkg/integration/components/menu_driver.go @@ -60,6 +60,12 @@ func (self *MenuDriver) LineCount(matcher *IntMatcher) *MenuDriver { return self } +func (self *MenuDriver) Wait(milliseconds int) *MenuDriver { + self.getViewDriver().Wait(milliseconds) + + return self +} + func (self *MenuDriver) checkNecessaryChecksCompleted() { if !self.hasCheckedTitle { self.t.Fail("You must check the title of a menu popup by calling Title() before calling Confirm()/Cancel().") diff --git a/pkg/integration/tests/demo/custom_patch.go b/pkg/integration/tests/demo/custom_patch.go new file mode 100644 index 000000000..b110054a5 --- /dev/null +++ b/pkg/integration/tests/demo/custom_patch.go @@ -0,0 +1,76 @@ +package demo + +import ( + "github.com/jesseduffield/lazygit/pkg/config" + . "github.com/jesseduffield/lazygit/pkg/integration/components" +) + +var usersFileContent = `package main + +import "fmt" + +func main() { + // TODO: verify that this actuall works + fmt.Println("hello world") +} +` + +var CustomPatch = NewIntegrationTest(NewIntegrationTestArgs{ + Description: "Remove a line from an old commit", + ExtraCmdArgs: []string{}, + Skip: false, + IsDemo: true, + SetupConfig: func(cfg *config.AppConfig) { + // No idea why I had to use version 2: it should be using my own computer's + // font and the one iterm uses is version 3. + cfg.UserConfig.Gui.NerdFontsVersion = "2" + }, + SetupRepo: func(shell *Shell) { + shell.CreateNCommitsWithRandomMessages(30) + shell.NewBranch("feature/user-authentication") + shell.EmptyCommit("Add user authentication feature") + shell.CreateFileAndAdd("src/users.go", "package main\n") + shell.Commit("Fix local session storage") + shell.CreateFile("src/authentication.go", "package main") + shell.CreateFile("src/session.go", "package main") + shell.UpdateFileAndAdd("src/users.go", usersFileContent) + shell.EmptyCommit("Stop using shims") + shell.UpdateFileAndAdd("src/authentication.go", "package authentication") + shell.UpdateFileAndAdd("src/session.go", "package session") + shell.Commit("Enhance user authentication feature") + }, + Run: func(t *TestDriver, keys config.KeybindingConfig) { + t.SetCaptionPrefix("Remove a line from an old commit") + t.Wait(1000) + + t.Views().Commits(). + Focus(). + NavigateToLine(Contains("Stop using shims")). + Wait(1000). + PressEnter(). + Tap(func() { + t.Views().CommitFiles(). + IsFocused(). + NavigateToLine(Contains("users.go")). + Wait(1000). + PressEnter(). + Tap(func() { + t.Views().PatchBuilding(). + IsFocused(). + NavigateToLine(Contains("TODO")). + Wait(500). + PressPrimaryAction(). + PressEscape() + }). + Press(keys.Universal.CreatePatchOptionsMenu). + Tap(func() { + t.ExpectPopup().Menu(). + Title(Equals("Patch options")). + Select(Contains("Remove patch from original commit")). + Wait(500). + Confirm() + }). + PressEscape() + }) + }, +}) diff --git a/pkg/integration/tests/test_list.go b/pkg/integration/tests/test_list.go index c5e94c532..f71a3981e 100644 --- a/pkg/integration/tests/test_list.go +++ b/pkg/integration/tests/test_list.go @@ -94,6 +94,7 @@ var tests = []*components.IntegrationTest{ demo.CherryPick, demo.CommitAndPush, demo.CustomCommand, + demo.CustomPatch, demo.Filter, demo.InteractiveRebase, demo.NukeWorkingTree, |