diff options
author | Stefan Haller <stefan@haller-berlin.de> | 2024-02-16 13:10:05 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-02-16 13:10:05 +0100 |
commit | b01bad7fad62ec54616d9cb9f0958da1d65c7aac (patch) | |
tree | cf8b65236e85485202d84d0a096a5f888f826482 | |
parent | 8746c3d9e0eb5cd19e74d5b36919da1e37d10d0d (diff) | |
parent | 3b7f32db95c3a666bd9fa07b4198ae302c393eba (diff) |
Fix two problems related to update-ref rebase todo items (#3290)
- **PR Description**
This fixes two loosely related problems with `update-ref` todos:
1. Panic when hitting enter on an `update-ref` item
2. When selecting an `update-ref` item and then triggering a refresh,
there was a bogus error message `fatal: ambiguous argument '': unknown
revision or path not in the working tree.`
-rw-r--r-- | pkg/gui/controllers/helpers/refresh_helper.go | 2 | ||||
-rw-r--r-- | pkg/gui/controllers/switch_to_diff_files_controller.go | 10 | ||||
-rw-r--r-- | pkg/i18n/english.go | 2 | ||||
-rw-r--r-- | pkg/integration/tests/interactive_rebase/view_files_of_todo_entries.go | 52 | ||||
-rw-r--r-- | pkg/integration/tests/test_list.go | 1 |
5 files changed, 65 insertions, 2 deletions
diff --git a/pkg/gui/controllers/helpers/refresh_helper.go b/pkg/gui/controllers/helpers/refresh_helper.go index a8f32d116..04b741b56 100644 --- a/pkg/gui/controllers/helpers/refresh_helper.go +++ b/pkg/gui/controllers/helpers/refresh_helper.go @@ -274,7 +274,7 @@ func (self *RefreshHelper) refreshCommitsAndCommitFiles() { // or perhaps we could just pop that context off the stack whenever cycling windows. // For now the awkwardness remains. commit := self.c.Contexts().LocalCommits.GetSelected() - if commit != nil { + if commit != nil && commit.RefName() != "" { self.c.Contexts().CommitFiles.SetRef(commit) self.c.Contexts().CommitFiles.SetTitleRef(commit.RefName()) _ = self.refreshCommitFilesContext() diff --git a/pkg/gui/controllers/switch_to_diff_files_controller.go b/pkg/gui/controllers/switch_to_diff_files_controller.go index 5207aeaf5..284fbd42f 100644 --- a/pkg/gui/controllers/switch_to_diff_files_controller.go +++ b/pkg/gui/controllers/switch_to_diff_files_controller.go @@ -51,7 +51,7 @@ func (self *SwitchToDiffFilesController) GetKeybindings(opts types.KeybindingsOp { Key: opts.GetKey(opts.Config.Universal.GoInto), Handler: self.withItem(self.enter), - GetDisabledReason: self.require(self.singleItemSelected()), + GetDisabledReason: self.require(self.singleItemSelected(self.itemRepresentsCommit)), Description: self.c.Tr.ViewItemFiles, }, } @@ -91,3 +91,11 @@ func (self *SwitchToDiffFilesController) viewFiles(opts SwitchToCommitFilesConte return self.c.PushContext(diffFilesContext) } + +func (self *SwitchToDiffFilesController) itemRepresentsCommit(ref types.Ref) *types.DisabledReason { + if ref.RefName() == "" { + return &types.DisabledReason{Text: self.c.Tr.SelectedItemDoesNotHaveFiles} + } + + return nil +} diff --git a/pkg/i18n/english.go b/pkg/i18n/english.go index da8dbc809..98c3ea5d2 100644 --- a/pkg/i18n/english.go +++ b/pkg/i18n/english.go @@ -756,6 +756,7 @@ type TranslationSet struct { RangeSelectNotSupported string NoItemSelected string SelectedItemIsNotABranch string + SelectedItemDoesNotHaveFiles string RangeSelectNotSupportedForSubmodules string OldCherryPickKeyWarning string Actions Actions @@ -1693,6 +1694,7 @@ func EnglishTranslationSet() TranslationSet { RangeSelectNotSupported: "Action does not support range selection, please select a single item", NoItemSelected: "No item selected", SelectedItemIsNotABranch: "Selected item is not a branch", + SelectedItemDoesNotHaveFiles: "Selected item does not have files to view", RangeSelectNotSupportedForSubmodules: "Range select not supported for submodules", OldCherryPickKeyWarning: "The 'c' key is no longer the default key for copying commits to cherry pick. Please use `{{.copy}}` instead (and `{{.paste}}` to paste). The reason for this change is that the 'v' key for selecting a range of lines when staging is now also used for selecting a range of lines in any list view, meaning that we needed to find a new key for pasting commits, and if we're going to now use `{{.paste}}` for pasting commits, we may as well use `{{.copy}}` for copying them. If you want to configure the keybindings to get the old behaviour, set the following in your config:\n\nkeybinding:\n universal:\n toggleRangeSelect: <something other than v>\n commits:\n cherryPickCopy: 'c'\n pasteCommits: 'v'", diff --git a/pkg/integration/tests/interactive_rebase/view_files_of_todo_entries.go b/pkg/integration/tests/interactive_rebase/view_files_of_todo_entries.go new file mode 100644 index 000000000..9a5a388c5 --- /dev/null +++ b/pkg/integration/tests/interactive_rebase/view_files_of_todo_entries.go @@ -0,0 +1,52 @@ +package interactive_rebase + +import ( + "github.com/jesseduffield/lazygit/pkg/config" + . "github.com/jesseduffield/lazygit/pkg/integration/components" +) + +var ViewFilesOfTodoEntries = NewIntegrationTest(NewIntegrationTestArgs{ + Description: "Check that files of a pick todo can be viewed, but files of an update-ref todo can't", + ExtraCmdArgs: []string{}, + Skip: false, + GitVersion: AtLeast("2.38.0"), + SetupConfig: func(config *config.AppConfig) { + config.UserConfig.Git.Log.ShowGraph = "never" + }, + SetupRepo: func(shell *Shell) { + shell. + CreateNCommits(1). + NewBranch("branch1"). + CreateNCommitsStartingAt(1, 2). + NewBranch("branch2"). + CreateNCommitsStartingAt(1, 3) + + shell.SetConfig("rebase.updateRefs", "true") + }, + Run: func(t *TestDriver, keys config.KeybindingConfig) { + t.Views().Commits(). + Focus(). + Press(keys.Commits.StartInteractiveRebase). + Lines( + Contains("pick").Contains("CI commit 03").IsSelected(), + Contains("update-ref").Contains("branch1"), + Contains("pick").Contains("CI * commit 02"), + Contains("CI <-- YOU ARE HERE --- commit 01"), + ). + Press(keys.Universal.GoInto) + + t.Views().CommitFiles(). + IsFocused(). + Lines( + Contains("file03.txt"), + ). + PressEscape() + + t.Views().Commits(). + IsFocused(). + NavigateToLine(Contains("update-ref")). + Press(keys.Universal.GoInto) + + t.ExpectToast(Equals("Disabled: Selected item does not have files to view")) + }, +}) diff --git a/pkg/integration/tests/test_list.go b/pkg/integration/tests/test_list.go index 6a448fff4..a5e17c470 100644 --- a/pkg/integration/tests/test_list.go +++ b/pkg/integration/tests/test_list.go @@ -187,6 +187,7 @@ var tests = []*components.IntegrationTest{ interactive_rebase.SwapInRebaseWithConflict, interactive_rebase.SwapInRebaseWithConflictAndEdit, interactive_rebase.SwapWithConflict, + interactive_rebase.ViewFilesOfTodoEntries, misc.ConfirmOnQuit, misc.CopyToClipboard, misc.DisabledKeybindings, |