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 09fe610c2..235809753 100644 --- a/pkg/commands/git.go +++ b/pkg/commands/git.go @@ -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 760dee934..907f14204 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 { @@ -157,6 +184,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 68bb295e5..52496b918 100644 --- a/pkg/gui/keybindings.go +++ b/pkg/gui/keybindings.go @@ -39,7 +39,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 6fda2dee0..5b8624e21 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..5364d3d8f 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 wszystkie zatwierdzenia", }, &i18n.Message{ ID: "refresh", Other: "odśwież",