From bb856ad7c6380802e0d621a69428ba155203a233 Mon Sep 17 00:00:00 2001 From: Stefan Haller Date: Sun, 19 Feb 2023 10:20:05 +0100 Subject: [PATCH 1/3] Bump minimum required git version to 2.20 We need this because the next commit is going to make use of the "break" interactive rebase instruction, which was added in 2.20. --- pkg/app/app.go | 2 +- pkg/i18n/chinese.go | 2 +- pkg/i18n/english.go | 2 +- pkg/i18n/japanese.go | 2 +- pkg/i18n/korean.go | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/pkg/app/app.go b/pkg/app/app.go index 05d13253a..23030b37d 100644 --- a/pkg/app/app.go +++ b/pkg/app/app.go @@ -123,7 +123,7 @@ func (app *App) validateGitVersion() (*git_commands.GitVersion, error) { return nil, minVersionError } - if version.IsOlderThan(2, 0, 0) { + if version.IsOlderThan(2, 20, 0) { return nil, minVersionError } diff --git a/pkg/i18n/chinese.go b/pkg/i18n/chinese.go index e9d1ee475..9533f0239 100644 --- a/pkg/i18n/chinese.go +++ b/pkg/i18n/chinese.go @@ -395,7 +395,7 @@ func chineseTranslationSet() TranslationSet { LcCreateNewBranchFromCommit: "从提交创建新分支", LcBuildingPatch: "正在构建补丁", LcViewCommits: "查看提交", - MinGitVersionError: "Git 版本必须至少为 2.0(即从 2014 年开始的版本)。请更新 git。或者在 https://github.com/jesseduffield/lazygit/issues 上提出一个问题,以使 lazygit 更加向后兼容。", + MinGitVersionError: "Git 版本必须至少为 2.20(即从 2018 年开始的版本)。请更新 git。或者在 https://github.com/jesseduffield/lazygit/issues 上提出一个问题,以使 lazygit 更加向后兼容。", LcRunningCustomCommandStatus: "正在运行自定义命令", LcSubmoduleStashAndReset: "存放未提交的子模块更改和更新", LcAndResetSubmodules: "和重置子模块", diff --git a/pkg/i18n/english.go b/pkg/i18n/english.go index 22c7d5c43..06ffd9b1c 100644 --- a/pkg/i18n/english.go +++ b/pkg/i18n/english.go @@ -1072,7 +1072,7 @@ func EnglishTranslationSet() TranslationSet { LcCreateNewBranchFromCommit: "create new branch off of commit", LcBuildingPatch: "building patch", LcViewCommits: "view commits", - MinGitVersionError: "Git version must be at least 2.0 (i.e. from 2014 onwards). Please upgrade your git version. Alternatively raise an issue at https://github.com/jesseduffield/lazygit/issues for lazygit to be more backwards compatible.", + MinGitVersionError: "Git version must be at least 2.20 (i.e. from 2018 onwards). Please upgrade your git version. Alternatively raise an issue at https://github.com/jesseduffield/lazygit/issues for lazygit to be more backwards compatible.", LcRunningCustomCommandStatus: "running custom command", LcSubmoduleStashAndReset: "stash uncommitted submodule changes and update", LcAndResetSubmodules: "and reset submodules", diff --git a/pkg/i18n/japanese.go b/pkg/i18n/japanese.go index b119b0a63..5248287a9 100644 --- a/pkg/i18n/japanese.go +++ b/pkg/i18n/japanese.go @@ -405,7 +405,7 @@ func japaneseTranslationSet() TranslationSet { LcCreateNewBranchFromCommit: "コミットにブランチを作成", LcBuildingPatch: "パッチを構築", LcViewCommits: "コミットを閲覧", - MinGitVersionError: "lazygitの実行にはGit 2.0以降のバージョンが必要です。Gitを更新してください。もしくは、lazygitの後方互換性を改善するために https://github.com/jesseduffield/lazygit/issues にissueを作成してください。", + MinGitVersionError: "lazygitの実行にはGit 2.20以降のバージョンが必要です。Gitを更新してください。もしくは、lazygitの後方互換性を改善するために https://github.com/jesseduffield/lazygit/issues にissueを作成してください。", LcRunningCustomCommandStatus: "カスタムコマンドを実行", // LcSubmoduleStashAndReset: "stash uncommitted submodule changes and update", // LcAndResetSubmodules: "and reset submodules", diff --git a/pkg/i18n/korean.go b/pkg/i18n/korean.go index b891d83c3..c191a436e 100644 --- a/pkg/i18n/korean.go +++ b/pkg/i18n/korean.go @@ -406,7 +406,7 @@ func koreanTranslationSet() TranslationSet { LcCreateNewBranchFromCommit: "커밋에서 새 브랜치를 만듭니다.", LcBuildingPatch: "building patch", LcViewCommits: "커밋 보기", - MinGitVersionError: "lazygit 실행을 위해서는 Git 2.0 이후의 버전(2014년 이후의)이 필요합니다. Git를 업데이트 해주세요. 아니면 lazygit이 이전 버전과 더 잘 호환되도록 https://github.com/jesseduffield/lazygit/issues 에 issue를 작성해 주세요.", + MinGitVersionError: "lazygit 실행을 위해서는 Git 2.20 이후의 버전(2018년 이후의)이 필요합니다. Git를 업데이트 해주세요. 아니면 lazygit이 이전 버전과 더 잘 호환되도록 https://github.com/jesseduffield/lazygit/issues 에 issue를 작성해 주세요.", LcRunningCustomCommandStatus: "커스텀 명령어 실행", LcSubmoduleStashAndReset: "stash uncommitted submodule changes and update", LcAndResetSubmodules: "and reset submodules", From 67b8ef449cf13ad7ac6dc52829331ad9803fefff Mon Sep 17 00:00:00 2001 From: Stefan Haller Date: Sat, 18 Feb 2023 16:12:41 +0100 Subject: [PATCH 2/3] Edit by breaking after current commit Instead of rebasing from the commit below the current one and then setting the current one to "edit", we rebase from the current one and insert a "break" after it. In most cases the behavior is exactly the same as before, except that the new method also works if the current commit is a merge commit. This is useful if you want to create a new commit at the very beginning of your branch (by editing the last commit before your branch). --- pkg/commands/git_commands/rebase.go | 16 +++++++++++++++- pkg/gui/controllers/local_commits_controller.go | 3 ++- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/pkg/commands/git_commands/rebase.go b/pkg/commands/git_commands/rebase.go index a99686220..66dbcf45f 100644 --- a/pkg/commands/git_commands/rebase.go +++ b/pkg/commands/git_commands/rebase.go @@ -117,6 +117,16 @@ func (self *RebaseCommands) InteractiveRebase(commits []*models.Commit, index in return self.PrepareInteractiveRebaseCommand(sha, todo, true).Run() } +func (self *RebaseCommands) InteractiveRebaseBreakAfter(commits []*models.Commit, index int) error { + todo, sha, err := self.BuildSingleActionTodo(commits, index-1, "pick") + if err != nil { + return err + } + + todo = append(todo, TodoLine{Action: "break", Commit: nil}) + return self.PrepareInteractiveRebaseCommand(sha, todo, 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 @@ -400,5 +410,9 @@ type TodoLine struct { } func (self *TodoLine) ToString() string { - return self.Action + " " + self.Commit.Sha + " " + self.Commit.Name + "\n" + if self.Action == "break" { + return self.Action + "\n" + } else { + return self.Action + " " + self.Commit.Sha + " " + self.Commit.Name + "\n" + } } diff --git a/pkg/gui/controllers/local_commits_controller.go b/pkg/gui/controllers/local_commits_controller.go index 3a9aff86b..a9fe7a190 100644 --- a/pkg/gui/controllers/local_commits_controller.go +++ b/pkg/gui/controllers/local_commits_controller.go @@ -298,7 +298,8 @@ func (self *LocalCommitsController) edit(commit *models.Commit) error { return self.c.WithWaitingStatus(self.c.Tr.RebasingStatus, func() error { self.c.LogAction(self.c.Tr.Actions.EditCommit) - return self.interactiveRebase("edit") + err := self.git.Rebase.InteractiveRebaseBreakAfter(self.model.Commits, self.context().GetSelectedLineIdx()) + return self.helpers.MergeAndRebase.CheckMergeOrRebase(err) }) } From ac9515d8c77dab0da87d913db6c2bdec3be6fe3c Mon Sep 17 00:00:00 2001 From: Stefan Haller Date: Sun, 19 Feb 2023 11:36:06 +0100 Subject: [PATCH 3/3] Revert "fix: improve backward compatibility" Since we now require git 2.20, we don't need this any more. This reverts commit 7c5f33980f541472aa29e4e072ace63358983308. --- pkg/commands/git.go | 2 +- pkg/commands/git_commands/tag_loader.go | 18 ++------- pkg/commands/git_commands/tag_loader_test.go | 39 +++----------------- 3 files changed, 11 insertions(+), 48 deletions(-) diff --git a/pkg/commands/git.go b/pkg/commands/git.go index e2a31c009..35cead260 100644 --- a/pkg/commands/git.go +++ b/pkg/commands/git.go @@ -133,7 +133,7 @@ func NewGitCommandAux( reflogCommitLoader := git_commands.NewReflogCommitLoader(cmn, cmd) remoteLoader := git_commands.NewRemoteLoader(cmn, cmd, repo.Remotes) stashLoader := git_commands.NewStashLoader(cmn, cmd) - tagLoader := git_commands.NewTagLoader(cmn, version, cmd) + tagLoader := git_commands.NewTagLoader(cmn, cmd) return &GitCommand{ Branch: branchCommands, diff --git a/pkg/commands/git_commands/tag_loader.go b/pkg/commands/git_commands/tag_loader.go index f9674a2b0..738283405 100644 --- a/pkg/commands/git_commands/tag_loader.go +++ b/pkg/commands/git_commands/tag_loader.go @@ -1,8 +1,6 @@ package git_commands import ( - "fmt" - "github.com/jesseduffield/generics/slices" "github.com/jesseduffield/lazygit/pkg/commands/models" "github.com/jesseduffield/lazygit/pkg/commands/oscommands" @@ -12,31 +10,23 @@ import ( type TagLoader struct { *common.Common - version *GitVersion - cmd oscommands.ICmdObjBuilder + cmd oscommands.ICmdObjBuilder } func NewTagLoader( common *common.Common, - version *GitVersion, cmd oscommands.ICmdObjBuilder, ) *TagLoader { return &TagLoader{ - Common: common, - version: version, - cmd: cmd, + Common: common, + cmd: cmd, } } func (self *TagLoader) GetTags() ([]*models.Tag, error) { // get remote branches, sorted by creation date (descending) // see: https://git-scm.com/docs/git-tag#Documentation/git-tag.txt---sortltkeygt - sortKey := "-creatordate" - if self.version.IsOlderThan(2, 7, 0) { - sortKey = "-v:refname" - } - - tagsOutput, err := self.cmd.New(fmt.Sprintf(`git tag --list --sort=%s`, sortKey)).DontLog().RunWithOutput() + tagsOutput, err := self.cmd.New(`git tag --list --sort=-creatordate`).DontLog().RunWithOutput() if err != nil { return nil, err } diff --git a/pkg/commands/git_commands/tag_loader_test.go b/pkg/commands/git_commands/tag_loader_test.go index 287d6e3c6..f8696cafa 100644 --- a/pkg/commands/git_commands/tag_loader_test.go +++ b/pkg/commands/git_commands/tag_loader_test.go @@ -20,7 +20,6 @@ testtag func TestGetTags(t *testing.T) { type scenario struct { testName string - gitVersion *GitVersion runner *oscommands.FakeCmdObjRunner expectedTags []*models.Tag expectedError error @@ -28,24 +27,14 @@ func TestGetTags(t *testing.T) { scenarios := []scenario{ { - testName: "should return no tags if there are none", - gitVersion: &GitVersion{2, 7, 0, ""}, + testName: "should return no tags if there are none", runner: oscommands.NewFakeRunner(t). Expect(`git tag --list --sort=-creatordate`, "", nil), expectedTags: []*models.Tag{}, expectedError: nil, }, { - testName: "should return no tags if there are none (< 2.7.0)", - gitVersion: &GitVersion{2, 6, 7, ""}, - runner: oscommands.NewFakeRunner(t). - Expect(`git tag --list --sort=-v:refname`, "", nil), - expectedTags: []*models.Tag{}, - expectedError: nil, - }, - { - testName: "should return tags if present", - gitVersion: &GitVersion{2, 7, 0, ""}, + testName: "should return tags if present", runner: oscommands.NewFakeRunner(t). Expect(`git tag --list --sort=-creatordate`, tagsOutput, nil), expectedTags: []*models.Tag{ @@ -58,31 +47,15 @@ func TestGetTags(t *testing.T) { }, expectedError: nil, }, - { - testName: "should return tags if present (< 2.7.0)", - gitVersion: &GitVersion{2, 6, 7, ""}, - runner: oscommands.NewFakeRunner(t). - Expect(`git tag --list --sort=-v:refname`, tagsOutput, nil), - expectedTags: []*models.Tag{ - {Name: "v0.34"}, - {Name: "v0.33"}, - {Name: "v0.32.2"}, - {Name: "v0.32.1"}, - {Name: "v0.32"}, - {Name: "testtag"}, - }, - expectedError: nil, - }, } for _, scenario := range scenarios { scenario := scenario t.Run(scenario.testName, func(t *testing.T) { - loader := NewTagLoader( - utils.NewDummyCommon(), - scenario.gitVersion, - oscommands.NewDummyCmdObjBuilder(scenario.runner), - ) + loader := &TagLoader{ + Common: utils.NewDummyCommon(), + cmd: oscommands.NewDummyCmdObjBuilder(scenario.runner), + } tags, err := loader.GetTags()