mirror of
				https://github.com/jesseduffield/lazygit.git
				synced 2025-10-30 23:57:43 +02:00 
			
		
		
		
	Allow rewording the head commit during interactive rebase
This commit is contained in:
		| @@ -34,7 +34,7 @@ func NewRebaseCommands( | ||||
| } | ||||
|  | ||||
| func (self *RebaseCommands) RewordCommit(commits []*models.Commit, index int, message string) error { | ||||
| 	if index == 0 { | ||||
| 	if models.IsHeadCommit(commits, index) { | ||||
| 		// we've selected the top commit so no rebase is required | ||||
| 		return self.commit.RewordLastCommit(message) | ||||
| 	} | ||||
|   | ||||
| @@ -65,3 +65,7 @@ func (c *Commit) IsMerge() bool { | ||||
| func (c *Commit) IsTODO() bool { | ||||
| 	return c.Action != "" | ||||
| } | ||||
|  | ||||
| func IsHeadCommit(commits []*Commit, index int) bool { | ||||
| 	return !commits[index].IsTODO() && (index == 0 || commits[index-1].IsTODO()) | ||||
| } | ||||
|   | ||||
| @@ -229,7 +229,7 @@ func (self *LocalCommitsController) reword(commit *models.Commit) error { | ||||
| func (self *LocalCommitsController) doRewordEditor() error { | ||||
| 	self.c.LogAction(self.c.Tr.Actions.RewordCommit) | ||||
|  | ||||
| 	if self.context().GetSelectedLineIdx() == 0 { | ||||
| 	if self.isHeadCommit() { | ||||
| 		return self.c.RunSubprocessAndRefresh(self.os.Cmd.New("git commit --allow-empty --amend --only")) | ||||
| 	} | ||||
|  | ||||
| @@ -728,3 +728,7 @@ func (self *LocalCommitsController) context() *context.LocalCommitsContext { | ||||
| func (self *LocalCommitsController) paste() error { | ||||
| 	return self.helpers.CherryPick.Paste() | ||||
| } | ||||
|  | ||||
| func (self *LocalCommitsController) isHeadCommit() bool { | ||||
| 	return models.IsHeadCommit(self.model.Commits, self.context().GetSelectedLineIdx()) | ||||
| } | ||||
|   | ||||
| @@ -0,0 +1,47 @@ | ||||
| package interactive_rebase | ||||
|  | ||||
| import ( | ||||
| 	"github.com/jesseduffield/lazygit/pkg/config" | ||||
| 	. "github.com/jesseduffield/lazygit/pkg/integration/components" | ||||
| ) | ||||
|  | ||||
| var RewordYouAreHereCommit = NewIntegrationTest(NewIntegrationTestArgs{ | ||||
| 	Description:  "Rewords the current HEAD commit in an interactive rebase", | ||||
| 	ExtraCmdArgs: "", | ||||
| 	Skip:         false, | ||||
| 	SetupConfig:  func(config *config.AppConfig) {}, | ||||
| 	SetupRepo: func(shell *Shell) { | ||||
| 		shell. | ||||
| 			CreateNCommits(3) | ||||
| 	}, | ||||
| 	Run: func(t *TestDriver, keys config.KeybindingConfig) { | ||||
| 		t.Views().Commits(). | ||||
| 			Focus(). | ||||
| 			Lines( | ||||
| 				Contains("commit 03").IsSelected(), | ||||
| 				Contains("commit 02"), | ||||
| 				Contains("commit 01"), | ||||
| 			). | ||||
| 			NavigateToLine(Contains("commit 02")). | ||||
| 			Press(keys.Universal.Edit). | ||||
| 			Lines( | ||||
| 				Contains("commit 03"), | ||||
| 				Contains("<-- YOU ARE HERE --- commit 02").IsSelected(), | ||||
| 				Contains("commit 01"), | ||||
| 			). | ||||
| 			Press(keys.Commits.RenameCommit). | ||||
| 			Tap(func() { | ||||
| 				t.ExpectPopup().Prompt(). | ||||
| 					Title(Equals("reword commit")). | ||||
| 					InitialText(Equals("commit 02")). | ||||
| 					Clear(). | ||||
| 					Type("renamed 02"). | ||||
| 					Confirm() | ||||
| 			}). | ||||
| 			Lines( | ||||
| 				Contains("commit 03"), | ||||
| 				Contains("<-- YOU ARE HERE --- renamed 02").IsSelected(), | ||||
| 				Contains("commit 01"), | ||||
| 			) | ||||
| 	}, | ||||
| }) | ||||
| @@ -0,0 +1,47 @@ | ||||
| package interactive_rebase | ||||
|  | ||||
| import ( | ||||
| 	"github.com/jesseduffield/lazygit/pkg/config" | ||||
| 	. "github.com/jesseduffield/lazygit/pkg/integration/components" | ||||
| ) | ||||
|  | ||||
| var RewordYouAreHereCommitWithEditor = NewIntegrationTest(NewIntegrationTestArgs{ | ||||
| 	Description:  "Rewords the current HEAD commit in an interactive rebase with editor", | ||||
| 	ExtraCmdArgs: "", | ||||
| 	Skip:         false, | ||||
| 	SetupConfig: func(config *config.AppConfig) { | ||||
| 	}, | ||||
| 	SetupRepo: func(shell *Shell) { | ||||
| 		shell. | ||||
| 			CreateNCommits(3). | ||||
| 			SetConfig("core.editor", "sh -c 'echo renamed 02 >.git/COMMIT_EDITMSG'") | ||||
| 	}, | ||||
| 	Run: func(t *TestDriver, keys config.KeybindingConfig) { | ||||
| 		t.Views().Commits(). | ||||
| 			Focus(). | ||||
| 			Lines( | ||||
| 				Contains("commit 03").IsSelected(), | ||||
| 				Contains("commit 02"), | ||||
| 				Contains("commit 01"), | ||||
| 			). | ||||
| 			NavigateToLine(Contains("commit 02")). | ||||
| 			Press(keys.Universal.Edit). | ||||
| 			Lines( | ||||
| 				Contains("commit 03"), | ||||
| 				Contains("<-- YOU ARE HERE --- commit 02").IsSelected(), | ||||
| 				Contains("commit 01"), | ||||
| 			). | ||||
| 			Press(keys.Commits.RenameCommitWithEditor). | ||||
| 			Tap(func() { | ||||
| 				t.ExpectPopup().Confirmation(). | ||||
| 					Title(Equals("Reword in editor")). | ||||
| 					Content(Contains("Are you sure you want to reword this commit in your editor?")). | ||||
| 					Confirm() | ||||
| 			}). | ||||
| 			Lines( | ||||
| 				Contains("commit 03"), | ||||
| 				Contains("<-- YOU ARE HERE --- renamed 02").IsSelected(), | ||||
| 				Contains("commit 01"), | ||||
| 			) | ||||
| 	}, | ||||
| }) | ||||
| @@ -90,6 +90,8 @@ var tests = []*components.IntegrationTest{ | ||||
| 	interactive_rebase.Rebase, | ||||
| 	interactive_rebase.RewordFirstCommit, | ||||
| 	interactive_rebase.RewordLastCommit, | ||||
| 	interactive_rebase.RewordYouAreHereCommit, | ||||
| 	interactive_rebase.RewordYouAreHereCommitWithEditor, | ||||
| 	interactive_rebase.SquashDownFirstCommit, | ||||
| 	interactive_rebase.SquashDownSecondCommit, | ||||
| 	interactive_rebase.SquashFixupsAboveFirstCommit, | ||||
|   | ||||
		Reference in New Issue
	
	Block a user