mirror of
https://github.com/jesseduffield/lazygit.git
synced 2025-05-12 21:05:48 +02:00
add feature of display diff between specific commits #397
This commit is contained in:
parent
1a933eaa73
commit
c350cdba43
11 changed files with 131 additions and 24 deletions
|
@ -25,16 +25,15 @@
|
||||||
<kbd>A</kbd>: amend last commit
|
<kbd>A</kbd>: amend last commit
|
||||||
<kbd>C</kbd>: commit changes using git editor
|
<kbd>C</kbd>: commit changes using git editor
|
||||||
<kbd>space</kbd>: toggle staged
|
<kbd>space</kbd>: toggle staged
|
||||||
<kbd>d</kbd>: delete if untracked / checkout if tracked
|
<kbd>d</kbd>: view 'discard changes' options
|
||||||
<kbd>e</kbd>: edit file
|
<kbd>e</kbd>: edit file
|
||||||
<kbd>o</kbd>: open file
|
<kbd>o</kbd>: open file
|
||||||
<kbd>i</kbd>: add to .gitignore
|
<kbd>i</kbd>: add to .gitignore
|
||||||
<kbd>r</kbd>: refresh files
|
<kbd>r</kbd>: refresh files
|
||||||
<kbd>S</kbd>: stash files
|
<kbd>S</kbd>: stash files
|
||||||
<kbd>s</kbd>: soft reset to last commit
|
|
||||||
<kbd>a</kbd>: stage/unstage all
|
<kbd>a</kbd>: stage/unstage all
|
||||||
<kbd>t</kbd>: add patch
|
<kbd>t</kbd>: add patch
|
||||||
<kbd>D</kbd>: reset hard and remove untracked files
|
<kbd>D</kbd>: view reset options
|
||||||
<kbd>enter</kbd>: stage individual hunks/lines
|
<kbd>enter</kbd>: stage individual hunks/lines
|
||||||
<kbd>f</kbd>: fetch
|
<kbd>f</kbd>: fetch
|
||||||
</pre>
|
</pre>
|
||||||
|
@ -72,6 +71,7 @@
|
||||||
<kbd>C</kbd>: copy commit range (cherry-pick)
|
<kbd>C</kbd>: copy commit range (cherry-pick)
|
||||||
<kbd>v</kbd>: paste commits (cherry-pick)
|
<kbd>v</kbd>: paste commits (cherry-pick)
|
||||||
<kbd>enter</kbd>: view commit's files
|
<kbd>enter</kbd>: view commit's files
|
||||||
|
<kbd>space</kbd>: diff specific commits
|
||||||
</pre>
|
</pre>
|
||||||
|
|
||||||
## Stash
|
## Stash
|
||||||
|
@ -91,19 +91,6 @@
|
||||||
<kbd>o</kbd>: open file
|
<kbd>o</kbd>: open file
|
||||||
</pre>
|
</pre>
|
||||||
|
|
||||||
## Main (Merging)
|
|
||||||
|
|
||||||
<pre>
|
|
||||||
<kbd>esc</kbd>: return to files panel
|
|
||||||
<kbd>space</kbd>: pick hunk
|
|
||||||
<kbd>b</kbd>: pick both hunks
|
|
||||||
<kbd>◄</kbd>: select previous conflict
|
|
||||||
<kbd>►</kbd>: select next conflict
|
|
||||||
<kbd>▲</kbd>: select top hunk
|
|
||||||
<kbd>▼</kbd>: select bottom hunk
|
|
||||||
<kbd>z</kbd>: undo
|
|
||||||
</pre>
|
|
||||||
|
|
||||||
## Main (Normal)
|
## Main (Normal)
|
||||||
|
|
||||||
<pre>
|
<pre>
|
||||||
|
@ -122,3 +109,16 @@
|
||||||
<kbd>space</kbd>: stage line
|
<kbd>space</kbd>: stage line
|
||||||
<kbd>a</kbd>: stage hunk
|
<kbd>a</kbd>: stage hunk
|
||||||
</pre>
|
</pre>
|
||||||
|
|
||||||
|
## Main (Merging)
|
||||||
|
|
||||||
|
<pre>
|
||||||
|
<kbd>esc</kbd>: return to files panel
|
||||||
|
<kbd>space</kbd>: pick hunk
|
||||||
|
<kbd>b</kbd>: pick both hunks
|
||||||
|
<kbd>◄</kbd>: select previous conflict
|
||||||
|
<kbd>►</kbd>: select next conflict
|
||||||
|
<kbd>▲</kbd>: select top hunk
|
||||||
|
<kbd>▼</kbd>: select bottom hunk
|
||||||
|
<kbd>z</kbd>: undo
|
||||||
|
</pre>
|
||||||
|
|
|
@ -25,16 +25,15 @@
|
||||||
<kbd>A</kbd>: wijzig laatste commit
|
<kbd>A</kbd>: wijzig laatste commit
|
||||||
<kbd>C</kbd>: commit veranderingen met de git editor
|
<kbd>C</kbd>: commit veranderingen met de git editor
|
||||||
<kbd>space</kbd>: toggle staged
|
<kbd>space</kbd>: toggle staged
|
||||||
<kbd>d</kbd>: Verwijder als untracked / uitchecken wordt gevolgd (ga weg)
|
<kbd>d</kbd>: view 'discard changes' options
|
||||||
<kbd>e</kbd>: verander bestand
|
<kbd>e</kbd>: verander bestand
|
||||||
<kbd>o</kbd>: open bestand
|
<kbd>o</kbd>: open bestand
|
||||||
<kbd>i</kbd>: voeg toe aan .gitignore
|
<kbd>i</kbd>: voeg toe aan .gitignore
|
||||||
<kbd>r</kbd>: refresh bestanden
|
<kbd>r</kbd>: refresh bestanden
|
||||||
<kbd>S</kbd>: stash-bestanden
|
<kbd>S</kbd>: stash-bestanden
|
||||||
<kbd>s</kbd>: soft reset to last commit
|
|
||||||
<kbd>a</kbd>: toggle staged alle
|
<kbd>a</kbd>: toggle staged alle
|
||||||
<kbd>t</kbd>: bewerkingen toevoegen
|
<kbd>t</kbd>: bewerkingen toevoegen
|
||||||
<kbd>D</kbd>: harde reset and verwijderen ongevolgde bestanden
|
<kbd>D</kbd>: view reset options
|
||||||
<kbd>enter</kbd>: stage individuele hunks/lijnen
|
<kbd>enter</kbd>: stage individuele hunks/lijnen
|
||||||
<kbd>f</kbd>: fetch
|
<kbd>f</kbd>: fetch
|
||||||
</pre>
|
</pre>
|
||||||
|
@ -72,6 +71,7 @@
|
||||||
<kbd>C</kbd>: copy commit range (cherry-pick)
|
<kbd>C</kbd>: copy commit range (cherry-pick)
|
||||||
<kbd>v</kbd>: paste commits (cherry-pick)
|
<kbd>v</kbd>: paste commits (cherry-pick)
|
||||||
<kbd>enter</kbd>: view commit's files
|
<kbd>enter</kbd>: view commit's files
|
||||||
|
<kbd>space</kbd>: diff specific commits
|
||||||
</pre>
|
</pre>
|
||||||
|
|
||||||
## Stash
|
## Stash
|
||||||
|
|
|
@ -25,16 +25,15 @@
|
||||||
<kbd>A</kbd>: zmień ostatnie zatwierdzenie
|
<kbd>A</kbd>: zmień ostatnie zatwierdzenie
|
||||||
<kbd>C</kbd>: commituj zmiany używając edytora z gita
|
<kbd>C</kbd>: commituj zmiany używając edytora z gita
|
||||||
<kbd>space</kbd>: przełącz zatwierdzenie
|
<kbd>space</kbd>: przełącz zatwierdzenie
|
||||||
<kbd>d</kbd>: usuń jeśli nie śledzony / przełącz jeśli śledzony
|
<kbd>d</kbd>: view 'discard changes' options
|
||||||
<kbd>e</kbd>: edytuj plik
|
<kbd>e</kbd>: edytuj plik
|
||||||
<kbd>o</kbd>: otwórz plik
|
<kbd>o</kbd>: otwórz plik
|
||||||
<kbd>i</kbd>: dodaj do .gitignore
|
<kbd>i</kbd>: dodaj do .gitignore
|
||||||
<kbd>r</kbd>: odśwież pliki
|
<kbd>r</kbd>: odśwież pliki
|
||||||
<kbd>S</kbd>: przechowaj pliki
|
<kbd>S</kbd>: przechowaj pliki
|
||||||
<kbd>s</kbd>: soft reset to last commit
|
|
||||||
<kbd>a</kbd>: przełącz wszystkie zatwierdzenia
|
<kbd>a</kbd>: przełącz wszystkie zatwierdzenia
|
||||||
<kbd>t</kbd>: dodaj łatkę
|
<kbd>t</kbd>: dodaj łatkę
|
||||||
<kbd>D</kbd>: zresetuj twardo i usuń niepotwierdzone pliki
|
<kbd>D</kbd>: view reset options
|
||||||
<kbd>enter</kbd>: zatwierdź pojedyncze linie
|
<kbd>enter</kbd>: zatwierdź pojedyncze linie
|
||||||
<kbd>f</kbd>: fetch
|
<kbd>f</kbd>: fetch
|
||||||
</pre>
|
</pre>
|
||||||
|
@ -72,6 +71,7 @@
|
||||||
<kbd>C</kbd>: copy commit range (cherry-pick)
|
<kbd>C</kbd>: copy commit range (cherry-pick)
|
||||||
<kbd>v</kbd>: paste commits (cherry-pick)
|
<kbd>v</kbd>: paste commits (cherry-pick)
|
||||||
<kbd>enter</kbd>: view commit's files
|
<kbd>enter</kbd>: view commit's files
|
||||||
|
<kbd>space</kbd>: diff specific commits
|
||||||
</pre>
|
</pre>
|
||||||
|
|
||||||
## Schowek
|
## Schowek
|
||||||
|
|
|
@ -13,6 +13,7 @@ type Commit struct {
|
||||||
DisplayString string
|
DisplayString string
|
||||||
Action string // one of "", "pick", "edit", "squash", "reword", "drop", "fixup"
|
Action string // one of "", "pick", "edit", "squash", "reword", "drop", "fixup"
|
||||||
Copied bool // to know if this commit is ready to be cherry-picked somewhere
|
Copied bool // to know if this commit is ready to be cherry-picked somewhere
|
||||||
|
Selected bool
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetDisplayStrings is a function.
|
// GetDisplayStrings is a function.
|
||||||
|
@ -52,5 +53,12 @@ func (c *Commit) GetDisplayStrings(isFocused bool) []string {
|
||||||
actionString = cyan.Sprint(utils.WithPadding(c.Action, 7)) + " "
|
actionString = cyan.Sprint(utils.WithPadding(c.Action, 7)) + " "
|
||||||
}
|
}
|
||||||
|
|
||||||
return []string{shaColor.Sprint(c.Sha), actionString + white.Sprint(c.Name)}
|
name := ""
|
||||||
|
if c.Selected {
|
||||||
|
name = color.New(color.FgMagenta).Sprint(c.Name)
|
||||||
|
} else {
|
||||||
|
name = white.Sprint(c.Name)
|
||||||
|
}
|
||||||
|
|
||||||
|
return []string{shaColor.Sprint(c.Sha), actionString + name}
|
||||||
}
|
}
|
||||||
|
|
|
@ -910,3 +910,9 @@ func (c *GitCommand) ResetHardHead() error {
|
||||||
func (c *GitCommand) ResetSoftHead() error {
|
func (c *GitCommand) ResetSoftHead() error {
|
||||||
return c.OSCommand.RunCommand("git reset --soft HEAD")
|
return c.OSCommand.RunCommand("git reset --soft HEAD")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// DiffCommits show diff between commits
|
||||||
|
func (c *GitCommand) DiffCommits(sha1, sha2 string) (string, error) {
|
||||||
|
cmd := fmt.Sprintf("git diff --color %s %s", sha1, sha2)
|
||||||
|
return c.OSCommand.RunCommandWithOutput(cmd)
|
||||||
|
}
|
||||||
|
|
|
@ -39,6 +39,12 @@ func (gui *Gui) handleCommitSelect(g *gocui.Gui, v *gocui.View) error {
|
||||||
if err := gui.focusPoint(0, gui.State.Panels.Commits.SelectedLine, len(gui.State.Commits), v); err != nil {
|
if err := gui.focusPoint(0, gui.State.Panels.Commits.SelectedLine, len(gui.State.Commits), v); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// if specific diff mode is on, don't show diff
|
||||||
|
if gui.State.Panels.Commits.SpecificDiffMode {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
commitText, err := gui.GitCommand.Show(commit.Sha)
|
commitText, err := gui.GitCommand.Show(commit.Sha)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
@ -56,6 +62,13 @@ func (gui *Gui) refreshCommits(g *gocui.Gui) error {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for _, commit := range commits {
|
||||||
|
if _, has := gui.State.DiffEntries[commit.Sha]; has {
|
||||||
|
commit.Selected = true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
gui.State.Commits = commits
|
gui.State.Commits = commits
|
||||||
|
|
||||||
gui.refreshSelectedLine(&gui.State.Panels.Commits.SelectedLine, len(gui.State.Commits))
|
gui.refreshSelectedLine(&gui.State.Panels.Commits.SelectedLine, len(gui.State.Commits))
|
||||||
|
@ -448,3 +461,56 @@ func (gui *Gui) handleSwitchToCommitFilesPanel(g *gocui.Gui, v *gocui.View) erro
|
||||||
|
|
||||||
return gui.switchFocus(g, v, gui.getCommitFilesView())
|
return gui.switchFocus(g, v, gui.getCommitFilesView())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (gui *Gui) handleToggleDiffCommit(g *gocui.Gui, v *gocui.View) error {
|
||||||
|
selectLimit := 2
|
||||||
|
|
||||||
|
// get selected commit
|
||||||
|
commit := gui.getSelectedCommit(g)
|
||||||
|
if commit == nil {
|
||||||
|
return gui.renderString(g, "main", gui.Tr.SLocalize("NoCommitsThisBranch"))
|
||||||
|
}
|
||||||
|
|
||||||
|
// if already selected commit delete
|
||||||
|
if _, has := gui.State.DiffEntries[commit.Sha]; has {
|
||||||
|
delete(gui.State.DiffEntries, commit.Sha)
|
||||||
|
gui.setDiffMode()
|
||||||
|
} else {
|
||||||
|
if len(gui.State.DiffEntries) == selectLimit {
|
||||||
|
return gui.createErrorPanel(gui.g, "you have already selected two commit, please deselect one of two")
|
||||||
|
}
|
||||||
|
gui.State.DiffEntries[commit.Sha] = commit
|
||||||
|
gui.setDiffMode()
|
||||||
|
}
|
||||||
|
|
||||||
|
// if selected tow commits, display diff between
|
||||||
|
if len(gui.State.DiffEntries) == selectLimit {
|
||||||
|
var entries []string
|
||||||
|
for _, entry := range gui.State.DiffEntries {
|
||||||
|
entries = append(entries, entry.Sha)
|
||||||
|
}
|
||||||
|
|
||||||
|
commitText, err := gui.GitCommand.DiffCommits(entries[0], entries[1])
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
return gui.createErrorPanel(gui.g, err.Error())
|
||||||
|
}
|
||||||
|
|
||||||
|
return gui.renderString(g, "main", commitText)
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (gui *Gui) setDiffMode() {
|
||||||
|
v := gui.getCommitsView()
|
||||||
|
if len(gui.State.DiffEntries) != 0 {
|
||||||
|
gui.State.Panels.Commits.SpecificDiffMode = true
|
||||||
|
v.Title = gui.Tr.SLocalize("CommitsDiffTitle")
|
||||||
|
} else {
|
||||||
|
gui.State.Panels.Commits.SpecificDiffMode = false
|
||||||
|
v.Title = gui.Tr.SLocalize("CommitsTitle")
|
||||||
|
}
|
||||||
|
|
||||||
|
gui.refreshCommits(gui.g)
|
||||||
|
}
|
||||||
|
|
|
@ -104,6 +104,7 @@ type branchPanelState struct {
|
||||||
|
|
||||||
type commitPanelState struct {
|
type commitPanelState struct {
|
||||||
SelectedLine int
|
SelectedLine int
|
||||||
|
SpecificDiffMode bool
|
||||||
}
|
}
|
||||||
|
|
||||||
type stashPanelState struct {
|
type stashPanelState struct {
|
||||||
|
@ -135,6 +136,7 @@ type guiState struct {
|
||||||
Commits []*commands.Commit
|
Commits []*commands.Commit
|
||||||
StashEntries []*commands.StashEntry
|
StashEntries []*commands.StashEntry
|
||||||
CommitFiles []*commands.CommitFile
|
CommitFiles []*commands.CommitFile
|
||||||
|
DiffEntries map[string]*commands.Commit
|
||||||
MenuItemCount int // can't store the actual list because it's of interface{} type
|
MenuItemCount int // can't store the actual list because it's of interface{} type
|
||||||
PreviousView string
|
PreviousView string
|
||||||
Platform commands.Platform
|
Platform commands.Platform
|
||||||
|
@ -154,6 +156,7 @@ func NewGui(log *logrus.Entry, gitCommand *commands.GitCommand, oSCommand *comma
|
||||||
Commits: make([]*commands.Commit, 0),
|
Commits: make([]*commands.Commit, 0),
|
||||||
CherryPickedCommits: make([]*commands.Commit, 0),
|
CherryPickedCommits: make([]*commands.Commit, 0),
|
||||||
StashEntries: make([]*commands.StashEntry, 0),
|
StashEntries: make([]*commands.StashEntry, 0),
|
||||||
|
DiffEntries: make(map[string]*commands.Commit),
|
||||||
Platform: *oSCommand.Platform,
|
Platform: *oSCommand.Platform,
|
||||||
Panels: &panelStates{
|
Panels: &panelStates{
|
||||||
Files: &filePanelState{SelectedLine: -1},
|
Files: &filePanelState{SelectedLine: -1},
|
||||||
|
|
|
@ -388,6 +388,12 @@ func (gui *Gui) GetInitialKeybindings() []*Binding {
|
||||||
Modifier: gocui.ModNone,
|
Modifier: gocui.ModNone,
|
||||||
Handler: gui.handleSwitchToCommitFilesPanel,
|
Handler: gui.handleSwitchToCommitFilesPanel,
|
||||||
Description: gui.Tr.SLocalize("viewCommitFiles"),
|
Description: gui.Tr.SLocalize("viewCommitFiles"),
|
||||||
|
}, {
|
||||||
|
ViewName: "commits",
|
||||||
|
Key: gocui.KeySpace,
|
||||||
|
Modifier: gocui.ModNone,
|
||||||
|
Handler: gui.handleToggleDiffCommit,
|
||||||
|
Description: gui.Tr.SLocalize("CommitsDiff"),
|
||||||
}, {
|
}, {
|
||||||
ViewName: "stash",
|
ViewName: "stash",
|
||||||
Key: gocui.KeySpace,
|
Key: gocui.KeySpace,
|
||||||
|
|
|
@ -28,6 +28,12 @@ func addDutch(i18nObject *i18n.Bundle) error {
|
||||||
}, &i18n.Message{
|
}, &i18n.Message{
|
||||||
ID: "CommitsTitle",
|
ID: "CommitsTitle",
|
||||||
Other: "Commits",
|
Other: "Commits",
|
||||||
|
}, &i18n.Message{
|
||||||
|
ID: "CommitsDiffTitle",
|
||||||
|
Other: "Commits(specific diff mode)",
|
||||||
|
}, &i18n.Message{
|
||||||
|
ID: "CommitsDiff",
|
||||||
|
Other: "diff specific commits",
|
||||||
}, &i18n.Message{
|
}, &i18n.Message{
|
||||||
ID: "StashTitle",
|
ID: "StashTitle",
|
||||||
Other: "Stash",
|
Other: "Stash",
|
||||||
|
|
|
@ -36,6 +36,12 @@ func addEnglish(i18nObject *i18n.Bundle) error {
|
||||||
}, &i18n.Message{
|
}, &i18n.Message{
|
||||||
ID: "CommitsTitle",
|
ID: "CommitsTitle",
|
||||||
Other: "Commits",
|
Other: "Commits",
|
||||||
|
}, &i18n.Message{
|
||||||
|
ID: "CommitsDiffTitle",
|
||||||
|
Other: "Commits(specific diff mode)",
|
||||||
|
}, &i18n.Message{
|
||||||
|
ID: "CommitsDiff",
|
||||||
|
Other: "diff specific commits",
|
||||||
}, &i18n.Message{
|
}, &i18n.Message{
|
||||||
ID: "StashTitle",
|
ID: "StashTitle",
|
||||||
Other: "Stash",
|
Other: "Stash",
|
||||||
|
|
|
@ -26,6 +26,12 @@ func addPolish(i18nObject *i18n.Bundle) error {
|
||||||
}, &i18n.Message{
|
}, &i18n.Message{
|
||||||
ID: "CommitsTitle",
|
ID: "CommitsTitle",
|
||||||
Other: "Commity",
|
Other: "Commity",
|
||||||
|
}, &i18n.Message{
|
||||||
|
ID: "CommitsDiffTitle",
|
||||||
|
Other: "Commits(specific diff mode)",
|
||||||
|
}, &i18n.Message{
|
||||||
|
ID: "CommitsDiff",
|
||||||
|
Other: "diff specific commits",
|
||||||
}, &i18n.Message{
|
}, &i18n.Message{
|
||||||
ID: "StashTitle",
|
ID: "StashTitle",
|
||||||
Other: "Schowek",
|
Other: "Schowek",
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue