1
0
mirror of https://github.com/jesseduffield/lazygit.git synced 2025-02-07 13:42:01 +02:00

Better error message for trying to squash or fixup the first commit

It's not so much the total number of commits that matters here, it's just
whether we are on the first one. (This includes the other condition.)

This allows us to get rid of the condition in rebase.go.
This commit is contained in:
Stefan Haller 2023-02-19 15:08:35 +01:00
parent 1c3db24e44
commit dd61c49a15
11 changed files with 87 additions and 22 deletions

View File

@ -178,10 +178,6 @@ func (self *RebaseCommands) BuildSingleActionTodo(commits []*models.Commit, acti
if action == "squash" || action == "fixup" {
baseIndex++
if len(commits) <= baseIndex {
return nil, "", errors.New(self.Tr.CannotSquashOntoSecondCommit)
}
}
todoLines := self.BuildTodoLines(commits[0:baseIndex], func(commit *models.Commit, i int) string {

View File

@ -148,8 +148,8 @@ func (self *LocalCommitsController) GetKeybindings(opts types.KeybindingsOpts) [
}
func (self *LocalCommitsController) squashDown(commit *models.Commit) error {
if len(self.model.Commits) <= 1 {
return self.c.ErrorMsg(self.c.Tr.YouNoCommitsToSquash)
if self.context().GetSelectedLineIdx() >= len(self.model.Commits)-1 {
return self.c.ErrorMsg(self.c.Tr.CannotSquashOrFixupFirstCommit)
}
applied, err := self.handleMidRebaseCommand("squash", commit)
@ -173,8 +173,8 @@ func (self *LocalCommitsController) squashDown(commit *models.Commit) error {
}
func (self *LocalCommitsController) fixup(commit *models.Commit) error {
if len(self.model.Commits) <= 1 {
return self.c.ErrorMsg(self.c.Tr.YouNoCommitsToSquash)
if self.context().GetSelectedLineIdx() >= len(self.model.Commits)-1 {
return self.c.ErrorMsg(self.c.Tr.CannotSquashOrFixupFirstCommit)
}
applied, err := self.handleMidRebaseCommand("fixup", commit)

View File

@ -102,7 +102,7 @@ func chineseTranslationSet() TranslationSet {
LcSquashDown: "向下压缩",
LcFixupCommit: "修正提交(fixup)",
NoCommitsThisBranch: "该分支没有提交",
YouNoCommitsToSquash: "您没有提交可以压缩",
CannotSquashOrFixupFirstCommit: "There's no commit below to squash into",
Fixup: "修正(fixup)",
SureFixupThisCommit: "您确定要“修正”此提交吗?它将合并到下面的提交中",
SureSquashThisCommit: "您确定要将这个提交压缩到下面的提交中吗?",
@ -217,7 +217,6 @@ func chineseTranslationSet() TranslationSet {
SureCherryPick: "您确定要将选中的提交进行拣选到这个分支吗?",
CherryPick: "拣选 (Cherry-Pick)",
CannotRebaseOntoFirstCommit: "您不能以交互方式变基 (rebase) 至第一次提交",
CannotSquashOntoSecondCommit: "您不能压缩 (squash) 或修正 (fixup) 第二个提交",
Donate: "捐助",
AskQuestion: "提问咨询",
PrevLine: "选择上一行",

View File

@ -67,7 +67,7 @@ func dutchTranslationSet() TranslationSet {
LcQuit: "quit",
LcSquashDown: "squash beneden",
LcFixupCommit: "Fixup commit",
YouNoCommitsToSquash: "Je hebt geen commits om mee te squashen",
CannotSquashOrFixupFirstCommit: "There's no commit below to squash into",
Fixup: "Fixup",
SureFixupThisCommit: "Weet je zeker dat je fixup wil uitvoeren op deze commit? De commit hieronder zol worden squashed in deze",
SureSquashThisCommit: "Weet je zeker dat je deze commit wil samenvoegen met de commit hieronder?",
@ -182,7 +182,6 @@ func dutchTranslationSet() TranslationSet {
SureCherryPick: "Weet je zeker dat je de gekopieerde commits naar deze branch wil cherry-picken?",
CherryPick: "Cherry-Pick",
CannotRebaseOntoFirstCommit: "Je kan niet interactief rebasen naar de eerste commit",
CannotSquashOntoSecondCommit: "Je kan niet een squash/fixup doen naar de 2de commit",
Donate: "Doneer",
PrevLine: "selecteer de vorige lijn",
NextLine: "selecteer de volgende lijn",

View File

@ -87,7 +87,7 @@ type TranslationSet struct {
LcQuit string
LcSquashDown string
LcFixupCommit string
YouNoCommitsToSquash string
CannotSquashOrFixupFirstCommit string
Fixup string
SureFixupThisCommit string
SureSquashThisCommit string
@ -220,7 +220,6 @@ type TranslationSet struct {
SureCherryPick string
CherryPick string
CannotRebaseOntoFirstCommit string
CannotSquashOntoSecondCommit string
Donate string
AskQuestion string
PrevLine string
@ -737,7 +736,7 @@ func EnglishTranslationSet() TranslationSet {
LcSquashDown: "squash down",
LcFixupCommit: "fixup commit",
NoCommitsThisBranch: "No commits for this branch",
YouNoCommitsToSquash: "You have no commits to squash with",
CannotSquashOrFixupFirstCommit: "There's no commit below to squash into",
Fixup: "Fixup",
SureFixupThisCommit: "Are you sure you want to 'fixup' this commit? It will be merged into the commit below",
SureSquashThisCommit: "Are you sure you want to squash this commit into the commit below?",
@ -870,7 +869,6 @@ func EnglishTranslationSet() TranslationSet {
SureCherryPick: "Are you sure you want to cherry-pick the copied commits onto this branch?",
CherryPick: "Cherry-Pick",
CannotRebaseOntoFirstCommit: "You cannot interactive rebase onto the first commit",
CannotSquashOntoSecondCommit: "You cannot squash/fixup onto the second commit",
Donate: "Donate",
AskQuestion: "Ask Question",
PrevLine: "select previous line",

View File

@ -93,7 +93,7 @@ func japaneseTranslationSet() TranslationSet {
// LcSquashDown: "squash down",
// LcFixupCommit: "fixup commit",
// NoCommitsThisBranch: "No commits for this branch",
// YouNoCommitsToSquash: "You have no commits to squash with",
// CannotSquashOrFixupFirstCommit: "There's no commit below to squash into",
// Fixup: "Fixup",
// SureFixupThisCommit: "Are you sure you want to 'fixup' this commit? It will be merged into the commit below",
// SureSquashThisCommit: "Are you sure you want to squash this commit into the commit below?",
@ -217,7 +217,6 @@ func japaneseTranslationSet() TranslationSet {
// SureCherryPick: "Are you sure you want to cherry-pick the copied commits onto this branch?",
CherryPick: "Cherry-Pick",
// CannotRebaseOntoFirstCommit: "You cannot interactive rebase onto the first commit",
// CannotSquashOntoSecondCommit: "You cannot squash/fixup onto the second commit",
Donate: "支援",
AskQuestion: "質問",
PrevLine: "前の行を選択",

View File

@ -92,7 +92,7 @@ func koreanTranslationSet() TranslationSet {
LcSquashDown: "squash down",
LcFixupCommit: "fixup commit",
NoCommitsThisBranch: "이 브랜치에 커밋이 없습니다.",
YouNoCommitsToSquash: "You have no commits to squash with",
CannotSquashOrFixupFirstCommit: "There's no commit below to squash into",
Fixup: "Fixup",
SureFixupThisCommit: "Are you sure you want to 'fixup' this commit? It will be merged into the commit below",
SureSquashThisCommit: "Are you sure you want to squash this commit into the commit below?",
@ -218,7 +218,6 @@ func koreanTranslationSet() TranslationSet {
SureCherryPick: "정말로 복사한 커밋을 이 브랜치에 체리픽하시겠습니까?",
CherryPick: "체리픽",
CannotRebaseOntoFirstCommit: "첫 번째 커밋에 대해 대화식으로 리베이스할 수 없습니다.",
CannotSquashOntoSecondCommit: "두 번째 커밋을 squash/fixup할 수 없습니다.",
Donate: "후원",
AskQuestion: "질문하기",
PrevLine: "이전 줄 선택",

View File

@ -62,7 +62,7 @@ func polishTranslationSet() TranslationSet {
LcSquashDown: "ściśnij",
LcFixupCommit: "napraw commit",
NoCommitsThisBranch: "Brak commitów dla tej gałęzi",
YouNoCommitsToSquash: "Nie masz commitów do spłaszczenia",
CannotSquashOrFixupFirstCommit: "There's no commit below to squash into",
Fixup: "Napraw",
SureFixupThisCommit: "Jesteś pewny, ze chcesz naprawić ten commit? Commit poniżej zostanie spłaszczony w górę wraz z tym",
LcRewordCommit: "zmień nazwę commita",
@ -150,7 +150,6 @@ func polishTranslationSet() TranslationSet {
SureCherryPick: "Czy na pewno chcesz przebierać w skopiowanych commitach na tej gałęzi?",
CherryPick: "Przebieranie",
CannotRebaseOntoFirstCommit: "Nie można interaktywnie zmienić bazy na pierwszym commicie",
CannotSquashOntoSecondCommit: "Nie można spłaszczyć na drugi commit",
Donate: "Wesprzyj",
PrevLine: "poprzednia linia",
NextLine: "następna linia",

View File

@ -0,0 +1,37 @@
package interactive_rebase
import (
"github.com/jesseduffield/lazygit/pkg/config"
. "github.com/jesseduffield/lazygit/pkg/integration/components"
)
var FixupFirstCommit = NewIntegrationTest(NewIntegrationTestArgs{
Description: "Tries to fixup the first commit, which results in an error message",
ExtraCmdArgs: "",
Skip: false,
SetupConfig: func(config *config.AppConfig) {},
SetupRepo: func(shell *Shell) {
shell.
CreateNCommits(2)
},
Run: func(t *TestDriver, keys config.KeybindingConfig) {
t.Views().Commits().
Focus().
Lines(
Contains("commit 02"),
Contains("commit 01"),
).
NavigateToListItem(Contains("commit 01")).
Press(keys.Commits.MarkCommitAsFixup).
Tap(func() {
t.ExpectPopup().Alert().
Title(Equals("Error")).
Content(Equals("There's no commit below to squash into")).
Confirm()
}).
Lines(
Contains("commit 02"),
Contains("commit 01"),
)
},
})

View File

@ -0,0 +1,37 @@
package interactive_rebase
import (
"github.com/jesseduffield/lazygit/pkg/config"
. "github.com/jesseduffield/lazygit/pkg/integration/components"
)
var SquashDownFirstCommit = NewIntegrationTest(NewIntegrationTestArgs{
Description: "Tries to squash down the first commit, which results in an error message",
ExtraCmdArgs: "",
Skip: false,
SetupConfig: func(config *config.AppConfig) {},
SetupRepo: func(shell *Shell) {
shell.
CreateNCommits(2)
},
Run: func(t *TestDriver, keys config.KeybindingConfig) {
t.Views().Commits().
Focus().
Lines(
Contains("commit 02"),
Contains("commit 01"),
).
NavigateToListItem(Contains("commit 01")).
Press(keys.Commits.SquashDown).
Tap(func() {
t.ExpectPopup().Alert().
Title(Equals("Error")).
Content(Equals("There's no commit below to squash into")).
Confirm()
}).
Lines(
Contains("commit 02"),
Contains("commit 01"),
)
},
})

View File

@ -66,7 +66,9 @@ var tests = []*components.IntegrationTest{
filter_by_path.SelectFile,
filter_by_path.TypeFile,
interactive_rebase.AmendMerge,
interactive_rebase.FixupFirstCommit,
interactive_rebase.One,
interactive_rebase.SquashDownFirstCommit,
misc.ConfirmOnQuit,
misc.InitialOpen,
patch_building.CopyPatchToClipboard,