mirror of
				https://github.com/jesseduffield/lazygit.git
				synced 2025-10-30 23:57:43 +02:00 
			
		
		
		
	Avoid crash when hitting enter on an update-ref todo
This commit is contained in:
		| @@ -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 | ||||
| } | ||||
|   | ||||
| @@ -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'", | ||||
|  | ||||
|   | ||||
| @@ -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")) | ||||
| 	}, | ||||
| }) | ||||
| @@ -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, | ||||
|   | ||||
		Reference in New Issue
	
	Block a user