From 11316b7a488ff4afa9a60595fb866a94c4c17216 Mon Sep 17 00:00:00 2001 From: Ryooooooga Date: Fri, 14 Oct 2022 22:19:53 +0900 Subject: [PATCH 1/6] feat: add rename stash --- docs/Config.md | 1 + docs/keybindings/Keybindings_en.md | 1 + docs/keybindings/Keybindings_ja.md | 1 + docs/keybindings/Keybindings_ko.md | 1 + docs/keybindings/Keybindings_nl.md | 1 + docs/keybindings/Keybindings_pl.md | 1 + docs/keybindings/Keybindings_zh.md | 1 + pkg/commands/git_commands/stash.go | 14 ++++++-- pkg/commands/git_commands/stash_test.go | 48 +++++++++++++++++++++++-- pkg/config/user_config.go | 6 ++-- pkg/gui/controllers/stash_controller.go | 45 ++++++++++++++++++++++- pkg/i18n/chinese.go | 3 ++ pkg/i18n/dutch.go | 2 ++ pkg/i18n/english.go | 6 ++++ pkg/i18n/japanese.go | 3 ++ pkg/i18n/korean.go | 3 ++ 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 g: pop d: drop n: new branch + r: rename stash enter: view selected item's files 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 g: pop d: drop n: 新しいブランチを作成 + r: Stashを変更 enter: view selected item's files 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 g: pop d: drop n: 새 브랜치 생성 + r: rename stash enter: view selected item's files 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 g: pop d: laten vallen n: nieuwe branch + r: rename stash enter: bekijk gecommite bestanden 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 g: wyciągnij d: porzuć n: nowa gałąź + r: rename stash enter: przeglądaj pliki commita 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 g: 应用并删除 d: 删除 n: 新分支 + r: rename stash enter: 查看提交的文件 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", From 8a9eefa4d275f925e149be2c05c5c6958da86f5b Mon Sep 17 00:00:00 2001 From: Ryoga Date: Sat, 15 Oct 2022 11:03:47 +0900 Subject: [PATCH 2/6] chore: remove unnecessary space Co-authored-by: Jesse Duffield --- pkg/commands/git_commands/stash.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/commands/git_commands/stash.go b/pkg/commands/git_commands/stash.go index 1a7c62b08..841765e81 100644 --- a/pkg/commands/git_commands/stash.go +++ b/pkg/commands/git_commands/stash.go @@ -51,7 +51,7 @@ func (self *StashCommands) Save(message string) error { 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 -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() } From eceb3a5aa6de864f31c52016e6fd497b9b6a1214 Mon Sep 17 00:00:00 2001 From: Ryooooooga Date: Sat, 15 Oct 2022 11:15:31 +0900 Subject: [PATCH 3/6] chore: refactor rename stash --- pkg/commands/git_commands/stash.go | 25 ++++++++++++++ pkg/commands/git_commands/stash_test.go | 43 +++++++++++++++++++++++++ pkg/gui/controllers/stash_controller.go | 17 ++-------- 3 files changed, 70 insertions(+), 15 deletions(-) diff --git a/pkg/commands/git_commands/stash.go b/pkg/commands/git_commands/stash.go index 841765e81..176a67e52 100644 --- a/pkg/commands/git_commands/stash.go +++ b/pkg/commands/git_commands/stash.go @@ -1,7 +1,9 @@ package git_commands import ( + "errors" "fmt" + "regexp" "strings" "github.com/jesseduffield/lazygit/pkg/commands/loaders" @@ -119,3 +121,26 @@ func (self *StashCommands) SaveStagedChanges(message string) error { return nil } + +func (self *StashCommands) Rename(index int, message string) error { + output, err := self.Drop(index) + if err != nil { + return err + } + + // `output` is in the following format: + // Dropped refs/stash@{0} (f0d0f20f2f61ffd6d6bfe0752deffa38845a3edd) + stashShaPattern := regexp.MustCompile(`\(([0-9a-f]+)\)`) + matches := stashShaPattern.FindStringSubmatch(output) + if len(matches) <= 1 { + return errors.New("Output of `git stash drop` is invalid") // Usually this error does not occur + } + stashSha := matches[1] + + err = self.Store(stashSha, message) + if err != nil { + return err + } + + return nil +} diff --git a/pkg/commands/git_commands/stash_test.go b/pkg/commands/git_commands/stash_test.go index e5ce39181..41efc07db 100644 --- a/pkg/commands/git_commands/stash_test.go +++ b/pkg/commands/git_commands/stash_test.go @@ -123,3 +123,46 @@ func TestStashStashEntryCmdObj(t *testing.T) { }) } } + +func TestStashRename(t *testing.T) { + type scenario struct { + testName string + index int + message string + expectedDropCmd []string + dropResult string + expectedStoreCmd []string + } + + scenarios := []scenario{ + { + testName: "Default case", + index: 3, + message: "New message", + expectedDropCmd: []string{"stash", "drop", "stash@{3}"}, + dropResult: "Dropped refs/stash@{3} (f0d0f20f2f61ffd6d6bfe0752deffa38845a3edd)\n", + expectedStoreCmd: []string{"stash", "store", "f0d0f20f2f61ffd6d6bfe0752deffa38845a3edd", "-m", "New message"}, + }, + { + testName: "Empty message", + index: 4, + message: "", + expectedDropCmd: []string{"stash", "drop", "stash@{4}"}, + dropResult: "Dropped refs/stash@{4} (f0d0f20f2f61ffd6d6bfe0752deffa38845a3edd)\n", + expectedStoreCmd: []string{"stash", "store", "f0d0f20f2f61ffd6d6bfe0752deffa38845a3edd"}, + }, + } + + for _, s := range scenarios { + s := s + t.Run(s.testName, func(t *testing.T) { + runner := oscommands.NewFakeRunner(t). + ExpectGitArgs(s.expectedDropCmd, s.dropResult, nil). + ExpectGitArgs(s.expectedStoreCmd, "", nil) + instance := buildStashCommands(commonDeps{runner: runner}) + + err := instance.Rename(s.index, s.message) + assert.NoError(t, err) + }) + } +} diff --git a/pkg/gui/controllers/stash_controller.go b/pkg/gui/controllers/stash_controller.go index 6cd06c6d4..1e4137777 100644 --- a/pkg/gui/controllers/stash_controller.go +++ b/pkg/gui/controllers/stash_controller.go @@ -1,8 +1,6 @@ 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" @@ -161,23 +159,12 @@ func (self *StashController) handleRenameStashEntry(stashEntry *models.StashEntr 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) + err := self.git.Stash.Rename(stashEntry.Index, response) _ = self.c.Refresh(types.RefreshOptions{Scope: []types.RefreshableView{types.STASH}}) if err != nil { return err } + self.context().SetSelectedLineIdx(0) // Select the renamed stash return nil }, }) From e78e829e3a8940f5b7b8f0bfc77b3316d19e1e8b Mon Sep 17 00:00:00 2001 From: Ryooooooga Date: Sat, 15 Oct 2022 11:57:19 +0900 Subject: [PATCH 4/6] test: add an integration test for rename stash --- pkg/integration/components/shell.go | 5 +++ pkg/integration/tests/stash/rename.go | 33 ++++++++++++++++++ pkg/integration/tests/tests.go | 2 ++ .../expected/repo/.git_keep/COMMIT_EDITMSG | 1 + .../rename/expected/repo/.git_keep/FETCH_HEAD | 0 .../stash/rename/expected/repo/.git_keep/HEAD | 1 + .../rename/expected/repo/.git_keep/ORIG_HEAD | 1 + .../repo/.git_keep/commit-template.txt | 0 .../rename/expected/repo/.git_keep/config | 12 +++++++ .../expected/repo/.git_keep/description | 1 + .../rename/expected/repo/.git_keep/index | Bin 0 -> 65 bytes .../expected/repo/.git_keep/info/exclude | 0 .../rename/expected/repo/.git_keep/logs/HEAD | 2 ++ .../repo/.git_keep/logs/refs/heads/master | 1 + .../expected/repo/.git_keep/logs/refs/stash | 1 + .../25/0122ffb92a8c1c2a6554ce2ac84b49e5f3afe3 | Bin 0 -> 31 bytes .../4b/825dc642cb6eb9a060e54bf8d69288fbee4904 | Bin 0 -> 15 bytes .../4d/ff185ecddfb638f76215fa07adde0f4e97da7c | 2 ++ .../8d/4897b3dcbb5c8fbc8fa8439ec7e9627c3159cf | 2 ++ .../c6/f35659c0cf57c794d79df88283d7ee933831dd | Bin 0 -> 181 bytes .../fc/66bff0a9fdfe660b6e490dc217a9c26ffc5fff | Bin 0 -> 48 bytes .../expected/repo/.git_keep/refs/heads/master | 1 + .../rename/expected/repo/.git_keep/refs/stash | 1 + 23 files changed, 66 insertions(+) create mode 100644 pkg/integration/tests/stash/rename.go create mode 100644 test/integration_new/stash/rename/expected/repo/.git_keep/COMMIT_EDITMSG create mode 100644 test/integration_new/stash/rename/expected/repo/.git_keep/FETCH_HEAD create mode 100644 test/integration_new/stash/rename/expected/repo/.git_keep/HEAD create mode 100644 test/integration_new/stash/rename/expected/repo/.git_keep/ORIG_HEAD create mode 100644 test/integration_new/stash/rename/expected/repo/.git_keep/commit-template.txt create mode 100644 test/integration_new/stash/rename/expected/repo/.git_keep/config create mode 100644 test/integration_new/stash/rename/expected/repo/.git_keep/description create mode 100644 test/integration_new/stash/rename/expected/repo/.git_keep/index create mode 100644 test/integration_new/stash/rename/expected/repo/.git_keep/info/exclude create mode 100644 test/integration_new/stash/rename/expected/repo/.git_keep/logs/HEAD create mode 100644 test/integration_new/stash/rename/expected/repo/.git_keep/logs/refs/heads/master create mode 100644 test/integration_new/stash/rename/expected/repo/.git_keep/logs/refs/stash create mode 100644 test/integration_new/stash/rename/expected/repo/.git_keep/objects/25/0122ffb92a8c1c2a6554ce2ac84b49e5f3afe3 create mode 100644 test/integration_new/stash/rename/expected/repo/.git_keep/objects/4b/825dc642cb6eb9a060e54bf8d69288fbee4904 create mode 100644 test/integration_new/stash/rename/expected/repo/.git_keep/objects/4d/ff185ecddfb638f76215fa07adde0f4e97da7c create mode 100644 test/integration_new/stash/rename/expected/repo/.git_keep/objects/8d/4897b3dcbb5c8fbc8fa8439ec7e9627c3159cf create mode 100644 test/integration_new/stash/rename/expected/repo/.git_keep/objects/c6/f35659c0cf57c794d79df88283d7ee933831dd create mode 100644 test/integration_new/stash/rename/expected/repo/.git_keep/objects/fc/66bff0a9fdfe660b6e490dc217a9c26ffc5fff create mode 100644 test/integration_new/stash/rename/expected/repo/.git_keep/refs/heads/master create mode 100644 test/integration_new/stash/rename/expected/repo/.git_keep/refs/stash diff --git a/pkg/integration/components/shell.go b/pkg/integration/components/shell.go index 5f7fef350..1d8182edb 100644 --- a/pkg/integration/components/shell.go +++ b/pkg/integration/components/shell.go @@ -111,3 +111,8 @@ func (s *Shell) CreateNCommits(n int) *Shell { return s } + +func (s *Shell) StashWithMessage(message string) *Shell { + s.RunCommand(fmt.Sprintf(`git stash -m "%s"`, message)) + return s +} diff --git a/pkg/integration/tests/stash/rename.go b/pkg/integration/tests/stash/rename.go new file mode 100644 index 000000000..97cfae006 --- /dev/null +++ b/pkg/integration/tests/stash/rename.go @@ -0,0 +1,33 @@ +package stash + +import ( + "github.com/jesseduffield/lazygit/pkg/config" + . "github.com/jesseduffield/lazygit/pkg/integration/components" +) + +var Rename = NewIntegrationTest(NewIntegrationTestArgs{ + Description: "Try to rename the stash.", + ExtraCmdArgs: "", + Skip: false, + SetupConfig: func(config *config.AppConfig) {}, + SetupRepo: func(shell *Shell) { + shell. + EmptyCommit("blah"). + CreateFileAndAdd("foo", "change to stash"). + StashWithMessage("bar") + }, + Run: func(shell *Shell, input *Input, assert *Assert, keys config.KeybindingConfig) { + input.SwitchToStashWindow() + assert.CurrentViewName("stash") + + assert.MatchSelectedLine(Equals("On master: bar")) + input.PressKeys(keys.Stash.RenameStash) + assert.InPrompt() + assert.MatchCurrentViewTitle(Equals("Rename stash: stash@{0}")) + + input.Type(" baz") + input.Confirm() + + assert.MatchSelectedLine(Equals("On master: bar baz")) + }, +}) diff --git a/pkg/integration/tests/tests.go b/pkg/integration/tests/tests.go index 21f06a376..6b4583e6d 100644 --- a/pkg/integration/tests/tests.go +++ b/pkg/integration/tests/tests.go @@ -16,6 +16,7 @@ import ( "github.com/jesseduffield/lazygit/pkg/integration/tests/commit" "github.com/jesseduffield/lazygit/pkg/integration/tests/custom_commands" "github.com/jesseduffield/lazygit/pkg/integration/tests/interactive_rebase" + "github.com/jesseduffield/lazygit/pkg/integration/tests/stash" ) // Here is where we lists the actual tests that will run. When you create a new test, @@ -38,6 +39,7 @@ var tests = []*components.IntegrationTest{ cherry_pick.CherryPick, cherry_pick.CherryPickConflicts, custom_commands.FormPrompts, + stash.Rename, } func GetTests() []*components.IntegrationTest { diff --git a/test/integration_new/stash/rename/expected/repo/.git_keep/COMMIT_EDITMSG b/test/integration_new/stash/rename/expected/repo/.git_keep/COMMIT_EDITMSG new file mode 100644 index 000000000..907b30816 --- /dev/null +++ b/test/integration_new/stash/rename/expected/repo/.git_keep/COMMIT_EDITMSG @@ -0,0 +1 @@ +blah diff --git a/test/integration_new/stash/rename/expected/repo/.git_keep/FETCH_HEAD b/test/integration_new/stash/rename/expected/repo/.git_keep/FETCH_HEAD new file mode 100644 index 000000000..e69de29bb diff --git a/test/integration_new/stash/rename/expected/repo/.git_keep/HEAD b/test/integration_new/stash/rename/expected/repo/.git_keep/HEAD new file mode 100644 index 000000000..cb089cd89 --- /dev/null +++ b/test/integration_new/stash/rename/expected/repo/.git_keep/HEAD @@ -0,0 +1 @@ +ref: refs/heads/master diff --git a/test/integration_new/stash/rename/expected/repo/.git_keep/ORIG_HEAD b/test/integration_new/stash/rename/expected/repo/.git_keep/ORIG_HEAD new file mode 100644 index 000000000..4db7189cb --- /dev/null +++ b/test/integration_new/stash/rename/expected/repo/.git_keep/ORIG_HEAD @@ -0,0 +1 @@ +8d4897b3dcbb5c8fbc8fa8439ec7e9627c3159cf diff --git a/test/integration_new/stash/rename/expected/repo/.git_keep/commit-template.txt b/test/integration_new/stash/rename/expected/repo/.git_keep/commit-template.txt new file mode 100644 index 000000000..e69de29bb diff --git a/test/integration_new/stash/rename/expected/repo/.git_keep/config b/test/integration_new/stash/rename/expected/repo/.git_keep/config new file mode 100644 index 000000000..8a748ce32 --- /dev/null +++ b/test/integration_new/stash/rename/expected/repo/.git_keep/config @@ -0,0 +1,12 @@ +[core] + repositoryformatversion = 0 + filemode = true + bare = false + logallrefupdates = true + ignorecase = true + precomposeunicode = true +[user] + email = CI@example.com + name = CI +[commit] + gpgSign = false diff --git a/test/integration_new/stash/rename/expected/repo/.git_keep/description b/test/integration_new/stash/rename/expected/repo/.git_keep/description new file mode 100644 index 000000000..498b267a8 --- /dev/null +++ b/test/integration_new/stash/rename/expected/repo/.git_keep/description @@ -0,0 +1 @@ +Unnamed repository; edit this file 'description' to name the repository. diff --git a/test/integration_new/stash/rename/expected/repo/.git_keep/index b/test/integration_new/stash/rename/expected/repo/.git_keep/index new file mode 100644 index 0000000000000000000000000000000000000000..65d675154f23ffb2d0196e017d44a5e7017550f5 GIT binary patch literal 65 zcmZ?q402{*U|<4bhL9jvS0E+HV4z^Y<=qr}%;|LA&IJiiy? 1665802395 +0900 commit (initial): blah +8d4897b3dcbb5c8fbc8fa8439ec7e9627c3159cf 8d4897b3dcbb5c8fbc8fa8439ec7e9627c3159cf CI 1665802396 +0900 reset: moving to HEAD diff --git a/test/integration_new/stash/rename/expected/repo/.git_keep/logs/refs/heads/master b/test/integration_new/stash/rename/expected/repo/.git_keep/logs/refs/heads/master new file mode 100644 index 000000000..698928dd3 --- /dev/null +++ b/test/integration_new/stash/rename/expected/repo/.git_keep/logs/refs/heads/master @@ -0,0 +1 @@ +0000000000000000000000000000000000000000 8d4897b3dcbb5c8fbc8fa8439ec7e9627c3159cf CI 1665802395 +0900 commit (initial): blah diff --git a/test/integration_new/stash/rename/expected/repo/.git_keep/logs/refs/stash b/test/integration_new/stash/rename/expected/repo/.git_keep/logs/refs/stash new file mode 100644 index 000000000..02b7af510 --- /dev/null +++ b/test/integration_new/stash/rename/expected/repo/.git_keep/logs/refs/stash @@ -0,0 +1 @@ +0000000000000000000000000000000000000000 c6f35659c0cf57c794d79df88283d7ee933831dd CI 1665802399 +0900 On master: bar baz diff --git a/test/integration_new/stash/rename/expected/repo/.git_keep/objects/25/0122ffb92a8c1c2a6554ce2ac84b49e5f3afe3 b/test/integration_new/stash/rename/expected/repo/.git_keep/objects/25/0122ffb92a8c1c2a6554ce2ac84b49e5f3afe3 new file mode 100644 index 0000000000000000000000000000000000000000..2a62b4b9d117b02f668e94e9d15e38d53e04515e GIT binary patch literal 31 ncmbe\wxKYn'T&%k͹QEʹ$9`] a4_C^ \ No newline at end of file diff --git a/test/integration_new/stash/rename/expected/repo/.git_keep/objects/8d/4897b3dcbb5c8fbc8fa8439ec7e9627c3159cf b/test/integration_new/stash/rename/expected/repo/.git_keep/objects/8d/4897b3dcbb5c8fbc8fa8439ec7e9627c3159cf new file mode 100644 index 000000000..98e81aa49 --- /dev/null +++ b/test/integration_new/stash/rename/expected/repo/.git_keep/objects/8d/4897b3dcbb5c8fbc8fa8439ec7e9627c3159cf @@ -0,0 +1,2 @@ +x +0 a}ɺ4$ "h +Qw烿Z_/p2i)LiFFOd,Qd5wR?}kL3ܧ\߻J`51t~?+ \ No newline at end of file diff --git a/test/integration_new/stash/rename/expected/repo/.git_keep/objects/c6/f35659c0cf57c794d79df88283d7ee933831dd b/test/integration_new/stash/rename/expected/repo/.git_keep/objects/c6/f35659c0cf57c794d79df88283d7ee933831dd new file mode 100644 index 0000000000000000000000000000000000000000..0eda983672af0f73b4c2736daef7cb465e6ca4f0 GIT binary patch literal 181 zcmV;m080OO0gcbQY6CG4h2hlu6zT&;*OA5q6L96q&oG(`2}EAAks*(ttz5e}&Ck~y zUdQ;JF6Q<&H&tg0(9Jxdi79~Zpc%bz43&^0m~k<) Date: Sun, 16 Oct 2022 09:11:54 +0900 Subject: [PATCH 5/6] chore: refactor rename stash --- pkg/commands/git_commands/stash.go | 25 ++++++++++----------- pkg/commands/git_commands/stash_test.go | 29 ++++++++++++++++++------- pkg/gui/controllers/stash_controller.go | 2 +- 3 files changed, 33 insertions(+), 23 deletions(-) diff --git a/pkg/commands/git_commands/stash.go b/pkg/commands/git_commands/stash.go index 176a67e52..9c7321b50 100644 --- a/pkg/commands/git_commands/stash.go +++ b/pkg/commands/git_commands/stash.go @@ -1,9 +1,7 @@ package git_commands import ( - "errors" "fmt" - "regexp" "strings" "github.com/jesseduffield/lazygit/pkg/commands/loaders" @@ -32,9 +30,8 @@ func (self *StashCommands) DropNewest() error { return self.cmd.New("git stash drop").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) Drop(index int) error { + return self.cmd.New(fmt.Sprintf("git stash drop stash@{%d}", index)).Run() } func (self *StashCommands) Pop(index int) error { @@ -58,6 +55,11 @@ func (self *StashCommands) Store(sha string, message string) error { return self.cmd.New(fmt.Sprintf("git stash store %s", self.cmd.Quote(sha))).Run() } +func (self *StashCommands) Sha(index int) (string, error) { + sha, _, err := self.cmd.New(fmt.Sprintf("git rev-parse refs/stash@{%d}", index)).DontLog().RunWithOutputs() + return strings.Trim(sha, "\r\n"), err +} + 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) @@ -123,21 +125,16 @@ func (self *StashCommands) SaveStagedChanges(message string) error { } func (self *StashCommands) Rename(index int, message string) error { - output, err := self.Drop(index) + sha, err := self.Sha(index) if err != nil { return err } - // `output` is in the following format: - // Dropped refs/stash@{0} (f0d0f20f2f61ffd6d6bfe0752deffa38845a3edd) - stashShaPattern := regexp.MustCompile(`\(([0-9a-f]+)\)`) - matches := stashShaPattern.FindStringSubmatch(output) - if len(matches) <= 1 { - return errors.New("Output of `git stash drop` is invalid") // Usually this error does not occur + if err := self.Drop(index); err != nil { + return err } - stashSha := matches[1] - err = self.Store(stashSha, message) + err = self.Store(sha, message) if err != nil { return err } diff --git a/pkg/commands/git_commands/stash_test.go b/pkg/commands/git_commands/stash_test.go index 41efc07db..1a4e50822 100644 --- a/pkg/commands/git_commands/stash_test.go +++ b/pkg/commands/git_commands/stash_test.go @@ -10,12 +10,10 @@ import ( func TestStashDrop(t *testing.T) { runner := oscommands.NewFakeRunner(t). - ExpectGitArgs([]string{"stash", "drop", "stash@{1}"}, "Dropped refs/stash@{1} (98e9cca532c37c766107093010c72e26f2c24c04)", nil) + ExpectGitArgs([]string{"stash", "drop", "stash@{1}"}, "Dropped refs/stash@{1} (98e9cca532c37c766107093010c72e26f2c24c04)\n", nil) instance := buildStashCommands(commonDeps{runner: runner}) - output, err := instance.Drop(1) - assert.NoError(t, err) - assert.Equal(t, "Dropped refs/stash@{1} (98e9cca532c37c766107093010c72e26f2c24c04)", output) + assert.NoError(t, instance.Drop(1)) runner.CheckForMissingCalls() } @@ -88,6 +86,17 @@ func TestStashStore(t *testing.T) { } } +func TestStashSha(t *testing.T) { + runner := oscommands.NewFakeRunner(t). + ExpectGitArgs([]string{"rev-parse", "refs/stash@{5}"}, "14d94495194651adfd5f070590df566c11d28243\n", nil) + instance := buildStashCommands(commonDeps{runner: runner}) + + sha, err := instance.Sha(5) + assert.NoError(t, err) + assert.Equal(t, "14d94495194651adfd5f070590df566c11d28243", sha) + runner.CheckForMissingCalls() +} + func TestStashStashEntryCmdObj(t *testing.T) { type scenario struct { testName string @@ -129,8 +138,9 @@ func TestStashRename(t *testing.T) { testName string index int message string + expectedShaCmd []string + shaResult string expectedDropCmd []string - dropResult string expectedStoreCmd []string } @@ -139,16 +149,18 @@ func TestStashRename(t *testing.T) { testName: "Default case", index: 3, message: "New message", + expectedShaCmd: []string{"rev-parse", "refs/stash@{3}"}, + shaResult: "f0d0f20f2f61ffd6d6bfe0752deffa38845a3edd\n", expectedDropCmd: []string{"stash", "drop", "stash@{3}"}, - dropResult: "Dropped refs/stash@{3} (f0d0f20f2f61ffd6d6bfe0752deffa38845a3edd)\n", expectedStoreCmd: []string{"stash", "store", "f0d0f20f2f61ffd6d6bfe0752deffa38845a3edd", "-m", "New message"}, }, { testName: "Empty message", index: 4, message: "", + expectedShaCmd: []string{"rev-parse", "refs/stash@{4}"}, + shaResult: "f0d0f20f2f61ffd6d6bfe0752deffa38845a3edd\n", expectedDropCmd: []string{"stash", "drop", "stash@{4}"}, - dropResult: "Dropped refs/stash@{4} (f0d0f20f2f61ffd6d6bfe0752deffa38845a3edd)\n", expectedStoreCmd: []string{"stash", "store", "f0d0f20f2f61ffd6d6bfe0752deffa38845a3edd"}, }, } @@ -157,7 +169,8 @@ func TestStashRename(t *testing.T) { s := s t.Run(s.testName, func(t *testing.T) { runner := oscommands.NewFakeRunner(t). - ExpectGitArgs(s.expectedDropCmd, s.dropResult, nil). + ExpectGitArgs(s.expectedShaCmd, s.shaResult, nil). + ExpectGitArgs(s.expectedDropCmd, "", nil). ExpectGitArgs(s.expectedStoreCmd, "", nil) instance := buildStashCommands(commonDeps{runner: runner}) diff --git a/pkg/gui/controllers/stash_controller.go b/pkg/gui/controllers/stash_controller.go index 1e4137777..68a121931 100644 --- a/pkg/gui/controllers/stash_controller.go +++ b/pkg/gui/controllers/stash_controller.go @@ -128,7 +128,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) From 2ec0b671e660b8a7d505a7ffb24a171cea6d8dde Mon Sep 17 00:00:00 2001 From: Ryooooooga Date: Sun, 16 Oct 2022 16:26:01 +0900 Subject: [PATCH 6/6] test: update stash/rename integration test --- pkg/integration/tests/stash/rename.go | 10 +++++++--- .../rename/expected/repo/.git_keep/ORIG_HEAD | 2 +- .../rename/expected/repo/.git_keep/logs/HEAD | 5 +++-- .../repo/.git_keep/logs/refs/heads/master | 2 +- .../expected/repo/.git_keep/logs/refs/stash | 3 ++- .../20/9b9fa9264fa15f128127817f080fd7372050cf | 3 +++ .../25/0122ffb92a8c1c2a6554ce2ac84b49e5f3afe3 | Bin 31 -> 0 bytes .../43/a4e12864cee1d7020a6d22772f0be34a24d257 | Bin 0 -> 162 bytes .../4d/ff185ecddfb638f76215fa07adde0f4e97da7c | 2 -- .../65/d11c8b2d3c173850f337661c9bf264d0406cf1 | 4 ++++ .../71/2f414b554b56ba82d43e1f7a0fe33be7eecc95 | Bin 0 -> 32 bytes .../86/8a798775e91d6387f351add6c5abf06cdb3357 | Bin 0 -> 51 bytes .../8d/4897b3dcbb5c8fbc8fa8439ec7e9627c3159cf | 2 -- .../a5/272a200897df5558c8cad683c1af14f7184124 | 3 +++ .../b2/3d362d3fa47c3b1f29c4dd41c419326415122c | Bin 0 -> 51 bytes .../c6/f35659c0cf57c794d79df88283d7ee933831dd | Bin 181 -> 0 bytes .../dc/052e9e4df6fe8f66b7e110466e1db8ce104b8b | Bin 0 -> 32 bytes .../de/8f5ed6f8a58664edfbdecd20b75a6ea0633bf6 | 1 + .../fc/66bff0a9fdfe660b6e490dc217a9c26ffc5fff | Bin 48 -> 0 bytes .../expected/repo/.git_keep/refs/heads/master | 2 +- .../rename/expected/repo/.git_keep/refs/stash | 2 +- 21 files changed, 27 insertions(+), 14 deletions(-) create mode 100644 test/integration_new/stash/rename/expected/repo/.git_keep/objects/20/9b9fa9264fa15f128127817f080fd7372050cf delete mode 100644 test/integration_new/stash/rename/expected/repo/.git_keep/objects/25/0122ffb92a8c1c2a6554ce2ac84b49e5f3afe3 create mode 100644 test/integration_new/stash/rename/expected/repo/.git_keep/objects/43/a4e12864cee1d7020a6d22772f0be34a24d257 delete mode 100644 test/integration_new/stash/rename/expected/repo/.git_keep/objects/4d/ff185ecddfb638f76215fa07adde0f4e97da7c create mode 100644 test/integration_new/stash/rename/expected/repo/.git_keep/objects/65/d11c8b2d3c173850f337661c9bf264d0406cf1 create mode 100644 test/integration_new/stash/rename/expected/repo/.git_keep/objects/71/2f414b554b56ba82d43e1f7a0fe33be7eecc95 create mode 100644 test/integration_new/stash/rename/expected/repo/.git_keep/objects/86/8a798775e91d6387f351add6c5abf06cdb3357 delete mode 100644 test/integration_new/stash/rename/expected/repo/.git_keep/objects/8d/4897b3dcbb5c8fbc8fa8439ec7e9627c3159cf create mode 100644 test/integration_new/stash/rename/expected/repo/.git_keep/objects/a5/272a200897df5558c8cad683c1af14f7184124 create mode 100644 test/integration_new/stash/rename/expected/repo/.git_keep/objects/b2/3d362d3fa47c3b1f29c4dd41c419326415122c delete mode 100644 test/integration_new/stash/rename/expected/repo/.git_keep/objects/c6/f35659c0cf57c794d79df88283d7ee933831dd create mode 100644 test/integration_new/stash/rename/expected/repo/.git_keep/objects/dc/052e9e4df6fe8f66b7e110466e1db8ce104b8b create mode 100644 test/integration_new/stash/rename/expected/repo/.git_keep/objects/de/8f5ed6f8a58664edfbdecd20b75a6ea0633bf6 delete mode 100644 test/integration_new/stash/rename/expected/repo/.git_keep/objects/fc/66bff0a9fdfe660b6e490dc217a9c26ffc5fff diff --git a/pkg/integration/tests/stash/rename.go b/pkg/integration/tests/stash/rename.go index 97cfae006..761d7135b 100644 --- a/pkg/integration/tests/stash/rename.go +++ b/pkg/integration/tests/stash/rename.go @@ -13,7 +13,9 @@ var Rename = NewIntegrationTest(NewIntegrationTestArgs{ SetupRepo: func(shell *Shell) { shell. EmptyCommit("blah"). - CreateFileAndAdd("foo", "change to stash"). + CreateFileAndAdd("file-1", "change to stash1"). + StashWithMessage("foo"). + CreateFileAndAdd("file-2", "change to stash2"). StashWithMessage("bar") }, Run: func(shell *Shell, input *Input, assert *Assert, keys config.KeybindingConfig) { @@ -21,13 +23,15 @@ var Rename = NewIntegrationTest(NewIntegrationTestArgs{ assert.CurrentViewName("stash") assert.MatchSelectedLine(Equals("On master: bar")) + input.NextItem() + assert.MatchSelectedLine(Equals("On master: foo")) input.PressKeys(keys.Stash.RenameStash) assert.InPrompt() - assert.MatchCurrentViewTitle(Equals("Rename stash: stash@{0}")) + assert.MatchCurrentViewTitle(Equals("Rename stash: stash@{1}")) input.Type(" baz") input.Confirm() - assert.MatchSelectedLine(Equals("On master: bar baz")) + assert.MatchSelectedLine(Equals("On master: foo baz")) }, }) diff --git a/test/integration_new/stash/rename/expected/repo/.git_keep/ORIG_HEAD b/test/integration_new/stash/rename/expected/repo/.git_keep/ORIG_HEAD index 4db7189cb..6d340468f 100644 --- a/test/integration_new/stash/rename/expected/repo/.git_keep/ORIG_HEAD +++ b/test/integration_new/stash/rename/expected/repo/.git_keep/ORIG_HEAD @@ -1 +1 @@ -8d4897b3dcbb5c8fbc8fa8439ec7e9627c3159cf +209b9fa9264fa15f128127817f080fd7372050cf diff --git a/test/integration_new/stash/rename/expected/repo/.git_keep/logs/HEAD b/test/integration_new/stash/rename/expected/repo/.git_keep/logs/HEAD index bca9be914..93b01e488 100644 --- a/test/integration_new/stash/rename/expected/repo/.git_keep/logs/HEAD +++ b/test/integration_new/stash/rename/expected/repo/.git_keep/logs/HEAD @@ -1,2 +1,3 @@ -0000000000000000000000000000000000000000 8d4897b3dcbb5c8fbc8fa8439ec7e9627c3159cf CI 1665802395 +0900 commit (initial): blah -8d4897b3dcbb5c8fbc8fa8439ec7e9627c3159cf 8d4897b3dcbb5c8fbc8fa8439ec7e9627c3159cf CI 1665802396 +0900 reset: moving to HEAD +0000000000000000000000000000000000000000 209b9fa9264fa15f128127817f080fd7372050cf CI 1665905121 +0900 commit (initial): blah +209b9fa9264fa15f128127817f080fd7372050cf 209b9fa9264fa15f128127817f080fd7372050cf CI 1665905122 +0900 reset: moving to HEAD +209b9fa9264fa15f128127817f080fd7372050cf 209b9fa9264fa15f128127817f080fd7372050cf CI 1665905122 +0900 reset: moving to HEAD diff --git a/test/integration_new/stash/rename/expected/repo/.git_keep/logs/refs/heads/master b/test/integration_new/stash/rename/expected/repo/.git_keep/logs/refs/heads/master index 698928dd3..f1bfb4ca0 100644 --- a/test/integration_new/stash/rename/expected/repo/.git_keep/logs/refs/heads/master +++ b/test/integration_new/stash/rename/expected/repo/.git_keep/logs/refs/heads/master @@ -1 +1 @@ -0000000000000000000000000000000000000000 8d4897b3dcbb5c8fbc8fa8439ec7e9627c3159cf CI 1665802395 +0900 commit (initial): blah +0000000000000000000000000000000000000000 209b9fa9264fa15f128127817f080fd7372050cf CI 1665905121 +0900 commit (initial): blah diff --git a/test/integration_new/stash/rename/expected/repo/.git_keep/logs/refs/stash b/test/integration_new/stash/rename/expected/repo/.git_keep/logs/refs/stash index 02b7af510..5addb2d25 100644 --- a/test/integration_new/stash/rename/expected/repo/.git_keep/logs/refs/stash +++ b/test/integration_new/stash/rename/expected/repo/.git_keep/logs/refs/stash @@ -1 +1,2 @@ -0000000000000000000000000000000000000000 c6f35659c0cf57c794d79df88283d7ee933831dd CI 1665802399 +0900 On master: bar baz +0000000000000000000000000000000000000000 a5272a200897df5558c8cad683c1af14f7184124 CI 1665905122 +0900 On master: bar +a5272a200897df5558c8cad683c1af14f7184124 de8f5ed6f8a58664edfbdecd20b75a6ea0633bf6 CI 1665905125 +0900 On master: foo baz diff --git a/test/integration_new/stash/rename/expected/repo/.git_keep/objects/20/9b9fa9264fa15f128127817f080fd7372050cf b/test/integration_new/stash/rename/expected/repo/.git_keep/objects/20/9b9fa9264fa15f128127817f080fd7372050cf new file mode 100644 index 000000000..b0b57c478 --- /dev/null +++ b/test/integration_new/stash/rename/expected/repo/.git_keep/objects/20/9b9fa9264fa15f128127817f080fd7372050cf @@ -0,0 +1,3 @@ +x1 +0 @>B]YXPB Sa9 +)ĸz]?~i;xza)ĥ0l*-ia )jFoi4ۣ:gwDwkOtϛ;+ \ No newline at end of file diff --git a/test/integration_new/stash/rename/expected/repo/.git_keep/objects/25/0122ffb92a8c1c2a6554ce2ac84b49e5f3afe3 b/test/integration_new/stash/rename/expected/repo/.git_keep/objects/25/0122ffb92a8c1c2a6554ce2ac84b49e5f3afe3 deleted file mode 100644 index 2a62b4b9d117b02f668e94e9d15e38d53e04515e..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 31 ncmbwEUWXZ&xYRoB zpvj%~Eobn~3kT0^bD-pm=VB~LN-kO%3c8pEV=Svxwmi2G!w`xD?XE@07Sf(Hd*Xr~ zOJc(sEykkcvyaOLT@UxJf96B#`pTEM)CZ7rHlQV~;fw)MHQJ{3{HLy_IpqVE8LGTn Qb^Bex@RCt|0jfqohXv_Sxc~qF literal 0 HcmV?d00001 diff --git a/test/integration_new/stash/rename/expected/repo/.git_keep/objects/4d/ff185ecddfb638f76215fa07adde0f4e97da7c b/test/integration_new/stash/rename/expected/repo/.git_keep/objects/4d/ff185ecddfb638f76215fa07adde0f4e97da7c deleted file mode 100644 index 6d964ed92..000000000 --- a/test/integration_new/stash/rename/expected/repo/.git_keep/objects/4d/ff185ecddfb638f76215fa07adde0f4e97da7c +++ /dev/null @@ -1,2 +0,0 @@ -xA -0E)f_(1)\yd2Q)x龋לKE@1@TmDi&vUrf ,|je\wxKYn'T&%k͹QEʹ$9`] a4_C^ \ No newline at end of file diff --git a/test/integration_new/stash/rename/expected/repo/.git_keep/objects/65/d11c8b2d3c173850f337661c9bf264d0406cf1 b/test/integration_new/stash/rename/expected/repo/.git_keep/objects/65/d11c8b2d3c173850f337661c9bf264d0406cf1 new file mode 100644 index 000000000..ac5229d86 --- /dev/null +++ b/test/integration_new/stash/rename/expected/repo/.git_keep/objects/65/d11c8b2d3c173850f337661c9bf264d0406cf1 @@ -0,0 +1,4 @@ +x +0=).&MzcL[j>|R +LTRs)6EVVs@fg[u'6==ha0duZwF #lt kiY-hiϹX(ը +Mr@% \ No newline at end of file diff --git a/test/integration_new/stash/rename/expected/repo/.git_keep/objects/71/2f414b554b56ba82d43e1f7a0fe33be7eecc95 b/test/integration_new/stash/rename/expected/repo/.git_keep/objects/71/2f414b554b56ba82d43e1f7a0fe33be7eecc95 new file mode 100644 index 0000000000000000000000000000000000000000..4b6819c3a2d169b8348253ad5ceaca40d5a55a25 GIT binary patch literal 32 ncmb9VK6i>Ff%bxNXyJg)iq=&)OYj_^$y$Bbj41-ivO|o^LJ;a J0ssa(4)OEx73BZ` literal 0 HcmV?d00001 diff --git a/test/integration_new/stash/rename/expected/repo/.git_keep/objects/8d/4897b3dcbb5c8fbc8fa8439ec7e9627c3159cf b/test/integration_new/stash/rename/expected/repo/.git_keep/objects/8d/4897b3dcbb5c8fbc8fa8439ec7e9627c3159cf deleted file mode 100644 index 98e81aa49..000000000 --- a/test/integration_new/stash/rename/expected/repo/.git_keep/objects/8d/4897b3dcbb5c8fbc8fa8439ec7e9627c3159cf +++ /dev/null @@ -1,2 +0,0 @@ -x -0 a}ɺ4$ "h +Qw烿Z_/p2i)LiFFOd,Qd5wR?}kL3ܧ\߻J`51t~?+ \ No newline at end of file diff --git a/test/integration_new/stash/rename/expected/repo/.git_keep/objects/a5/272a200897df5558c8cad683c1af14f7184124 b/test/integration_new/stash/rename/expected/repo/.git_keep/objects/a5/272a200897df5558c8cad683c1af14f7184124 new file mode 100644 index 000000000..32ae211fe --- /dev/null +++ b/test/integration_new/stash/rename/expected/repo/.git_keep/objects/a5/272a200897df5558c8cad683c1af14f7184124 @@ -0,0 +1,3 @@ +xj1]Sѯ1pU~i%g.g[.ҧfvG޿wC65S+{JIlbb[ 4ahFH)D +Dx*2.9x +(NsKqkGYA]41boħ3)y{OHW \ No newline at end of file diff --git a/test/integration_new/stash/rename/expected/repo/.git_keep/objects/b2/3d362d3fa47c3b1f29c4dd41c419326415122c b/test/integration_new/stash/rename/expected/repo/.git_keep/objects/b2/3d362d3fa47c3b1f29c4dd41c419326415122c new file mode 100644 index 0000000000000000000000000000000000000000..eae6abec12b5ec05d82c11834bb328fde31ac5c1 GIT binary patch literal 51 zcmV-30L=e*0V^p=O;s>9VK6i>Ff%bxNXyJg)iq+c!>TvW_uIezwCxWC-1201oD=Zw J1^^yL4^9d!75V@G literal 0 HcmV?d00001 diff --git a/test/integration_new/stash/rename/expected/repo/.git_keep/objects/c6/f35659c0cf57c794d79df88283d7ee933831dd b/test/integration_new/stash/rename/expected/repo/.git_keep/objects/c6/f35659c0cf57c794d79df88283d7ee933831dd deleted file mode 100644 index 0eda983672af0f73b4c2736daef7cb465e6ca4f0..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 181 zcmV;m080OO0gcbQY6CG4h2hlu6zT&;*OA5q6L96q&oG(`2}EAAks*(ttz5e}&Ck~y zUdQ;JF6Q<&H&tg0(9Jxdi79~Zpc%bz43&^0m~k<)