From 51a558040d64c54e66609a708307008dae3ce7ec Mon Sep 17 00:00:00 2001 From: Stefan Haller Date: Mon, 17 Apr 2023 17:32:10 +0200 Subject: [PATCH 1/3] Fix the title and text (and variable names) of the Discard Changes prompt The title was saying "Unstage lines", which was just wrong. The text said "Delete lines", which can be seen as a bit misleading; we are only discarding the changes to the selected lines, not deleting the lines themselves. For consistency, rename the config variable skipUnstageLineWarning accordingly. --- docs/Config.md | 2 +- pkg/config/user_config.go | 24 ++++++++++---------- pkg/gui/controllers/staging_controller.go | 6 ++--- pkg/i18n/chinese.go | 4 ++-- pkg/i18n/english.go | 8 +++---- pkg/i18n/japanese.go | 4 ++-- pkg/i18n/korean.go | 4 ++-- pkg/i18n/traditional_chinese.go | 4 ++-- pkg/integration/components/common.go | 4 ++-- pkg/integration/tests/staging/stage_lines.go | 4 ++-- 10 files changed, 32 insertions(+), 32 deletions(-) diff --git a/docs/Config.md b/docs/Config.md index 5c14b2da9..bf5248413 100644 --- a/docs/Config.md +++ b/docs/Config.md @@ -53,7 +53,7 @@ gui: commitLength: show: true mouseEvents: true - skipUnstageLineWarning: false + skipDiscardChangeWarning: false skipStashWarning: false showFileTree: true # for rendering changes files in a tree format showListFooter: true # for seeing the '5 of 20' message in list panels diff --git a/pkg/config/user_config.go b/pkg/config/user_config.go index dcc0e0ef6..c3e4fc07f 100644 --- a/pkg/config/user_config.go +++ b/pkg/config/user_config.go @@ -32,7 +32,7 @@ type GuiConfig struct { ScrollHeight int `yaml:"scrollHeight"` ScrollPastBottom bool `yaml:"scrollPastBottom"` MouseEvents bool `yaml:"mouseEvents"` - SkipUnstageLineWarning bool `yaml:"skipUnstageLineWarning"` + SkipDiscardChangeWarning bool `yaml:"skipDiscardChangeWarning"` SkipStashWarning bool `yaml:"skipStashWarning"` SidePanelWidth float64 `yaml:"sidePanelWidth"` ExpandFocusedSidePanel bool `yaml:"expandFocusedSidePanel"` @@ -397,17 +397,17 @@ type CustomCommandMenuOption struct { func GetDefaultConfig() *UserConfig { return &UserConfig{ Gui: GuiConfig{ - ScrollHeight: 2, - ScrollPastBottom: true, - MouseEvents: true, - SkipUnstageLineWarning: false, - SkipStashWarning: false, - SidePanelWidth: 0.3333, - ExpandFocusedSidePanel: false, - MainPanelSplitMode: "flexible", - Language: "auto", - TimeFormat: "02 Jan 06", - ShortTimeFormat: time.Kitchen, + ScrollHeight: 2, + ScrollPastBottom: true, + MouseEvents: true, + SkipDiscardChangeWarning: false, + SkipStashWarning: false, + SidePanelWidth: 0.3333, + ExpandFocusedSidePanel: false, + MainPanelSplitMode: "flexible", + Language: "auto", + TimeFormat: "02 Jan 06", + ShortTimeFormat: time.Kitchen, Theme: ThemeConfig{ ActiveBorderColor: []string{"green", "bold"}, InactiveBorderColor: []string{"default"}, diff --git a/pkg/gui/controllers/staging_controller.go b/pkg/gui/controllers/staging_controller.go index 71b11cc06..20a0ada67 100644 --- a/pkg/gui/controllers/staging_controller.go +++ b/pkg/gui/controllers/staging_controller.go @@ -169,10 +169,10 @@ func (self *StagingController) ToggleStaged() error { func (self *StagingController) ResetSelection() error { reset := func() error { return self.applySelectionAndRefresh(true) } - if !self.staged && !self.c.UserConfig.Gui.SkipUnstageLineWarning { + if !self.staged && !self.c.UserConfig.Gui.SkipDiscardChangeWarning { return self.c.Confirm(types.ConfirmOpts{ - Title: self.c.Tr.UnstageLinesTitle, - Prompt: self.c.Tr.UnstageLinesPrompt, + Title: self.c.Tr.DiscardChangeTitle, + Prompt: self.c.Tr.DiscardChangePrompt, HandleConfirm: reset, }) } diff --git a/pkg/i18n/chinese.go b/pkg/i18n/chinese.go index 52e92559f..179ed7a01 100644 --- a/pkg/i18n/chinese.go +++ b/pkg/i18n/chinese.go @@ -378,8 +378,8 @@ func chineseTranslationSet() TranslationSet { NoFilesStagedPrompt: "您尚未暂存任何文件。提交所有文件?", BranchNotFoundTitle: "找不到分支", BranchNotFoundPrompt: "找不到分支。创建一个新分支命名为:", - UnstageLinesTitle: "取消暂存选中的行", - UnstageLinesPrompt: "您确定要删除所选的行(git reset)吗?这是不可逆的。\n要禁用此对话框,请将 'gui.skipUnstageLineWarning' 的配置键设置为 true", + DiscardChangeTitle: "取消暂存选中的行", + DiscardChangePrompt: "您确定要删除所选的行(git reset)吗?这是不可逆的。\n要禁用此对话框,请将 'gui.skipDiscardChangeWarning' 的配置键设置为 true", CreateNewBranchFromCommit: "从提交创建新分支", BuildingPatch: "正在构建补丁", ViewCommits: "查看提交", diff --git a/pkg/i18n/english.go b/pkg/i18n/english.go index b291a0058..b95cfdfa4 100644 --- a/pkg/i18n/english.go +++ b/pkg/i18n/english.go @@ -428,8 +428,8 @@ type TranslationSet struct { BranchNotFoundTitle string BranchNotFoundPrompt string BranchUnknown string - UnstageLinesTitle string - UnstageLinesPrompt string + DiscardChangeTitle string + DiscardChangePrompt string CreateNewBranchFromCommit string BuildingPatch string ViewCommits string @@ -1119,8 +1119,8 @@ func EnglishTranslationSet() TranslationSet { BranchNotFoundTitle: "Branch not found", BranchNotFoundPrompt: "Branch not found. Create a new branch named", BranchUnknown: "Branch unknown", - UnstageLinesTitle: "Unstage lines", - UnstageLinesPrompt: "Are you sure you want to delete the selected lines (git reset)? It is irreversible.\nTo disable this dialogue set the config key of 'gui.skipUnstageLineWarning' to true", + DiscardChangeTitle: "Discard change", + DiscardChangePrompt: "Are you sure you want to discard this change (git reset)? It is irreversible.\nTo disable this dialogue set the config key of 'gui.skipDiscardChangeWarning' to true", CreateNewBranchFromCommit: "Create new branch off of commit", BuildingPatch: "Building patch", ViewCommits: "View commits", diff --git a/pkg/i18n/japanese.go b/pkg/i18n/japanese.go index 49941f6c0..6713bf4fb 100644 --- a/pkg/i18n/japanese.go +++ b/pkg/i18n/japanese.go @@ -394,8 +394,8 @@ func japaneseTranslationSet() TranslationSet { NoFilesStagedPrompt: "ファイルがステージされていません。すべての変更をコミットしますか?", BranchNotFoundTitle: "ブランチが見つかりませんでした。", BranchNotFoundPrompt: "ブランチが見つかりませんでした。新しくブランチを作成します ", - UnstageLinesTitle: "選択行をアンステージ", - UnstageLinesPrompt: "選択された行を削除 (git reset) します。よろしいですか? この操作は取り消せません。\nこの警告を無効化するには設定ファイルの 'gui.skipUnstageLineWarning' を true に設定してください。", + DiscardChangeTitle: "選択行をアンステージ", + DiscardChangePrompt: "選択された行を削除 (git reset) します。よろしいですか? この操作は取り消せません。\nこの警告を無効化するには設定ファイルの 'gui.skipDiscardChangeWarning' を true に設定してください。", CreateNewBranchFromCommit: "コミットにブランチを作成", BuildingPatch: "パッチを構築", ViewCommits: "コミットを閲覧", diff --git a/pkg/i18n/korean.go b/pkg/i18n/korean.go index 1c469ed68..ea4446d24 100644 --- a/pkg/i18n/korean.go +++ b/pkg/i18n/korean.go @@ -389,8 +389,8 @@ func koreanTranslationSet() TranslationSet { NoFilesStagedPrompt: "파일이 Staged 되지 않았습니다. 모든 파일을 커밋하시겠습니까?", BranchNotFoundTitle: "브랜치를 찾을 수 없습니다.", BranchNotFoundPrompt: "브랜치를 찾을 수 없습니다. 새로운 브랜치를 생성합니다.", - UnstageLinesTitle: "선택한 라인을 unstaged", - UnstageLinesPrompt: "정말로 선택한 라인을 삭제 (git reset) 하시겠습니까? 이 조작은 취소할 수 없습니다.\n이 경고를 비활성화 하려면 설정 파일의 'gui.skipUnstageLineWarning' 를 true로 설정하세요.", + DiscardChangeTitle: "선택한 라인을 unstaged", + DiscardChangePrompt: "정말로 선택한 라인을 삭제 (git reset) 하시겠습니까? 이 조작은 취소할 수 없습니다.\n이 경고를 비활성화 하려면 설정 파일의 'gui.skipDiscardChangeWarning' 를 true로 설정하세요.", CreateNewBranchFromCommit: "커밋에서 새 브랜치를 만듭니다.", BuildingPatch: "Building patch", ViewCommits: "커밋 보기", diff --git a/pkg/i18n/traditional_chinese.go b/pkg/i18n/traditional_chinese.go index c51ae97b1..bfcca1c1b 100644 --- a/pkg/i18n/traditional_chinese.go +++ b/pkg/i18n/traditional_chinese.go @@ -481,8 +481,8 @@ func traditionalChineseTranslationSet() TranslationSet { BranchNotFoundTitle: "找不到分支", BranchNotFoundPrompt: "找不到分支。是否創建一個名為", BranchUnknown: "分支未知", - UnstageLinesTitle: "取消預存行", - UnstageLinesPrompt: "你確定要刪除所選行嗎(git reset)?此操作是不可逆的。\n要禁用此對話框,請將“gui.skipUnstageLineWarning”設置為true。", + DiscardChangeTitle: "取消預存行", + DiscardChangePrompt: "你確定要刪除所選行嗎(git reset)?此操作是不可逆的。\n要禁用此對話框,請將“gui.skipDiscardChangeWarning”設置為true。", CreateNewBranchFromCommit: "從提交建立新分支", BuildingPatch: "正在建立補丁", ViewCommits: "檢視提交", diff --git a/pkg/integration/components/common.go b/pkg/integration/components/common.go index 904c73711..12afaee2f 100644 --- a/pkg/integration/components/common.go +++ b/pkg/integration/components/common.go @@ -34,8 +34,8 @@ func (self *Common) ContinueOnConflictsResolved() { func (self *Common) ConfirmDiscardLines() { self.t.ExpectPopup().Confirmation(). - Title(Equals("Unstage lines")). - Content(Contains("Are you sure you want to delete the selected lines")). + Title(Equals("Discard change")). + Content(Contains("Are you sure you want to discard this change")). Confirm() } diff --git a/pkg/integration/tests/staging/stage_lines.go b/pkg/integration/tests/staging/stage_lines.go index 197e003ca..5df7b23d4 100644 --- a/pkg/integration/tests/staging/stage_lines.go +++ b/pkg/integration/tests/staging/stage_lines.go @@ -92,8 +92,8 @@ var StageLines = NewIntegrationTest(NewIntegrationTestArgs{ Press(keys.Universal.Remove). Tap(func() { t.ExpectPopup().Confirmation(). - Title(Equals("Unstage lines")). - Content(Contains("Are you sure you want to delete the selected lines")). + Title(Equals("Discard change")). + Content(Contains("Are you sure you want to discard this change")). Confirm() }). IsEmpty() From ee03a0be41ef58b4775c9bd603636567f63c0c88 Mon Sep 17 00:00:00 2001 From: Stefan Haller Date: Mon, 5 Jun 2023 09:30:55 +0200 Subject: [PATCH 2/3] Rename "Delete change" menu entry to "Discard change" in staging panel For consistency with the previous commit. Note that this menu entry is used both for unstaged and for staged changes, and for staged changes it is not quite accurate, as we are not discarding changes in that case (just unstaging them). Not sure it's worth fixing this; it's still better than "Delete", anyway. --- docs/keybindings/Keybindings_en.md | 2 +- docs/keybindings/Keybindings_pl.md | 2 +- pkg/gui/controllers/staging_controller.go | 6 +++--- pkg/i18n/chinese.go | 2 +- pkg/i18n/dutch.go | 2 +- pkg/i18n/english.go | 4 ++-- pkg/i18n/japanese.go | 2 +- pkg/i18n/korean.go | 2 +- pkg/i18n/traditional_chinese.go | 2 +- 9 files changed, 12 insertions(+), 12 deletions(-) diff --git a/docs/keybindings/Keybindings_en.md b/docs/keybindings/Keybindings_en.md index 7a6687d9f..4dee9cbad 100644 --- a/docs/keybindings/Keybindings_en.md +++ b/docs/keybindings/Keybindings_en.md @@ -206,7 +206,7 @@ _Legend: `` means ctrl+b, `` means alt+b, `B` means shift+b_ <esc>: Return to files panel <tab>: Switch to other panel (staged/unstaged changes) <space>: Toggle line staged / unstaged - d: Delete change (git reset) + d: Discard change (git reset) E: Edit hunk c: Commit changes w: Commit changes without pre-commit hook diff --git a/docs/keybindings/Keybindings_pl.md b/docs/keybindings/Keybindings_pl.md index 2f1da2e62..7d2fef98b 100644 --- a/docs/keybindings/Keybindings_pl.md +++ b/docs/keybindings/Keybindings_pl.md @@ -190,7 +190,7 @@ _Legend: `` means ctrl+b, `` means alt+b, `B` means shift+b_ <esc>: Wróć do panelu plików <tab>: Switch to other panel (staged/unstaged changes) <space>: Toggle line staged / unstaged - d: Delete change (git reset) + d: Discard change (git reset) E: Edit hunk c: Zatwierdź zmiany w: Zatwierdź zmiany bez skryptu pre-commit diff --git a/pkg/gui/controllers/staging_controller.go b/pkg/gui/controllers/staging_controller.go index 20a0ada67..46cd6cb69 100644 --- a/pkg/gui/controllers/staging_controller.go +++ b/pkg/gui/controllers/staging_controller.go @@ -66,8 +66,8 @@ func (self *StagingController) GetKeybindings(opts types.KeybindingsOpts) []*typ }, { Key: opts.GetKey(opts.Config.Universal.Remove), - Handler: self.ResetSelection, - Description: self.c.Tr.ResetSelection, + Handler: self.DiscardSelection, + Description: self.c.Tr.DiscardSelection, }, { Key: opts.GetKey(opts.Config.Main.EditSelectHunk), @@ -166,7 +166,7 @@ func (self *StagingController) ToggleStaged() error { return self.applySelectionAndRefresh(self.staged) } -func (self *StagingController) ResetSelection() error { +func (self *StagingController) DiscardSelection() error { reset := func() error { return self.applySelectionAndRefresh(true) } if !self.staged && !self.c.UserConfig.Gui.SkipDiscardChangeWarning { diff --git a/pkg/i18n/chinese.go b/pkg/i18n/chinese.go index 179ed7a01..27576916e 100644 --- a/pkg/i18n/chinese.go +++ b/pkg/i18n/chinese.go @@ -167,7 +167,7 @@ func chineseTranslationSet() TranslationSet { FileEnter: `暂存单个 块/行 用于文件, 或 折叠/展开 目录`, FileStagingRequirements: `只能暂存跟踪文件的单独行`, StageSelection: `切换行暂存状态`, - ResetSelection: `取消变更 (git reset)`, + DiscardSelection: `取消变更 (git reset)`, ToggleDragSelect: `切换拖动选择`, ToggleSelectHunk: `切换选择区块`, ToggleSelectionForPatch: `添加/移除 行到补丁`, diff --git a/pkg/i18n/dutch.go b/pkg/i18n/dutch.go index bd0a15b8e..2c5792e91 100644 --- a/pkg/i18n/dutch.go +++ b/pkg/i18n/dutch.go @@ -132,7 +132,7 @@ func dutchTranslationSet() TranslationSet { FileEnter: `Stage individuele hunks/lijnen`, FileStagingRequirements: `Kan alleen individuele lijnen stagen van getrackte bestanden met onstaged veranderingen`, StageSelection: `Toggle lijnen staged / unstaged`, - ResetSelection: `Verwijdert change (git reset)`, + DiscardSelection: `Verwijdert change (git reset)`, ToggleDragSelect: `Toggle drag selecteer`, ToggleSelectHunk: `Toggle selecteer hunk`, ToggleSelectionForPatch: `Voeg toe/verwijder lijn(en) in patch`, diff --git a/pkg/i18n/english.go b/pkg/i18n/english.go index b95cfdfa4..f375fbea9 100644 --- a/pkg/i18n/english.go +++ b/pkg/i18n/english.go @@ -172,7 +172,7 @@ type TranslationSet struct { FileEnter string FileStagingRequirements string StageSelection string - ResetSelection string + DiscardSelection string ToggleDragSelect string ToggleSelectHunk string ToggleSelectionForPatch string @@ -863,7 +863,7 @@ func EnglishTranslationSet() TranslationSet { FileEnter: `Stage individual hunks/lines for file, or collapse/expand for directory`, FileStagingRequirements: `Can only stage individual lines for tracked files`, StageSelection: `Toggle line staged / unstaged`, - ResetSelection: `Delete change (git reset)`, + DiscardSelection: `Discard change (git reset)`, ToggleDragSelect: `Toggle drag select`, ToggleSelectHunk: `Toggle select hunk`, ToggleSelectionForPatch: `Add/Remove line(s) to patch`, diff --git a/pkg/i18n/japanese.go b/pkg/i18n/japanese.go index 6713bf4fb..28e51026a 100644 --- a/pkg/i18n/japanese.go +++ b/pkg/i18n/japanese.go @@ -167,7 +167,7 @@ func japaneseTranslationSet() TranslationSet { // FileEnter: `stage individual hunks/lines for file, or collapse/expand for directory`, // FileStagingRequirements: `Can only stage individual lines for tracked files`, StageSelection: `選択行をステージ/アンステージ`, - ResetSelection: `変更を削除 (git reset)`, + DiscardSelection: `変更を削除 (git reset)`, ToggleDragSelect: `範囲選択を切り替え`, ToggleSelectHunk: `Hunk選択を切り替え`, ToggleSelectionForPatch: `行をパッチに追加/削除`, diff --git a/pkg/i18n/korean.go b/pkg/i18n/korean.go index ea4446d24..10d399917 100644 --- a/pkg/i18n/korean.go +++ b/pkg/i18n/korean.go @@ -168,7 +168,7 @@ func koreanTranslationSet() TranslationSet { FileEnter: `Stage individual hunks/lines for file, or collapse/expand for directory`, FileStagingRequirements: `추적된 파일에 대해 개별 라인만 stage할 수 있습니다.`, StageSelection: `선택한 행을 staged / unstaged`, - ResetSelection: `변경을 삭제 (git reset)`, + DiscardSelection: `변경을 삭제 (git reset)`, ToggleDragSelect: `드래그 선택 전환`, ToggleSelectHunk: `Toggle select hunk`, ToggleSelectionForPatch: `Line(s)을 패치에 추가/삭제`, diff --git a/pkg/i18n/traditional_chinese.go b/pkg/i18n/traditional_chinese.go index bfcca1c1b..12d38d768 100644 --- a/pkg/i18n/traditional_chinese.go +++ b/pkg/i18n/traditional_chinese.go @@ -231,7 +231,7 @@ func traditionalChineseTranslationSet() TranslationSet { FileEnter: `選擇檔案中的單個程式碼塊/行,或展開/折疊目錄`, FileStagingRequirements: `只能選擇跟踪檔案中的單個行`, StageSelection: `切換現有行的狀態 (已預存/未預存)`, - ResetSelection: `刪除變更 (git reset)`, + DiscardSelection: `刪除變更 (git reset)`, ToggleDragSelect: `切換拖曳選擇`, ToggleSelectHunk: `切換選擇程式碼塊`, ToggleSelectionForPatch: `向 (或從) 補丁中添加/刪除行`, From 2f6b7b9bc300dd8d0cc5a2266f8a87509d8b0564 Mon Sep 17 00:00:00 2001 From: Stefan Haller Date: Thu, 8 Jun 2023 13:12:39 +0200 Subject: [PATCH 3/3] Rename the gui.skipUnstageLineWarning conf key to gui.skipDiscardChangeWarning --- pkg/config/app_config.go | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/pkg/config/app_config.go b/pkg/config/app_config.go index 3b3000a50..4108279ad 100644 --- a/pkg/config/app_config.go +++ b/pkg/config/app_config.go @@ -7,6 +7,7 @@ import ( "strings" "github.com/OpenPeeDeeP/xdg" + "github.com/jesseduffield/lazygit/pkg/utils/yaml_utils" "gopkg.in/yaml.v3" ) @@ -156,6 +157,11 @@ func loadUserConfig(configFiles []string, base *UserConfig) (*UserConfig, error) return nil, err } + content, err = migrateUserConfig(path, content) + if err != nil { + return nil, err + } + if err := yaml.Unmarshal(content, base); err != nil { return nil, fmt.Errorf("The config at `%s` couldn't be parsed, please inspect it before opening up an issue.\n%w", path, err) } @@ -164,6 +170,30 @@ func loadUserConfig(configFiles []string, base *UserConfig) (*UserConfig, error) return base, nil } +// Do any backward-compatibility migrations of things that have changed in the +// config over time; examples are renaming a key to a better name, moving a key +// from one container to another, or changing the type of a key (e.g. from bool +// to an enum). +func migrateUserConfig(path string, content []byte) ([]byte, error) { + changedContent, err := yaml_utils.RenameYamlKey(content, []string{"gui", "skipUnstageLineWarning"}, + "skipDiscardChangeWarning") + if err != nil { + return nil, fmt.Errorf("Couldn't migrate config file at `%s`: %s", path, err) + } + + // Add more migrations here... + + // Write config back if changed + if string(changedContent) != string(content) { + if err := os.WriteFile(path, changedContent, 0o644); err != nil { + return nil, fmt.Errorf("Couldn't write migrated config back to `%s`: %s", path, err) + } + return changedContent, nil + } + + return content, nil +} + func (c *AppConfig) GetDebug() bool { return c.Debug }