Skip to content

Commit

Permalink
Add compare-commits demo (jesseduffield#2929)
Browse files Browse the repository at this point in the history
  • Loading branch information
jesseduffield authored Aug 12, 2023
2 parents 26989ce + 1c6cfaf commit d99e983
Show file tree
Hide file tree
Showing 18 changed files with 99 additions and 25 deletions.
20 changes: 20 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,20 @@ If you're a mere mortal like me and you're tired of hearing how powerful git is
## Table of contents

- [Features](#features)
- [Stage individual lines](#stage-individual-lines)
- [Interactive Rebase](#interactive-rebase)
- [Cherry-pick](#cherry-pick)
- [Bisect](#bisect)
- [Nuke the working tree](#nuke-the-working-tree)
- [Amend an old commit](#amend-an-old-commit)
- [Filter](#filter)
- [Invoke a custom command](#invoke-a-custom-command)
- [Worktrees](#worktrees)
- [Rebase magic (custom patches)](#rebase-magic-custom-patches)
- [Rebase from marked base commit](#rebase-from-marked-base-commit)
- [Undo](#undo)
- [Commit graph](#commit-graph)
- [Compare two commits](#compare-two-commits)
- [Tutorials](#tutorials)
- [Installation](#installation)
- [Binary releases](#binary-releases)
Expand Down Expand Up @@ -150,6 +164,12 @@ When viewing the commit graph in an enlarged window (use `+` and `_` to cycle wi

![commit_graph](../assets/demo/commit_graph-compressed.gif)

### Compare two commits

If you press `shift+w` on a commit (or branch/ref) a menu will open that allows you to mark that commit so that any other commit you select will be diffed against it. Once you've selected the second commit, you'll see the diff in the main view and if you press `<enter>` you'll see the files of the diff. You can press `shift+w` to view the diff menu again to see options like reversing the diff direction or exiting diff mode. You can also exit diff mode by pressing `<escape>`.

![diff_commits](../assets/demo/diff_commits-compressed.gif)

## Tutorials

[<img src="https://i.imgur.com/sVEktDn.png">](https://youtu.be/CPLdltN7wgE)
Expand Down
2 changes: 1 addition & 1 deletion pkg/integration/tests/demo/amend_old_commit.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ var AmendOldCommit = NewIntegrationTest(NewIntegrationTestArgs{
Skip: false,
IsDemo: true,
SetupConfig: func(config *config.AppConfig) {
config.UserConfig.Gui.NerdFontsVersion = "3"
setDefaultDemoConfig(config)
config.UserConfig.Gui.ShowFileTree = false
},
SetupRepo: func(shell *Shell) {
Expand Down
2 changes: 1 addition & 1 deletion pkg/integration/tests/demo/bisect.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ var Bisect = NewIntegrationTest(NewIntegrationTestArgs{
Skip: false,
IsDemo: true,
SetupConfig: func(config *config.AppConfig) {
config.UserConfig.Gui.NerdFontsVersion = "3"
setDefaultDemoConfig(config)
},
SetupRepo: func(shell *Shell) {
shell.CreateFile("my-file.txt", "myfile content")
Expand Down
2 changes: 1 addition & 1 deletion pkg/integration/tests/demo/cherry_pick.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ var CherryPick = NewIntegrationTest(NewIntegrationTestArgs{
Skip: false,
IsDemo: true,
SetupConfig: func(config *config.AppConfig) {
config.UserConfig.Gui.NerdFontsVersion = "3"
setDefaultDemoConfig(config)
},
SetupRepo: func(shell *Shell) {
shell.CreateNCommitsWithRandomMessages(50)
Expand Down
2 changes: 1 addition & 1 deletion pkg/integration/tests/demo/commit_and_push.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ var CommitAndPush = NewIntegrationTest(NewIntegrationTestArgs{
Skip: false,
IsDemo: true,
SetupConfig: func(config *config.AppConfig) {
config.UserConfig.Gui.NerdFontsVersion = "3"
setDefaultDemoConfig(config)
},
SetupRepo: func(shell *Shell) {
shell.CreateFile("my-file.txt", "myfile content")
Expand Down
10 changes: 2 additions & 8 deletions pkg/integration/tests/demo/commit_graph.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,8 @@ var CommitGraph = NewIntegrationTest(NewIntegrationTestArgs{
Skip: false,
IsDemo: true,
SetupConfig: func(config *config.AppConfig) {
config.UserConfig.Gui.NerdFontsVersion = "3"
config.UserConfig.Gui.AuthorColors = map[string]string{
"Fredrica Greenhill": "#fb5aa3",
"Oscar Reuenthal": "#86c82f",
"Paul Oberstein": "#ffd500",
"Siegfried Kircheis": "#fe7e11",
"Yang Wen-li": "#8e3ccb",
}
setDefaultDemoConfig(config)
setGeneratedAuthorColours(config)
},
SetupRepo: func(shell *Shell) {
shell.CreateRepoHistory()
Expand Down
4 changes: 1 addition & 3 deletions pkg/integration/tests/demo/custom_command.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,7 @@ var CustomCommand = NewIntegrationTest(NewIntegrationTestArgs{
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"
setDefaultDemoConfig(cfg)

cfg.UserConfig.CustomCommands = []config.CustomCommand{
{
Expand Down
2 changes: 1 addition & 1 deletion pkg/integration/tests/demo/custom_patch.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ var CustomPatch = NewIntegrationTest(NewIntegrationTestArgs{
Skip: false,
IsDemo: true,
SetupConfig: func(cfg *config.AppConfig) {
cfg.UserConfig.Gui.NerdFontsVersion = "3"
setDefaultDemoConfig(cfg)
},
SetupRepo: func(shell *Shell) {
shell.CreateNCommitsWithRandomMessages(30)
Expand Down
44 changes: 44 additions & 0 deletions pkg/integration/tests/demo/diff_commits.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package demo

import (
"github.com/jesseduffield/lazygit/pkg/config"
. "github.com/jesseduffield/lazygit/pkg/integration/components"
)

var DiffCommits = NewIntegrationTest(NewIntegrationTestArgs{
Description: "Diff two commits",
ExtraCmdArgs: []string{},
Skip: false,
IsDemo: true,
SetupConfig: func(config *config.AppConfig) {
setDefaultDemoConfig(config)

config.UserConfig.Gui.ShowFileTree = false
config.UserConfig.Gui.ShowCommandLog = false
},
SetupRepo: func(shell *Shell) {
shell.CreateNCommitsWithRandomMessages(50)
},
Run: func(t *TestDriver, keys config.KeybindingConfig) {
t.SetCaptionPrefix("Compare two commits")
t.Wait(1000)

t.Views().Commits().
Focus().
NavigateToLine(Contains("Replace deprecated lifecycle methods in React components")).
Wait(1000).
Press(keys.Universal.DiffingMenu).
Tap(func() {
t.ExpectPopup().Menu().
Title(Equals("Diffing")).
TopLines(
MatchesRegexp(`Diff .*`),
).
Wait(500).
Confirm()
}).
NavigateToLine(Contains("Move constants to a separate config file")).
Wait(1000).
PressEnter()
},
})
2 changes: 1 addition & 1 deletion pkg/integration/tests/demo/filter.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ var Filter = NewIntegrationTest(NewIntegrationTestArgs{
Skip: false,
IsDemo: true,
SetupConfig: func(config *config.AppConfig) {
config.UserConfig.Gui.NerdFontsVersion = "3"
setDefaultDemoConfig(config)
},
SetupRepo: func(shell *Shell) {
shell.CreateNCommitsWithRandomMessages(30)
Expand Down
2 changes: 1 addition & 1 deletion pkg/integration/tests/demo/interactive_rebase.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ var InteractiveRebase = NewIntegrationTest(NewIntegrationTestArgs{
Skip: false,
IsDemo: true,
SetupConfig: func(config *config.AppConfig) {
config.UserConfig.Gui.NerdFontsVersion = "3"
setDefaultDemoConfig(config)
},
SetupRepo: func(shell *Shell) {
shell.CreateFile("my-file.txt", "myfile content")
Expand Down
2 changes: 1 addition & 1 deletion pkg/integration/tests/demo/nuke_working_tree.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ var NukeWorkingTree = NewIntegrationTest(NewIntegrationTestArgs{
Skip: false,
IsDemo: true,
SetupConfig: func(config *config.AppConfig) {
config.UserConfig.Gui.NerdFontsVersion = "3"
setDefaultDemoConfig(config)
config.UserConfig.Gui.AnimateExplosion = true
},
SetupRepo: func(shell *Shell) {
Expand Down
2 changes: 1 addition & 1 deletion pkg/integration/tests/demo/rebase_onto.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ var RebaseOnto = NewIntegrationTest(NewIntegrationTestArgs{
Skip: false,
IsDemo: true,
SetupConfig: func(config *config.AppConfig) {
config.UserConfig.Gui.NerdFontsVersion = "3"
setDefaultDemoConfig(config)
},
SetupRepo: func(shell *Shell) {
shell.CreateNCommitsWithRandomMessages(60)
Expand Down
19 changes: 19 additions & 0 deletions pkg/integration/tests/demo/shared.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package demo

import "github.com/jesseduffield/lazygit/pkg/config"

// Gives us nicer colours when we generate a git repo history with `shell.CreateRepoHistory()`
func setGeneratedAuthorColours(config *config.AppConfig) {
config.UserConfig.Gui.AuthorColors = map[string]string{
"Fredrica Greenhill": "#fb5aa3",
"Oscar Reuenthal": "#86c82f",
"Paul Oberstein": "#ffd500",
"Siegfried Kircheis": "#fe7e11",
"Yang Wen-li": "#8e3ccb",
}
}

func setDefaultDemoConfig(config *config.AppConfig) {
// demos look much nicers with icons shown
config.UserConfig.Gui.NerdFontsVersion = "3"
}
2 changes: 1 addition & 1 deletion pkg/integration/tests/demo/stage_lines.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ var StageLines = NewIntegrationTest(NewIntegrationTestArgs{
Skip: false,
IsDemo: true,
SetupConfig: func(config *config.AppConfig) {
config.UserConfig.Gui.NerdFontsVersion = "3"
setDefaultDemoConfig(config)
config.UserConfig.Gui.ShowFileTree = false
config.UserConfig.Gui.ShowCommandLog = false
},
Expand Down
2 changes: 1 addition & 1 deletion pkg/integration/tests/demo/undo.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ var Undo = NewIntegrationTest(NewIntegrationTestArgs{
Skip: false,
IsDemo: true,
SetupConfig: func(config *config.AppConfig) {
config.UserConfig.Gui.NerdFontsVersion = "3"
setDefaultDemoConfig(config)
},
SetupRepo: func(shell *Shell) {
shell.CreateNCommitsWithRandomMessages(30)
Expand Down
4 changes: 1 addition & 3 deletions pkg/integration/tests/demo/worktree_create_from_branches.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,7 @@ var WorktreeCreateFromBranches = NewIntegrationTest(NewIntegrationTestArgs{
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"
setDefaultDemoConfig(cfg)
},
SetupRepo: func(shell *Shell) {
shell.CreateNCommitsWithRandomMessages(30)
Expand Down
1 change: 1 addition & 0 deletions pkg/integration/tests/test_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ var tests = []*components.IntegrationTest{
demo.CommitGraph,
demo.CustomCommand,
demo.CustomPatch,
demo.DiffCommits,
demo.Filter,
demo.InteractiveRebase,
demo.NukeWorkingTree,
Expand Down

0 comments on commit d99e983

Please sign in to comment.