From 6f7038c8277f82c32d2c23502f94fdf675ad07e1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luka=20Marku=C5=A1i=C4=87?= Date: Fri, 8 Apr 2022 11:32:23 +0200 Subject: [PATCH] Add option to stash only unstaged files --- docs/keybindings/Keybindings_en.md | 2 +- pkg/commands/git_commands/stash.go | 4 ++++ pkg/gui/controllers/files_controller.go | 23 +++++++++++++++++++---- pkg/i18n/chinese.go | 2 +- pkg/i18n/dutch.go | 2 +- pkg/i18n/english.go | 10 +++++++--- pkg/i18n/polish.go | 2 +- 7 files changed, 34 insertions(+), 11 deletions(-) diff --git a/docs/keybindings/Keybindings_en.md b/docs/keybindings/Keybindings_en.md index 3a1d21fbd..7b53c0e34 100644 --- a/docs/keybindings/Keybindings_en.md +++ b/docs/keybindings/Keybindings_en.md @@ -124,7 +124,7 @@ _This file is auto-generated. To update, make the changes in the pkg/i18n direct o: open file i: add to .gitignore r: refresh files - s: stash changes + s: stash all changes S: view stash options a: stage/unstage all enter: stage individual hunks/lines for file, or collapse/expand for directory diff --git a/pkg/commands/git_commands/stash.go b/pkg/commands/git_commands/stash.go index d20024aa9..26460bfa0 100644 --- a/pkg/commands/git_commands/stash.go +++ b/pkg/commands/git_commands/stash.go @@ -49,6 +49,10 @@ func (self *StashCommands) ShowStashEntryCmdObj(index int) oscommands.ICmdObj { return self.cmd.New(cmdStr).DontLog() } +func (self *StashCommands) StashAndKeepIndex(message string) error { + return self.cmd.New(fmt.Sprintf("git stash save %s --keep-index", self.cmd.Quote(message))).Run() +} + // SaveStagedChanges stashes only the currently staged changes. This takes a few steps // shoutouts to Joe on https://stackoverflow.com/questions/14759748/stashing-only-staged-changes-in-git-is-it-possible func (self *StashCommands) SaveStagedChanges(message string) error { diff --git a/pkg/gui/controllers/files_controller.go b/pkg/gui/controllers/files_controller.go index 764c9753b..e37cc0951 100644 --- a/pkg/gui/controllers/files_controller.go +++ b/pkg/gui/controllers/files_controller.go @@ -561,14 +561,21 @@ func (self *FilesController) createStashMenu() error { OnPress: func() error { return self.handleStashSave(self.git.Stash.Save, self.c.Tr.Actions.StashAllChanges) }, - Key: 's', + Key: 'a', }, { - DisplayString: self.c.Tr.LcStashStagedChanges, + DisplayString: self.c.Tr.LcStashAllChangesKeepIndex, OnPress: func() error { - return self.handleStashSave(self.git.Stash.SaveStagedChanges, self.c.Tr.Actions.StashStagedChanges) + return self.handleStagedStashSave() }, - Key: 'S', + Key: 'i', + }, + { + DisplayString: self.c.Tr.LcStashUnstagedChanges, + OnPress: func() error { + return self.handleStashSave(self.git.Stash.StashAndKeepIndex, self.c.Tr.Actions.StashUnstagedChanges) + }, + Key: 'u', }, }, }) @@ -603,6 +610,14 @@ func (self *FilesController) toggleTreeView() error { return self.c.PostRefreshUpdate(self.context()) } +func (self *FilesController) handleStagedStashSave() error { + if !self.helpers.WorkingTree.AnyStagedFiles() { + return self.c.ErrorMsg(self.c.Tr.NoTrackedStagedFilesStash) + } + + return self.handleStashSave(self.git.Stash.StashAndKeepIndex, self.c.Tr.Actions.StashStagedChanges) +} + func (self *FilesController) handleStashSave(stashFunc func(message string) error, action string) error { if !self.helpers.WorkingTree.IsWorkingTreeDirty() { return self.c.ErrorMsg(self.c.Tr.NoTrackedStagedFilesStash) diff --git a/pkg/i18n/chinese.go b/pkg/i18n/chinese.go index 2e4c4abc9..f9d8d26db 100644 --- a/pkg/i18n/chinese.go +++ b/pkg/i18n/chinese.go @@ -283,7 +283,7 @@ func chineseTranslationSet() TranslationSet { PressEnterToReturn: "按下 Enter 键返回 lazygit", LcViewStashOptions: "查看贮藏选项", LcStashAllChanges: "将所有更改加入贮藏", - LcStashStagedChanges: "将已暂存的更改加入贮藏", + LcStashAllChangesKeepIndex: "将已暂存的更改加入贮藏", LcStashOptions: "贮藏选项", NotARepository: "错误:必须在 git 仓库中运行", LcJump: "跳到面板", diff --git a/pkg/i18n/dutch.go b/pkg/i18n/dutch.go index 7069734c9..ee42ab34a 100644 --- a/pkg/i18n/dutch.go +++ b/pkg/i18n/dutch.go @@ -246,7 +246,7 @@ func dutchTranslationSet() TranslationSet { PressEnterToReturn: "Press om terug te gaan naar lazygit", LcViewStashOptions: "bekijk stash opties", LcStashAllChanges: "stash-bestanden", - LcStashStagedChanges: "stash staged wijzigingen", + LcStashAllChangesKeepIndex: "stash staged wijzigingen", LcStashOptions: "Stash opties", NotARepository: "Fout: moet in een git repository uitgevoerd worden", LcJump: "ga naar paneel", diff --git a/pkg/i18n/english.go b/pkg/i18n/english.go index 585da5e30..1df120dda 100644 --- a/pkg/i18n/english.go +++ b/pkg/i18n/english.go @@ -276,7 +276,8 @@ type TranslationSet struct { PressEnterToReturn string LcViewStashOptions string LcStashAllChanges string - LcStashStagedChanges string + LcStashAllChangesKeepIndex string + LcStashUnstagedChanges string LcStashOptions string NotARepository string LcJump string @@ -545,6 +546,7 @@ type Actions struct { OpenFile string StashAllChanges string StashStagedChanges string + StashUnstagedChanges string GitFlowFinish string GitFlowStart string CopyToClipboard string @@ -875,8 +877,9 @@ func EnglishTranslationSet() TranslationSet { LcResetTo: `reset to`, PressEnterToReturn: "Press enter to return to lazygit", LcViewStashOptions: "view stash options", - LcStashAllChanges: "stash changes", - LcStashStagedChanges: "stash staged changes", + LcStashAllChanges: "stash all changes", + LcStashAllChangesKeepIndex: "stash all changes and keep index", + LcStashUnstagedChanges: "stash unstaged changes", LcStashOptions: "Stash options", NotARepository: "Error: must be run inside a git repository", LcJump: "jump to panel", @@ -1128,6 +1131,7 @@ func EnglishTranslationSet() TranslationSet { OpenFile: "Open file", StashAllChanges: "Stash all changes", StashStagedChanges: "Stash staged changes", + StashUnstagedChanges: "Stash unstaged changes", GitFlowFinish: "Git flow finish", GitFlowStart: "Git Flow start", CopyToClipboard: "Copy to clipboard", diff --git a/pkg/i18n/polish.go b/pkg/i18n/polish.go index 3ed130e05..53b67c476 100644 --- a/pkg/i18n/polish.go +++ b/pkg/i18n/polish.go @@ -208,7 +208,7 @@ func polishTranslationSet() TranslationSet { PressEnterToReturn: "Wciśnij enter żeby wrócić do lazygit", LcViewStashOptions: "wyświetl opcje schowka", LcStashAllChanges: "przechowaj zmiany", - LcStashStagedChanges: "przechowaj zmiany z poczekalni", + LcStashAllChangesKeepIndex: "przechowaj zmiany z poczekalni", LcStashOptions: "Opcje schowka", NotARepository: "Błąd: nie jesteś w repozytorium", LcJump: "przeskocz do panelu",