From 60422912c8d41628c5ed1b4dd9432694c1be9199 Mon Sep 17 00:00:00 2001 From: Jesse Duffield Date: Sat, 25 Aug 2018 08:51:47 +1000 Subject: [PATCH 1/2] add 'a' keybinding to toggle staged/unstaged for all files --- docs/Keybindings.md | 2 ++ pkg/commands/git.go | 12 +++++++++++- pkg/gui/files_panel.go | 28 ++++++++++++++++++++++++++++ pkg/gui/keybindings.go | 3 ++- pkg/i18n/dutch.go | 3 +++ pkg/i18n/english.go | 3 +++ pkg/i18n/polish.go | 3 +++ 7 files changed, 52 insertions(+), 2 deletions(-) diff --git a/docs/Keybindings.md b/docs/Keybindings.md index 37fb523a2..9160b9c2b 100644 --- a/docs/Keybindings.md +++ b/docs/Keybindings.md @@ -22,6 +22,7 @@
   space:    toggle staged
+  a:        stage/unstage all
   c:        commit changes
   shift+C: commit using git editor
   shift+S: stash files
@@ -33,6 +34,7 @@
   i:        add to .gitignore
   d:        delete if untracked checkout if tracked (aka go away)
   shift+R: refresh files
+  shift+A: abort merge
 
## Branches Panel: diff --git a/pkg/commands/git.go b/pkg/commands/git.go index 14f3a433a..ab4cebf87 100644 --- a/pkg/commands/git.go +++ b/pkg/commands/git.go @@ -7,9 +7,9 @@ import ( "os/exec" "strings" - "github.com/sirupsen/logrus" "github.com/jesseduffield/gocui" "github.com/jesseduffield/lazygit/pkg/utils" + "github.com/sirupsen/logrus" gitconfig "github.com/tcnksm/go-gitconfig" gogit "gopkg.in/src-d/go-git.v4" ) @@ -340,6 +340,16 @@ func (c *GitCommand) StageFile(fileName string) error { return c.OSCommand.RunCommand("git add " + c.OSCommand.Quote(fileName)) } +// StageAll stages all files +func (c *GitCommand) StageAll() error { + return c.OSCommand.RunCommand("git add -A") +} + +// UnstageAll stages all files +func (c *GitCommand) UnstageAll() error { + return c.OSCommand.RunCommand("git reset") +} + // UnStageFile unstages a file func (c *GitCommand) UnStageFile(fileName string, tracked bool) error { var command string diff --git a/pkg/gui/files_panel.go b/pkg/gui/files_panel.go index 5791a9d15..642f6432a 100644 --- a/pkg/gui/files_panel.go +++ b/pkg/gui/files_panel.go @@ -71,6 +71,33 @@ func (gui *Gui) handleFilePress(g *gocui.Gui, v *gocui.View) error { return gui.handleFileSelect(g, v) } +func (gui *Gui) allFilesStaged() bool { + for _, file := range gui.State.Files { + if file.HasUnstagedChanges { + return false + } + } + return true +} + +func (gui *Gui) handleStageAll(g *gocui.Gui, v *gocui.View) error { + var err error + if gui.allFilesStaged() { + err = gui.GitCommand.UnstageAll() + } else { + err = gui.GitCommand.StageAll() + } + if err != nil { + _ = gui.createErrorPanel(g, err.Error()) + } + + if err := gui.refreshFiles(g); err != nil { + return err + } + + return gui.handleFileSelect(g, v) +} + func (gui *Gui) handleAddPatch(g *gocui.Gui, v *gocui.View) error { file, err := gui.getSelectedFile(g) if err != nil { @@ -160,6 +187,7 @@ func (gui *Gui) renderfilesOptions(g *gocui.Gui, file *commands.File) error { "R": gui.Tr.SLocalize("refresh"), "t": gui.Tr.SLocalize("addPatch"), "e": gui.Tr.SLocalize("edit"), + "a": gui.Tr.SLocalize("toggleStagedAll"), "PgUp/PgDn": gui.Tr.SLocalize("scroll"), } if gui.State.HasMergeConflicts { diff --git a/pkg/gui/keybindings.go b/pkg/gui/keybindings.go index 8041d14ff..e48507724 100644 --- a/pkg/gui/keybindings.go +++ b/pkg/gui/keybindings.go @@ -38,7 +38,8 @@ func (gui *Gui) keybindings(g *gocui.Gui) error { {ViewName: "files", Key: 'i', Modifier: gocui.ModNone, Handler: gui.handleIgnoreFile}, {ViewName: "files", Key: 'r', Modifier: gocui.ModNone, Handler: gui.handleRefreshFiles}, {ViewName: "files", Key: 'S', Modifier: gocui.ModNone, Handler: gui.handleStashSave}, - {ViewName: "files", Key: 'a', Modifier: gocui.ModNone, Handler: gui.handleAbortMerge}, + {ViewName: "files", Key: 'A', Modifier: gocui.ModNone, Handler: gui.handleAbortMerge}, + {ViewName: "files", Key: 'a', Modifier: gocui.ModNone, Handler: gui.handleStageAll}, {ViewName: "files", Key: 't', Modifier: gocui.ModNone, Handler: gui.handleAddPatch}, {ViewName: "files", Key: 'D', Modifier: gocui.ModNone, Handler: gui.handleResetHard}, {ViewName: "main", Key: gocui.KeyEsc, Modifier: gocui.ModNone, Handler: gui.handleEscapeMerge}, diff --git a/pkg/i18n/dutch.go b/pkg/i18n/dutch.go index 68e7c82bd..ff588b264 100644 --- a/pkg/i18n/dutch.go +++ b/pkg/i18n/dutch.go @@ -55,6 +55,9 @@ func addDutch(i18nObject *i18n.Bundle) error { }, &i18n.Message{ ID: "toggleStaged", Other: "toggle staged", + }, &i18n.Message{ + ID: "toggleStagedAll", + Other: "toggle staged alle", }, &i18n.Message{ ID: "refresh", Other: "verversen", diff --git a/pkg/i18n/english.go b/pkg/i18n/english.go index 38fbac4cb..9c20826ac 100644 --- a/pkg/i18n/english.go +++ b/pkg/i18n/english.go @@ -63,6 +63,9 @@ func addEnglish(i18nObject *i18n.Bundle) error { }, &i18n.Message{ ID: "toggleStaged", Other: "toggle staged", + }, &i18n.Message{ + ID: "toggleStagedAll", + Other: "stage/unstage all", }, &i18n.Message{ ID: "refresh", Other: "refresh", diff --git a/pkg/i18n/polish.go b/pkg/i18n/polish.go index 9b9fa19e1..4bbfb91d5 100644 --- a/pkg/i18n/polish.go +++ b/pkg/i18n/polish.go @@ -53,6 +53,9 @@ func addPolish(i18nObject *i18n.Bundle) error { }, &i18n.Message{ ID: "toggleStaged", Other: "przełącz zatwierdzenie", + }, &i18n.Message{ + ID: "toggleStagedAll", + Other: "przełącz zatwierdzenie wszystko", }, &i18n.Message{ ID: "refresh", Other: "odśwież", From da2d3f253ffa3c044bf4b6b6c983c7d059af05db Mon Sep 17 00:00:00 2001 From: Jesse Duffield Date: Mon, 27 Aug 2018 20:58:17 +1000 Subject: [PATCH 2/2] better translation --- pkg/i18n/polish.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/i18n/polish.go b/pkg/i18n/polish.go index 4bbfb91d5..5364d3d8f 100644 --- a/pkg/i18n/polish.go +++ b/pkg/i18n/polish.go @@ -55,7 +55,7 @@ func addPolish(i18nObject *i18n.Bundle) error { Other: "przełącz zatwierdzenie", }, &i18n.Message{ ID: "toggleStagedAll", - Other: "przełącz zatwierdzenie wszystko", + Other: "przełącz wszystkie zatwierdzenia", }, &i18n.Message{ ID: "refresh", Other: "odśwież",