diff options
-rw-r--r-- | docs/Config.md | 1 | ||||
-rw-r--r-- | docs/keybindings/Keybindings_en.md | 1 | ||||
-rw-r--r-- | docs/keybindings/Keybindings_ja.md | 1 | ||||
-rw-r--r-- | docs/keybindings/Keybindings_ko.md | 1 | ||||
-rw-r--r-- | docs/keybindings/Keybindings_nl.md | 1 | ||||
-rw-r--r-- | docs/keybindings/Keybindings_pl.md | 1 | ||||
-rw-r--r-- | docs/keybindings/Keybindings_zh.md | 1 | ||||
-rw-r--r-- | pkg/commands/git_commands/stash.go | 14 | ||||
-rw-r--r-- | pkg/commands/git_commands/stash_test.go | 48 | ||||
-rw-r--r-- | pkg/config/user_config.go | 6 | ||||
-rw-r--r-- | pkg/gui/controllers/stash_controller.go | 45 | ||||
-rw-r--r-- | pkg/i18n/chinese.go | 3 | ||||
-rw-r--r-- | pkg/i18n/dutch.go | 2 | ||||
-rw-r--r-- | pkg/i18n/english.go | 6 | ||||
-rw-r--r-- | pkg/i18n/japanese.go | 3 | ||||
-rw-r--r-- | pkg/i18n/korean.go | 3 | ||||
-rw-r--r-- | pkg/i18n/polish.go | 2 |
17 files changed, 132 insertions, 7 deletions
diff --git a/docs/Config.md b/docs/Config.md index 87ed70eed..d0d90ea31 100644 --- a/docs/Config.md +++ b/docs/Config.md @@ -223,6 +223,7 @@ keybinding: viewBisectOptions: 'b' stash: popStash: 'g' + renameStash: 'r' commitFiles: checkoutCommitFile: 'c' main: diff --git a/docs/keybindings/Keybindings_en.md b/docs/keybindings/Keybindings_en.md index af5787dab..df42f5a62 100644 --- a/docs/keybindings/Keybindings_en.md +++ b/docs/keybindings/Keybindings_en.md @@ -238,6 +238,7 @@ _This file is auto-generated. To update, make the changes in the pkg/i18n direct <kbd>g</kbd>: pop <kbd>d</kbd>: drop <kbd>n</kbd>: new branch + <kbd>r</kbd>: rename stash <kbd>enter</kbd>: view selected item's files </pre> diff --git a/docs/keybindings/Keybindings_ja.md b/docs/keybindings/Keybindings_ja.md index d22f6d150..910b6938d 100644 --- a/docs/keybindings/Keybindings_ja.md +++ b/docs/keybindings/Keybindings_ja.md @@ -48,6 +48,7 @@ _This file is auto-generated. To update, make the changes in the pkg/i18n direct <kbd>g</kbd>: pop <kbd>d</kbd>: drop <kbd>n</kbd>: 新しいブランチを作成 + <kbd>r</kbd>: Stashを変更 <kbd>enter</kbd>: view selected item's files </pre> diff --git a/docs/keybindings/Keybindings_ko.md b/docs/keybindings/Keybindings_ko.md index 690cd5790..2edef93ff 100644 --- a/docs/keybindings/Keybindings_ko.md +++ b/docs/keybindings/Keybindings_ko.md @@ -63,6 +63,7 @@ _This file is auto-generated. To update, make the changes in the pkg/i18n direct <kbd>g</kbd>: pop <kbd>d</kbd>: drop <kbd>n</kbd>: 새 브랜치 생성 + <kbd>r</kbd>: rename stash <kbd>enter</kbd>: view selected item's files </pre> diff --git a/docs/keybindings/Keybindings_nl.md b/docs/keybindings/Keybindings_nl.md index 15484be73..06b96af5c 100644 --- a/docs/keybindings/Keybindings_nl.md +++ b/docs/keybindings/Keybindings_nl.md @@ -238,6 +238,7 @@ _This file is auto-generated. To update, make the changes in the pkg/i18n direct <kbd>g</kbd>: pop <kbd>d</kbd>: laten vallen <kbd>n</kbd>: nieuwe branch + <kbd>r</kbd>: rename stash <kbd>enter</kbd>: bekijk gecommite bestanden </pre> diff --git a/docs/keybindings/Keybindings_pl.md b/docs/keybindings/Keybindings_pl.md index 9cfc64294..a1ca9cfd2 100644 --- a/docs/keybindings/Keybindings_pl.md +++ b/docs/keybindings/Keybindings_pl.md @@ -231,6 +231,7 @@ _This file is auto-generated. To update, make the changes in the pkg/i18n direct <kbd>g</kbd>: wyciągnij <kbd>d</kbd>: porzuć <kbd>n</kbd>: nowa gałąź + <kbd>r</kbd>: rename stash <kbd>enter</kbd>: przeglądaj pliki commita </pre> diff --git a/docs/keybindings/Keybindings_zh.md b/docs/keybindings/Keybindings_zh.md index df1db2e55..98b180a52 100644 --- a/docs/keybindings/Keybindings_zh.md +++ b/docs/keybindings/Keybindings_zh.md @@ -264,6 +264,7 @@ _This file is auto-generated. To update, make the changes in the pkg/i18n direct <kbd>g</kbd>: 应用并删除 <kbd>d</kbd>: 删除 <kbd>n</kbd>: 新分支 + <kbd>r</kbd>: rename stash <kbd>enter</kbd>: 查看提交的文件 </pre> diff --git a/pkg/commands/git_commands/stash.go b/pkg/commands/git_commands/stash.go index c0d187a13..1a7c62b08 100644 --- a/pkg/commands/git_commands/stash.go +++ b/pkg/commands/git_commands/stash.go @@ -2,6 +2,7 @@ package git_commands import ( "fmt" + "strings" "github.com/jesseduffield/lazygit/pkg/commands/loaders" "github.com/jesseduffield/lazygit/pkg/commands/oscommands" @@ -29,8 +30,9 @@ func (self *StashCommands) DropNewest() error { return self.cmd.New("git stash drop").Run() } -func (self *StashCommands) Drop(index int) error { - return self.cmd.New(fmt.Sprintf("git stash drop stash@{%d}", index)).Run() +func (self *StashCommands) Drop(index int) (string, error) { + output, _, err := self.cmd.New(fmt.Sprintf("git stash drop stash@{%d}", index)).RunWithOutputs() + return output, err } func (self *StashCommands) Pop(index int) error { @@ -46,6 +48,14 @@ func (self *StashCommands) Save(message string) error { return self.cmd.New("git stash save " + self.cmd.Quote(message)).Run() } +func (self *StashCommands) Store(sha string, message string) error { + trimmedMessage := strings.Trim(message, " \t") + if len(trimmedMessage) > 0 { + return self.cmd.New(fmt.Sprintf("git stash store %s -m %s", self.cmd.Quote(sha), self.cmd.Quote(trimmedMessage))).Run() + } + return self.cmd.New(fmt.Sprintf("git stash store %s", self.cmd.Quote(sha))).Run() +} + func (self *StashCommands) ShowStashEntryCmdObj(index int) oscommands.ICmdObj { cmdStr := fmt.Sprintf("git stash show -p --stat --color=%s --unified=%d stash@{%d}", self.UserConfig.Git.Paging.ColorArg, self.UserConfig.Git.DiffContextSize, index) diff --git a/pkg/commands/git_commands/stash_test.go b/pkg/commands/git_commands/stash_test.go index b41f7815b..e5ce39181 100644 --- a/pkg/commands/git_commands/stash_test.go +++ b/pkg/commands/git_commands/stash_test.go @@ -10,10 +10,12 @@ import ( func TestStashDrop(t *testing.T) { runner := oscommands.NewFakeRunner(t). - ExpectGitArgs([]string{"stash", "drop", "stash@{1}"}, "", nil) + ExpectGitArgs([]string{"stash", "drop", "stash@{1}"}, "Dropped refs/stash@{1} (98e9cca532c37c766107093010c72e26f2c24c04)", nil) instance := buildStashCommands(commonDeps{runner: runner}) - assert.NoError(t, instance.Drop(1)) + output, err := instance.Drop(1) + assert.NoError(t, err) + assert.Equal(t, "Dropped refs/stash@{1} (98e9cca532c37c766107093010c72e26f2c24c04)", output) runner.CheckForMissingCalls() } @@ -44,6 +46,48 @@ func TestStashSave(t *testing.T) { runner.CheckForMissingCalls() } +func TestStashStore(t *testing.T) { + type scenario struct { + testName string + sha string + message string + expected []string + } + + scenarios := []scenario{ + { + testName: "Non-empty message", + sha: "0123456789abcdef", + message: "New stash name", + expected: []string{"stash", "store", "0123456789abcdef", "-m", "New stash name"}, + }, + { + testName: "Empty message", + sha: "0123456789abcdef", + message: "", + expected: []string{"stash", "store", "0123456789abcdef"}, + }, + { + testName: "Space message", + sha: "0123456789abcdef", + message: " ", + expected: []string{"stash", "store", "0123456789abcdef"}, + }, + } + + for _, s := range scenarios { + s := s + t.Run(s.testName, func(t *testing.T) { + runner := oscommands.NewFakeRunner(t). + ExpectGitArgs(s.expected, "", nil) + instance := buildStashCommands(commonDeps{runner: runner}) + + assert.NoError(t, instance.Store(s.sha, s.message)) + runner.CheckForMissingCalls() + }) + } +} + func TestStashStashEntryCmdObj(t *testing.T) { type scenario struct { testName string diff --git a/pkg/config/user_config.go b/pkg/config/user_config.go index f3ff1befb..a90b100d5 100644 --- a/pkg/config/user_config.go +++ b/pkg/config/user_config.go @@ -265,7 +265,8 @@ type KeybindingCommitsConfig struct { } type KeybindingStashConfig struct { - PopStash string `yaml:"popStash"` + PopStash string `yaml:"popStash"` + RenameStash string `yaml:"renameStash"` } type KeybindingCommitFilesConfig struct { @@ -547,7 +548,8 @@ func GetDefaultConfig() *UserConfig { ViewBisectOptions: "b", }, Stash: KeybindingStashConfig{ - PopStash: "g", + PopStash: "g", + RenameStash: "r", }, CommitFiles: KeybindingCommitFilesConfig{ CheckoutCommitFile: "c", diff --git a/pkg/gui/controllers/stash_controller.go b/pkg/gui/controllers/stash_controller.go index 6c8e7c349..6cd06c6d4 100644 --- a/pkg/gui/controllers/stash_controller.go +++ b/pkg/gui/controllers/stash_controller.go @@ -1,9 +1,12 @@ package controllers import ( + "regexp" + "github.com/jesseduffield/lazygit/pkg/commands/models" "github.com/jesseduffield/lazygit/pkg/gui/context" "github.com/jesseduffield/lazygit/pkg/gui/types" + "github.com/jesseduffield/lazygit/pkg/utils" ) type StashController struct { @@ -44,6 +47,11 @@ func (self *StashController) GetKeybindings(opts types.KeybindingsOpts) []*types Handler: self.checkSelected(self.handleNewBranchOffStashEntry), Description: self.c.Tr.LcNewBranch, }, + { + Key: opts.GetKey(opts.Config.Stash.RenameStash), + Handler: self.checkSelected(self.handleRenameStashEntry), + Description: self.c.Tr.LcRenameStash, + }, } return bindings @@ -122,7 +130,7 @@ func (self *StashController) handleStashDrop(stashEntry *models.StashEntry) erro Prompt: self.c.Tr.SureDropStashEntry, HandleConfirm: func() error { self.c.LogAction(self.c.Tr.Actions.Stash) - err := self.git.Stash.Drop(stashEntry.Index) + _, err := self.git.Stash.Drop(stashEntry.Index) _ = self.c.Refresh(types.RefreshOptions{Scope: []types.RefreshableView{types.STASH}}) if err != nil { return self.c.Error(err) @@ -139,3 +147,38 @@ func (self *StashController) postStashRefresh() error { func (self *StashController) handleNewBranchOffStashEntry(stashEntry *models.StashEntry) error { return self.helpers.Refs.NewBranch(stashEntry.RefName(), stashEntry.Description(), "") } + +func (self *StashController) handleRenameStashEntry(stashEntry *models.StashEntry) error { + message := utils.ResolvePlaceholderString( + self.c.Tr.RenameStashPrompt, + map[string]string{ + "stashName": stashEntry.RefName(), + }, + ) + + return self.c.Prompt(types.PromptOpts{ + Title: message, + InitialContent: stashEntry.Name, + HandleConfirm: func(response string) error { + self.c.LogAction(self.c.Tr.Actions.RenameStash) + output, err := self.git.Stash.Drop(stashEntry.Index) + if err != nil { + return err + } + + stashShaPattern := regexp.MustCompile(`\(([0-9a-f]+)\)`) + matches := stashShaPattern.FindStringSubmatch(output) + stashSha := "" + if len(matches) > 1 { + stashSha = matches[1] + } + + err = self.git.Stash.Store(stashSha, response) + _ = self.c.Refresh(types.RefreshOptions{Scope: []types.RefreshableView{types.STASH}}) + if err != nil { + return err + } + return nil + }, + }) +} diff --git a/pkg/i18n/chinese.go b/pkg/i18n/chinese.go index fb594a1a9..67cf264ce 100644 --- a/pkg/i18n/chinese.go +++ b/pkg/i18n/chinese.go @@ -139,6 +139,8 @@ func chineseTranslationSet() TranslationSet { SureApplyStashEntry: "您确定要应用此贮藏条目?", NoTrackedStagedFilesStash: "没有可以贮藏的已跟踪/暂存文件", StashChanges: "贮藏更改", + LcRenameStash: "rename stash", + RenameStashPrompt: "Rename stash: {{.stashName}}", OpenConfig: "打开配置文件", EditConfig: "编辑配置文件", ForcePush: "强制推送", @@ -530,6 +532,7 @@ func chineseTranslationSet() TranslationSet { UpdateRemote: "更新远程", ApplyPatch: "应用补丁", Stash: "贮藏 (Stash)", + RenameStash: "Rename stash", RemoveSubmodule: "删除子模块", ResetSubmodule: "重置子模块", AddSubmodule: "添加子模块", diff --git a/pkg/i18n/dutch.go b/pkg/i18n/dutch.go index 536793fc6..4436d653c 100644 --- a/pkg/i18n/dutch.go +++ b/pkg/i18n/dutch.go @@ -105,6 +105,8 @@ func dutchTranslationSet() TranslationSet { SureApplyStashEntry: "Weet je zeker dat je deze stash entry wil toepassen?", NoTrackedStagedFilesStash: "Je hebt geen tracked/staged bestanden om te laten stashen", StashChanges: "Stash veranderingen", + LcRenameStash: "rename stash", + RenameStashPrompt: "Rename stash: {{.stashName}}", NoChangedFiles: "Geen veranderde bestanden", OpenConfig: "open config bestand", EditConfig: "verander config bestand", diff --git a/pkg/i18n/english.go b/pkg/i18n/english.go index 08f737a51..75e121545 100644 --- a/pkg/i18n/english.go +++ b/pkg/i18n/english.go @@ -128,6 +128,8 @@ type TranslationSet struct { NoTrackedStagedFilesStash string NoFilesToStash string StashChanges string + LcRenameStash string + RenameStashPrompt string OpenConfig string EditConfig string ForcePush string @@ -601,6 +603,7 @@ type Actions struct { UpdateRemote string ApplyPatch string Stash string + RenameStash string RemoveSubmodule string ResetSubmodule string AddSubmodule string @@ -769,6 +772,8 @@ func EnglishTranslationSet() TranslationSet { NoTrackedStagedFilesStash: "You have no tracked/staged files to stash", NoFilesToStash: "You have no files to stash", StashChanges: "Stash changes", + LcRenameStash: "rename stash", + RenameStashPrompt: "Rename stash: {{.stashName}}", OpenConfig: "open config file", EditConfig: "edit config file", ForcePush: "Force push", @@ -1226,6 +1231,7 @@ func EnglishTranslationSet() TranslationSet { UpdateRemote: "Update remote", ApplyPatch: "Apply patch", Stash: "Stash", + RenameStash: "Rename stash", RemoveSubmodule: "Remove submodule", ResetSubmodule: "Reset submodule", AddSubmodule: "Add submodule", diff --git a/pkg/i18n/japanese.go b/pkg/i18n/japanese.go index 03d949549..bfdf492f8 100644 --- a/pkg/i18n/japanese.go +++ b/pkg/i18n/japanese.go @@ -130,6 +130,8 @@ func japaneseTranslationSet() TranslationSet { SureApplyStashEntry: "Stashを適用します。よろしいですか?", // NoTrackedStagedFilesStash: "You have no tracked/staged files to stash", StashChanges: "変更をStash", + LcRenameStash: "Stashを変更", + RenameStashPrompt: "Stash名を変更: {{.stashName}}", OpenConfig: "設定ファイルを開く", EditConfig: "設定ファイルを編集", ForcePush: "Force push", @@ -556,6 +558,7 @@ func japaneseTranslationSet() TranslationSet { UpdateRemote: "リモートを更新", ApplyPatch: "パッチを適用", Stash: "Stash", + RenameStash: "Stash名を変更", RemoveSubmodule: "サブモジュールを削除", ResetSubmodule: "サブモジュールをリセット", AddSubmodule: "サブモジュールを追加", diff --git a/pkg/i18n/korean.go b/pkg/i18n/korean.go index afda25c6d..573f22bdc 100644 --- a/pkg/i18n/korean.go +++ b/pkg/i18n/korean.go @@ -131,6 +131,8 @@ func koreanTranslationSet() TranslationSet { SureApplyStashEntry: "정말로 Stash를 적용하시겠습니까?", NoTrackedStagedFilesStash: "You have no tracked/staged files to stash", StashChanges: "변경을 Stash", + LcRenameStash: "rename stash", + RenameStashPrompt: "Rename stash: {{.stashName}}", OpenConfig: "설정 파일 열기", EditConfig: "설정 파일 수정", ForcePush: "강제 푸시", @@ -561,6 +563,7 @@ func koreanTranslationSet() TranslationSet { UpdateRemote: "Update remote", ApplyPatch: "Apply patch", Stash: "Stash", + RenameStash: "Rename stash", RemoveSubmodule: "서브모듈 삭제", ResetSubmodule: "서브모듈 Reset", AddSubmodule: "서브모듈 추가", diff --git a/pkg/i18n/polish.go b/pkg/i18n/polish.go index e82ddc2de..8bcc460e1 100644 --- a/pkg/i18n/polish.go +++ b/pkg/i18n/polish.go @@ -83,6 +83,8 @@ func polishTranslationSet() TranslationSet { SureDropStashEntry: "Jesteś pewny, że chcesz porzucić tę pozycję w schowku?", NoTrackedStagedFilesStash: "Nie masz śledzonych/zatwierdzonych plików do przechowania", StashChanges: "Przechowaj zmiany", + LcRenameStash: "rename stash", + RenameStashPrompt: "Rename stash: {{.stashName}}", OpenConfig: "otwórz konfigurację", EditConfig: "edytuj konfigurację", ForcePush: "Wymuś wysłanie", |