diff --git a/pkg/commands/git_commands/rebase.go b/pkg/commands/git_commands/rebase.go index 66dbcf45f..6990d6bd5 100644 --- a/pkg/commands/git_commands/rebase.go +++ b/pkg/commands/git_commands/rebase.go @@ -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 { diff --git a/pkg/gui/controllers/local_commits_controller.go b/pkg/gui/controllers/local_commits_controller.go index a9fe7a190..42920bf81 100644 --- a/pkg/gui/controllers/local_commits_controller.go +++ b/pkg/gui/controllers/local_commits_controller.go @@ -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) diff --git a/pkg/i18n/chinese.go b/pkg/i18n/chinese.go index 9533f0239..68ee2735b 100644 --- a/pkg/i18n/chinese.go +++ b/pkg/i18n/chinese.go @@ -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: "选择上一行", diff --git a/pkg/i18n/dutch.go b/pkg/i18n/dutch.go index 0127c07ad..31ef939ab 100644 --- a/pkg/i18n/dutch.go +++ b/pkg/i18n/dutch.go @@ -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", diff --git a/pkg/i18n/english.go b/pkg/i18n/english.go index 06ffd9b1c..6639b9e48 100644 --- a/pkg/i18n/english.go +++ b/pkg/i18n/english.go @@ -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", diff --git a/pkg/i18n/japanese.go b/pkg/i18n/japanese.go index 5248287a9..122fd3133 100644 --- a/pkg/i18n/japanese.go +++ b/pkg/i18n/japanese.go @@ -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: "前の行を選択", diff --git a/pkg/i18n/korean.go b/pkg/i18n/korean.go index c191a436e..361df81f2 100644 --- a/pkg/i18n/korean.go +++ b/pkg/i18n/korean.go @@ -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: "이전 줄 선택", diff --git a/pkg/i18n/polish.go b/pkg/i18n/polish.go index 05534c365..5bc2a9a35 100644 --- a/pkg/i18n/polish.go +++ b/pkg/i18n/polish.go @@ -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", diff --git a/pkg/integration/tests/interactive_rebase/fixup_first_commit.go b/pkg/integration/tests/interactive_rebase/fixup_first_commit.go new file mode 100644 index 000000000..fe339f3e2 --- /dev/null +++ b/pkg/integration/tests/interactive_rebase/fixup_first_commit.go @@ -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"), + ) + }, +}) diff --git a/pkg/integration/tests/interactive_rebase/squash_down_first_commit.go b/pkg/integration/tests/interactive_rebase/squash_down_first_commit.go new file mode 100644 index 000000000..0ec334a6c --- /dev/null +++ b/pkg/integration/tests/interactive_rebase/squash_down_first_commit.go @@ -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"), + ) + }, +}) diff --git a/pkg/integration/tests/tests_gen.go b/pkg/integration/tests/tests_gen.go index 2be0b902c..b711ea6d7 100644 --- a/pkg/integration/tests/tests_gen.go +++ b/pkg/integration/tests/tests_gen.go @@ -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,