1
0
mirror of https://github.com/jesseduffield/lazygit.git synced 2025-02-03 13:21:56 +02:00

Add option to stash only unstaged files

This commit is contained in:
Luka Markušić 2022-04-08 11:32:23 +02:00
parent 58ed23a47a
commit 6f7038c827
7 changed files with 34 additions and 11 deletions

View File

@ -124,7 +124,7 @@ _This file is auto-generated. To update, make the changes in the pkg/i18n direct
<kbd>o</kbd>: open file
<kbd>i</kbd>: add to .gitignore
<kbd>r</kbd>: refresh files
<kbd>s</kbd>: stash changes
<kbd>s</kbd>: stash all changes
<kbd>S</kbd>: view stash options
<kbd>a</kbd>: stage/unstage all
<kbd>enter</kbd>: stage individual hunks/lines for file, or collapse/expand for directory

View File

@ -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 {

View File

@ -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)

View File

@ -283,7 +283,7 @@ func chineseTranslationSet() TranslationSet {
PressEnterToReturn: "按下 Enter 键返回 lazygit",
LcViewStashOptions: "查看贮藏选项",
LcStashAllChanges: "将所有更改加入贮藏",
LcStashStagedChanges: "将已暂存的更改加入贮藏",
LcStashAllChangesKeepIndex: "将已暂存的更改加入贮藏",
LcStashOptions: "贮藏选项",
NotARepository: "错误:必须在 git 仓库中运行",
LcJump: "跳到面板",

View File

@ -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",

View File

@ -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",

View File

@ -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",