mirror of
https://github.com/jesseduffield/lazygit.git
synced 2026-05-22 10:15:43 +02:00
Merge pull request #1870 from mark2185/feature/stash-unstaged
This commit is contained in:
@@ -38,7 +38,6 @@ func (self *StashCommands) Apply(index int) error {
|
||||
}
|
||||
|
||||
// Save save stash
|
||||
// TODO: before calling this, check if there is anything to save
|
||||
func (self *StashCommands) Save(message string) error {
|
||||
return self.cmd.New("git stash save " + self.cmd.Quote(message)).Run()
|
||||
}
|
||||
@@ -49,6 +48,23 @@ 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()
|
||||
}
|
||||
|
||||
func (self *StashCommands) StashUnstagedChanges(message string) error {
|
||||
if err := self.cmd.New("git commit --no-verify -m \"[lazygit] stashing unstaged changes\"").Run(); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := self.Save(message); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := self.cmd.New("git reset --soft HEAD^").Run(); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// 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 {
|
||||
|
||||
@@ -559,23 +559,46 @@ func (self *FilesController) createStashMenu() error {
|
||||
{
|
||||
DisplayString: self.c.Tr.LcStashAllChanges,
|
||||
OnPress: func() error {
|
||||
return self.handleStashSave(self.git.Stash.Save, self.c.Tr.Actions.StashAllChanges)
|
||||
return self.handleStashSave(self.git.Stash.Save, self.c.Tr.Actions.StashAllChanges, self.c.Tr.NoFilesToStash)
|
||||
},
|
||||
Key: 's',
|
||||
Key: 'a',
|
||||
},
|
||||
{
|
||||
DisplayString: self.c.Tr.LcStashAllChangesKeepIndex,
|
||||
OnPress: func() error {
|
||||
// if there are no staged files it behaves the same as Stash.Save
|
||||
return self.handleStashSave(self.git.Stash.StashAndKeepIndex, self.c.Tr.Actions.StashAllChangesKeepIndex, self.c.Tr.NoFilesToStash)
|
||||
},
|
||||
Key: 'i',
|
||||
},
|
||||
{
|
||||
DisplayString: self.c.Tr.LcStashStagedChanges,
|
||||
OnPress: func() error {
|
||||
return self.handleStashSave(self.git.Stash.SaveStagedChanges, self.c.Tr.Actions.StashStagedChanges)
|
||||
// there must be something in staging otherwise the current implementation mucks the stash up
|
||||
if !self.helpers.WorkingTree.AnyStagedFiles() {
|
||||
return self.c.ErrorMsg(self.c.Tr.NoTrackedStagedFilesStash)
|
||||
}
|
||||
return self.handleStashSave(self.git.Stash.SaveStagedChanges, self.c.Tr.Actions.StashStagedChanges, self.c.Tr.NoTrackedStagedFilesStash)
|
||||
},
|
||||
Key: 'S',
|
||||
Key: 's',
|
||||
},
|
||||
{
|
||||
DisplayString: self.c.Tr.LcStashUnstagedChanges,
|
||||
OnPress: func() error {
|
||||
if self.helpers.WorkingTree.AnyStagedFiles() {
|
||||
return self.handleStashSave(self.git.Stash.StashUnstagedChanges, self.c.Tr.Actions.StashUnstagedChanges, self.c.Tr.NoFilesToStash)
|
||||
}
|
||||
// ordinary stash
|
||||
return self.handleStashSave(self.git.Stash.Save, self.c.Tr.Actions.StashUnstagedChanges, self.c.Tr.NoFilesToStash)
|
||||
},
|
||||
Key: 'u',
|
||||
},
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
func (self *FilesController) stash() error {
|
||||
return self.handleStashSave(self.git.Stash.Save, self.c.Tr.Actions.StashAllChanges)
|
||||
return self.handleStashSave(self.git.Stash.Save, self.c.Tr.Actions.StashAllChanges, self.c.Tr.NoTrackedStagedFilesStash)
|
||||
}
|
||||
|
||||
func (self *FilesController) createResetToUpstreamMenu() error {
|
||||
@@ -603,9 +626,9 @@ func (self *FilesController) toggleTreeView() error {
|
||||
return self.c.PostRefreshUpdate(self.context())
|
||||
}
|
||||
|
||||
func (self *FilesController) handleStashSave(stashFunc func(message string) error, action string) error {
|
||||
func (self *FilesController) handleStashSave(stashFunc func(message string) error, action string, errorMsg string) error {
|
||||
if !self.helpers.WorkingTree.IsWorkingTreeDirty() {
|
||||
return self.c.ErrorMsg(self.c.Tr.NoTrackedStagedFilesStash)
|
||||
return self.c.ErrorMsg(errorMsg)
|
||||
}
|
||||
|
||||
return self.c.Prompt(types.PromptOpts{
|
||||
|
||||
+1
-1
@@ -282,7 +282,7 @@ func chineseTranslationSet() TranslationSet {
|
||||
PressEnterToReturn: "按下 Enter 键返回 lazygit",
|
||||
LcViewStashOptions: "查看贮藏选项",
|
||||
LcStashAllChanges: "将所有更改加入贮藏",
|
||||
LcStashStagedChanges: "将已暂存的更改加入贮藏",
|
||||
LcStashAllChangesKeepIndex: "将已暂存的更改加入贮藏",
|
||||
LcStashOptions: "贮藏选项",
|
||||
NotARepository: "错误:必须在 git 仓库中运行",
|
||||
LcJump: "跳到面板",
|
||||
|
||||
+1
-1
@@ -245,7 +245,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",
|
||||
|
||||
+11
-1
@@ -119,6 +119,7 @@ type TranslationSet struct {
|
||||
StashApply string
|
||||
SureApplyStashEntry string
|
||||
NoTrackedStagedFilesStash string
|
||||
NoFilesToStash string
|
||||
StashChanges string
|
||||
OpenConfig string
|
||||
EditConfig string
|
||||
@@ -276,6 +277,8 @@ type TranslationSet struct {
|
||||
LcViewStashOptions string
|
||||
LcStashAllChanges string
|
||||
LcStashStagedChanges string
|
||||
LcStashAllChangesKeepIndex string
|
||||
LcStashUnstagedChanges string
|
||||
LcStashOptions string
|
||||
NotARepository string
|
||||
LcJump string
|
||||
@@ -550,7 +553,9 @@ type Actions struct {
|
||||
Pull string
|
||||
OpenFile string
|
||||
StashAllChanges string
|
||||
StashAllChangesKeepIndex string
|
||||
StashStagedChanges string
|
||||
StashUnstagedChanges string
|
||||
GitFlowFinish string
|
||||
GitFlowStart string
|
||||
CopyToClipboard string
|
||||
@@ -724,6 +729,7 @@ func EnglishTranslationSet() TranslationSet {
|
||||
StashApply: "Stash apply",
|
||||
SureApplyStashEntry: "Are you sure you want to apply this stash entry?",
|
||||
NoTrackedStagedFilesStash: "You have no tracked/staged files to stash",
|
||||
NoFilesToStash: "You have no files to stash",
|
||||
StashChanges: "Stash changes",
|
||||
OpenConfig: "open config file",
|
||||
EditConfig: "edit config file",
|
||||
@@ -880,8 +886,10 @@ func EnglishTranslationSet() TranslationSet {
|
||||
LcResetTo: `reset to`,
|
||||
PressEnterToReturn: "Press enter to return to lazygit",
|
||||
LcViewStashOptions: "view stash options",
|
||||
LcStashAllChanges: "stash changes",
|
||||
LcStashAllChanges: "stash all changes",
|
||||
LcStashStagedChanges: "stash staged 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",
|
||||
@@ -1139,7 +1147,9 @@ func EnglishTranslationSet() TranslationSet {
|
||||
Pull: "Pull",
|
||||
OpenFile: "Open file",
|
||||
StashAllChanges: "Stash all changes",
|
||||
StashAllChangesKeepIndex: "Stash all changes and keep index",
|
||||
StashStagedChanges: "Stash staged changes",
|
||||
StashUnstagedChanges: "Stash unstaged changes",
|
||||
GitFlowFinish: "Git flow finish",
|
||||
GitFlowStart: "Git Flow start",
|
||||
CopyToClipboard: "Copy to clipboard",
|
||||
|
||||
+1
-1
@@ -207,7 +207,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",
|
||||
|
||||
Reference in New Issue
Block a user