Skip to content

Commit

Permalink
feat: allow to perform a rebase with breaking before the first commit
Browse files Browse the repository at this point in the history
  • Loading branch information
AzraelSec authored and jesseduffield committed Apr 15, 2023
1 parent 368f9c8 commit a3fdf91
Show file tree
Hide file tree
Showing 7 changed files with 40 additions and 22 deletions.
5 changes: 5 additions & 0 deletions pkg/commands/git_commands/rebase.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,11 @@ func (self *RebaseCommands) InteractiveRebaseBreakAfter(commits []*models.Commit
return self.PrepareInteractiveRebaseCommand(sha, todo, true, false).Run()
}

func (self *RebaseCommands) EditRebase(branchRef string) error {
commands := []TodoLine{{Action: "break"}}
return self.PrepareInteractiveRebaseCommand(branchRef, commands, false, true).Run()
}

// PrepareInteractiveRebaseCommand returns the cmd for an interactive rebase
// we tell git to run lazygit to edit the todo list, and we pass the client
// lazygit a todo string to write to the todo file
Expand Down
39 changes: 28 additions & 11 deletions pkg/gui/controllers/helpers/merge_and_rebase_helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -201,22 +201,39 @@ func (self *MergeAndRebaseHelper) RebaseOntoRef(ref string) error {
if ref == checkedOutBranch {
return self.c.ErrorMsg(self.c.Tr.CantRebaseOntoSelf)
}
prompt := utils.ResolvePlaceholderString(
self.c.Tr.ConfirmRebase,
menuItems := []*types.MenuItem{
{
Label: self.c.Tr.SimpleRebase,
Key: 's',
OnPress: func() error {
self.c.LogAction(self.c.Tr.Actions.RebaseBranch)
err := self.git.Rebase.RebaseBranch(ref)
return self.CheckMergeOrRebase(err)
},
},
{
Label: self.c.Tr.InteractiveRebase,
Key: 'i',
Tooltip: self.c.Tr.InteractiveRebaseTooltip,
OnPress: func() error {
self.c.LogAction(self.c.Tr.Actions.RebaseBranch)
err := self.git.Rebase.EditRebase(ref)
return self.CheckMergeOrRebase(err)
},
},
}

title := utils.ResolvePlaceholderString(
self.c.Tr.RebasingTitle,
map[string]string{
"checkedOutBranch": checkedOutBranch,
"selectedBranch": ref,
"ref": ref,
},
)

return self.c.Confirm(types.ConfirmOpts{
Title: self.c.Tr.RebasingTitle,
Prompt: prompt,
HandleConfirm: func() error {
self.c.LogAction(self.c.Tr.Actions.RebaseBranch)
err := self.git.Rebase.RebaseBranch(ref)
return self.CheckMergeOrRebase(err)
},
return self.c.Menu(types.CreateMenuOptions{
Title: title,
Items: menuItems,
})
}

Expand Down
2 changes: 0 additions & 2 deletions pkg/i18n/chinese.go
Original file line number Diff line number Diff line change
Expand Up @@ -201,8 +201,6 @@ func chineseTranslationSet() TranslationSet {
ReflogCommitsTitle: "Reflog 页面",
GlobalTitle: "全局键绑定",
ConflictsResolved: "已解决所有冲突。是否继续?",
RebasingTitle: "变基",
ConfirmRebase: "您确定要将分支 {{.checkedOutBranch}} 变基到 {{.selectedBranch}} 吗?",
ConfirmMerge: "您确定要将分支 {{.selectedBranch}} 合并到 {{.checkedOutBranch}} 吗?",
FwdNoUpstream: "此分支没有上游,无法快进",
FwdNoLocalUpstream: "此分支的远程未在本地注册,无法快进",
Expand Down
2 changes: 0 additions & 2 deletions pkg/i18n/dutch.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,9 +166,7 @@ func dutchTranslationSet() TranslationSet {
ReflogCommitsTitle: "Reflog",
GlobalTitle: "Globale Sneltoetsen",
ConflictsResolved: "alle merge conflicten zijn opgelost. Wilt je verder gaan?",
RebasingTitle: "Rebasen",
MergingTitle: "Mergen",
ConfirmRebase: "Weet je zeker dat je '{{.checkedOutBranch}}' op '{{.selectedBranch}}' wil rebasen?",
ConfirmMerge: "Weet je zeker dat je '{{.selectedBranch}}' in '{{.checkedOutBranch}}' wil mergen?",
FwdNoUpstream: "Kan niet de branch vooruitspoelen zonder upstream",
FwdCommitsToPush: "Je kan niet vooruitspoelen als de branch geen nieuwe commits heeft",
Expand Down
10 changes: 7 additions & 3 deletions pkg/i18n/english.go
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,9 @@ type TranslationSet struct {
ReflogCommitsTitle string
ConflictsResolved string
RebasingTitle string
ConfirmRebase string
SimpleRebase string
InteractiveRebase string
InteractiveRebaseTooltip string
ConfirmMerge string
FwdNoUpstream string
FwdNoLocalUpstream string
Expand Down Expand Up @@ -877,8 +879,10 @@ func EnglishTranslationSet() TranslationSet {
ReflogCommitsTitle: "Reflog",
GlobalTitle: "Global Keybindings",
ConflictsResolved: "all merge conflicts resolved. Continue?",
RebasingTitle: "Rebasing",
ConfirmRebase: "Are you sure you want to rebase '{{.checkedOutBranch}}' on top of '{{.selectedBranch}}'?",
RebasingTitle: "Rebase '{{.checkedOutBranch}}' onto '{{.ref}}'",
SimpleRebase: "Simple rebase",
InteractiveRebase: "Interactive rebase",
InteractiveRebaseTooltip: "Begin an interactive rebase with a break at the start, so you can update the TODO commits before continuing",
ConfirmMerge: "Are you sure you want to merge '{{.selectedBranch}}' into '{{.checkedOutBranch}}'?",
FwdNoUpstream: "Cannot fast-forward a branch with no upstream",
FwdNoLocalUpstream: "Cannot fast-forward a branch whose remote is not registered locally",
Expand Down
2 changes: 0 additions & 2 deletions pkg/i18n/korean.go
Original file line number Diff line number Diff line change
Expand Up @@ -202,8 +202,6 @@ func koreanTranslationSet() TranslationSet {
ReflogCommitsTitle: "Reflog",
GlobalTitle: "글로벌 키 바인딩",
ConflictsResolved: "모든 병합 충돌이 해결되었습니다. 계속 할까요?",
RebasingTitle: "리베이스 중",
ConfirmRebase: "정말로 '{{.checkedOutBranch}}' 을(를) '{{.selectedBranch}}'에 리베이스 하시겠습니까?",
ConfirmMerge: "정말로 '{{.selectedBranch}}' 을(를) '{{.checkedOutBranch}}'에 병합하시겠습니까?",
FwdNoUpstream: "Cannot fast-forward a branch with no upstream",
FwdNoLocalUpstream: "Cannot fast-forward a branch whose remote is not registered locally",
Expand Down
2 changes: 0 additions & 2 deletions pkg/i18n/polish.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,9 +112,7 @@ func polishTranslationSet() TranslationSet {
FileStagingRequirements: "Można tylko zatwierdzić pojedyncze linie dla śledzonych plików z niezatwierdzonymi zmianami",
StagingTitle: "Poczekalnia",
ReturnToFilesPanel: "wróć do panelu plików",
RebasingTitle: "Zmiana bazy",
MergingTitle: "Scalanie",
ConfirmRebase: "Czy napewno chcesz zmienić bazę '{{.checkedOutBranch}}' na '{{.selectedBranch}}'?",
ConfirmMerge: "Czy na pewno chcesz scalić '{{.selectedBranch}}' do '{{.checkedOutBranch}}'?",
FwdNoUpstream: "Nie można przewinąć gałęzi bez gałęzi nadrzędnej",
FwdCommitsToPush: "Nie można przewinąć gałęzi z commitami do wysłania",
Expand Down

0 comments on commit a3fdf91

Please sign in to comment.