mirror of
https://github.com/jesseduffield/lazygit.git
synced 2025-07-01 00:54:58 +02:00
Add more demos (#2874)
This commit is contained in:
22
README.md
22
README.md
@ -107,6 +107,28 @@ You can filter a view with `/`. Here we filter down our branches view and then h
|
|||||||
|
|
||||||

|

|
||||||
|
|
||||||
|
### Invoke a custom command
|
||||||
|
|
||||||
|
Lazygit has a very flexible [custom command system](docs/Custom_Command_Keybindings.md). In this example a custom command is defined which emulates the built-in branch checkout action.
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
### Worktrees
|
||||||
|
|
||||||
|
You can create worktrees to have multiple branches going at once without the need for stashing or creating WIP commits when switching between them. Press `w` in the branches view to create a worktree from the selected branch and switch to it.
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
### 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).
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
## Tutorials
|
## Tutorials
|
||||||
|
|
||||||
[<img src="https://i.imgur.com/sVEktDn.png">](https://youtu.be/CPLdltN7wgE)
|
[<img src="https://i.imgur.com/sVEktDn.png">](https://youtu.be/CPLdltN7wgE)
|
||||||
|
@ -60,6 +60,12 @@ func (self *MenuDriver) LineCount(matcher *IntMatcher) *MenuDriver {
|
|||||||
return self
|
return self
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (self *MenuDriver) Wait(milliseconds int) *MenuDriver {
|
||||||
|
self.getViewDriver().Wait(milliseconds)
|
||||||
|
|
||||||
|
return self
|
||||||
|
}
|
||||||
|
|
||||||
func (self *MenuDriver) checkNecessaryChecksCompleted() {
|
func (self *MenuDriver) checkNecessaryChecksCompleted() {
|
||||||
if !self.hasCheckedTitle {
|
if !self.hasCheckedTitle {
|
||||||
self.t.Fail("You must check the title of a menu popup by calling Title() before calling Confirm()/Cancel().")
|
self.t.Fail("You must check the title of a menu popup by calling Title() before calling Confirm()/Cancel().")
|
||||||
|
78
pkg/integration/tests/demo/custom_command.go
Normal file
78
pkg/integration/tests/demo/custom_command.go
Normal file
@ -0,0 +1,78 @@
|
|||||||
|
package demo
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/jesseduffield/lazygit/pkg/config"
|
||||||
|
. "github.com/jesseduffield/lazygit/pkg/integration/components"
|
||||||
|
)
|
||||||
|
|
||||||
|
var customCommandContent = `
|
||||||
|
customCommands:
|
||||||
|
- key: 'a'
|
||||||
|
command: 'git checkout {{.Form.Branch}}'
|
||||||
|
context: 'localBranches'
|
||||||
|
prompts:
|
||||||
|
- type: 'input'
|
||||||
|
title: 'Enter a branch name to checkout:'
|
||||||
|
key: 'Branch'
|
||||||
|
suggestions:
|
||||||
|
preset: 'branches'
|
||||||
|
`
|
||||||
|
|
||||||
|
var CustomCommand = NewIntegrationTest(NewIntegrationTestArgs{
|
||||||
|
Description: "Invoke a custom command",
|
||||||
|
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"
|
||||||
|
|
||||||
|
cfg.UserConfig.CustomCommands = []config.CustomCommand{
|
||||||
|
{
|
||||||
|
Key: "a",
|
||||||
|
Context: "localBranches",
|
||||||
|
Command: `git checkout {{.Form.Branch}}`,
|
||||||
|
Prompts: []config.CustomCommandPrompt{
|
||||||
|
{
|
||||||
|
Key: "Branch",
|
||||||
|
Type: "input",
|
||||||
|
Title: "Enter a branch name to checkout",
|
||||||
|
Suggestions: config.CustomCommandSuggestions{
|
||||||
|
Preset: "branches",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
},
|
||||||
|
SetupRepo: func(shell *Shell) {
|
||||||
|
shell.CreateNCommitsWithRandomMessages(30)
|
||||||
|
shell.NewBranch("feature/user-authentication")
|
||||||
|
shell.NewBranch("feature/payment-processing")
|
||||||
|
shell.NewBranch("feature/search-functionality")
|
||||||
|
shell.NewBranch("feature/mobile-responsive")
|
||||||
|
shell.EmptyCommit("Make mobile response")
|
||||||
|
shell.NewBranch("bugfix/fix-login-issue")
|
||||||
|
shell.HardReset("HEAD~1")
|
||||||
|
shell.NewBranch("bugfix/fix-crash-bug")
|
||||||
|
shell.CreateFile("custom_commands_example.yml", customCommandContent)
|
||||||
|
},
|
||||||
|
Run: func(t *TestDriver, keys config.KeybindingConfig) {
|
||||||
|
t.SetCaptionPrefix("Invoke a custom command")
|
||||||
|
t.Wait(1500)
|
||||||
|
|
||||||
|
t.Views().Branches().
|
||||||
|
Focus().
|
||||||
|
Wait(500).
|
||||||
|
Press("a").
|
||||||
|
Tap(func() {
|
||||||
|
t.Wait(500)
|
||||||
|
|
||||||
|
t.ExpectPopup().Prompt().
|
||||||
|
Title(Equals("Enter a branch name to checkout")).
|
||||||
|
Type("mobile").
|
||||||
|
ConfirmFirstSuggestion()
|
||||||
|
})
|
||||||
|
},
|
||||||
|
})
|
76
pkg/integration/tests/demo/custom_patch.go
Normal file
76
pkg/integration/tests/demo/custom_patch.go
Normal file
@ -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()
|
||||||
|
})
|
||||||
|
},
|
||||||
|
})
|
71
pkg/integration/tests/demo/undo.go
Normal file
71
pkg/integration/tests/demo/undo.go
Normal file
@ -0,0 +1,71 @@
|
|||||||
|
package demo
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/jesseduffield/lazygit/pkg/config"
|
||||||
|
. "github.com/jesseduffield/lazygit/pkg/integration/components"
|
||||||
|
)
|
||||||
|
|
||||||
|
// TODO: fix confirmation view wrapping issue: https://github.com/jesseduffield/lazygit/issues/2872
|
||||||
|
|
||||||
|
var Undo = NewIntegrationTest(NewIntegrationTestArgs{
|
||||||
|
Description: "Undo",
|
||||||
|
ExtraCmdArgs: []string{},
|
||||||
|
Skip: false,
|
||||||
|
IsDemo: true,
|
||||||
|
SetupConfig: func(config *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.
|
||||||
|
config.UserConfig.Gui.NerdFontsVersion = "2"
|
||||||
|
},
|
||||||
|
SetupRepo: func(shell *Shell) {
|
||||||
|
shell.CreateNCommitsWithRandomMessages(30)
|
||||||
|
},
|
||||||
|
Run: func(t *TestDriver, keys config.KeybindingConfig) {
|
||||||
|
t.SetCaptionPrefix("Undo commands")
|
||||||
|
t.Wait(1000)
|
||||||
|
|
||||||
|
confirmCommitDrop := func() {
|
||||||
|
t.ExpectPopup().Confirmation().
|
||||||
|
Title(Equals("Delete commit")).
|
||||||
|
Content(Equals("Are you sure you want to delete this commit?")).
|
||||||
|
Wait(500).
|
||||||
|
Confirm()
|
||||||
|
}
|
||||||
|
|
||||||
|
confirmUndo := func() {
|
||||||
|
t.ExpectPopup().Confirmation().
|
||||||
|
Title(Equals("Undo")).
|
||||||
|
Content(MatchesRegexp(`Are you sure you want to hard reset to '.*'\? An auto-stash will be performed if necessary\.`)).
|
||||||
|
Wait(500).
|
||||||
|
Confirm()
|
||||||
|
}
|
||||||
|
|
||||||
|
confirmRedo := func() {
|
||||||
|
t.ExpectPopup().Confirmation().
|
||||||
|
Title(Equals("Redo")).
|
||||||
|
Content(MatchesRegexp(`Are you sure you want to hard reset to '.*'\? An auto-stash will be performed if necessary\.`)).
|
||||||
|
Wait(500).
|
||||||
|
Confirm()
|
||||||
|
}
|
||||||
|
|
||||||
|
t.Views().Commits().Focus().
|
||||||
|
SetCaptionPrefix("Drop two commits").
|
||||||
|
Wait(1000).
|
||||||
|
Press(keys.Universal.Remove).
|
||||||
|
Tap(confirmCommitDrop).
|
||||||
|
Press(keys.Universal.Remove).
|
||||||
|
Tap(confirmCommitDrop).
|
||||||
|
SetCaptionPrefix("Undo the drops").
|
||||||
|
Wait(1000).
|
||||||
|
Press(keys.Universal.Undo).
|
||||||
|
Tap(confirmUndo).
|
||||||
|
Press(keys.Universal.Undo).
|
||||||
|
Tap(confirmUndo).
|
||||||
|
SetCaptionPrefix("Redo the drops").
|
||||||
|
Wait(1000).
|
||||||
|
Press(keys.Universal.Redo).
|
||||||
|
Tap(confirmRedo).
|
||||||
|
Press(keys.Universal.Redo).
|
||||||
|
Tap(confirmRedo)
|
||||||
|
},
|
||||||
|
})
|
59
pkg/integration/tests/demo/worktree_create_from_branches.go
Normal file
59
pkg/integration/tests/demo/worktree_create_from_branches.go
Normal file
@ -0,0 +1,59 @@
|
|||||||
|
package demo
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/jesseduffield/lazygit/pkg/config"
|
||||||
|
. "github.com/jesseduffield/lazygit/pkg/integration/components"
|
||||||
|
)
|
||||||
|
|
||||||
|
var WorktreeCreateFromBranches = NewIntegrationTest(NewIntegrationTestArgs{
|
||||||
|
Description: "Create a worktree from the branches view",
|
||||||
|
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.EmptyCommit("Fix local session storage")
|
||||||
|
shell.CreateFile("src/authentication.go", "package main")
|
||||||
|
shell.CreateFile("src/shims.go", "package main")
|
||||||
|
shell.CreateFile("src/session.go", "package main")
|
||||||
|
shell.EmptyCommit("Stop using shims")
|
||||||
|
shell.UpdateFile("src/authentication.go", "package authentication")
|
||||||
|
shell.UpdateFileAndAdd("src/shims.go", "// removing for now")
|
||||||
|
shell.UpdateFile("src/session.go", "package session")
|
||||||
|
},
|
||||||
|
Run: func(t *TestDriver, keys config.KeybindingConfig) {
|
||||||
|
t.SetCaptionPrefix("Create a worktree from a branch")
|
||||||
|
t.Wait(1000)
|
||||||
|
|
||||||
|
t.Views().Branches().
|
||||||
|
Focus().
|
||||||
|
NavigateToLine(Contains("master")).
|
||||||
|
Wait(500).
|
||||||
|
Press(keys.Worktrees.ViewWorktreeOptions).
|
||||||
|
Tap(func() {
|
||||||
|
t.Wait(500)
|
||||||
|
|
||||||
|
t.ExpectPopup().Menu().
|
||||||
|
Title(Equals("Worktree")).
|
||||||
|
Select(Contains("Create worktree from master").DoesNotContain("detached")).
|
||||||
|
Confirm()
|
||||||
|
|
||||||
|
t.ExpectPopup().Prompt().
|
||||||
|
Title(Equals("New worktree path")).
|
||||||
|
Type("../hotfix").
|
||||||
|
Confirm()
|
||||||
|
|
||||||
|
t.ExpectPopup().Prompt().
|
||||||
|
Title(Contains("New branch name")).
|
||||||
|
Type("hotfix/db-on-fire").
|
||||||
|
Confirm()
|
||||||
|
})
|
||||||
|
},
|
||||||
|
})
|
@ -93,10 +93,14 @@ var tests = []*components.IntegrationTest{
|
|||||||
demo.Bisect,
|
demo.Bisect,
|
||||||
demo.CherryPick,
|
demo.CherryPick,
|
||||||
demo.CommitAndPush,
|
demo.CommitAndPush,
|
||||||
|
demo.CustomCommand,
|
||||||
|
demo.CustomPatch,
|
||||||
demo.Filter,
|
demo.Filter,
|
||||||
demo.InteractiveRebase,
|
demo.InteractiveRebase,
|
||||||
demo.NukeWorkingTree,
|
demo.NukeWorkingTree,
|
||||||
demo.StageLines,
|
demo.StageLines,
|
||||||
|
demo.Undo,
|
||||||
|
demo.WorktreeCreateFromBranches,
|
||||||
diff.Diff,
|
diff.Diff,
|
||||||
diff.DiffAndApplyPatch,
|
diff.DiffAndApplyPatch,
|
||||||
diff.DiffCommits,
|
diff.DiffCommits,
|
||||||
|
Reference in New Issue
Block a user