mirror of
https://github.com/jesseduffield/lazygit.git
synced 2025-07-17 01:42:45 +02:00
Merge pull request #2451 from stefanhaller/edit-by-breaking-after-current-commit
This commit is contained in:
@ -123,7 +123,7 @@ func (app *App) validateGitVersion() (*git_commands.GitVersion, error) {
|
|||||||
return nil, minVersionError
|
return nil, minVersionError
|
||||||
}
|
}
|
||||||
|
|
||||||
if version.IsOlderThan(2, 0, 0) {
|
if version.IsOlderThan(2, 20, 0) {
|
||||||
return nil, minVersionError
|
return nil, minVersionError
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -133,7 +133,7 @@ func NewGitCommandAux(
|
|||||||
reflogCommitLoader := git_commands.NewReflogCommitLoader(cmn, cmd)
|
reflogCommitLoader := git_commands.NewReflogCommitLoader(cmn, cmd)
|
||||||
remoteLoader := git_commands.NewRemoteLoader(cmn, cmd, repo.Remotes)
|
remoteLoader := git_commands.NewRemoteLoader(cmn, cmd, repo.Remotes)
|
||||||
stashLoader := git_commands.NewStashLoader(cmn, cmd)
|
stashLoader := git_commands.NewStashLoader(cmn, cmd)
|
||||||
tagLoader := git_commands.NewTagLoader(cmn, version, cmd)
|
tagLoader := git_commands.NewTagLoader(cmn, cmd)
|
||||||
|
|
||||||
return &GitCommand{
|
return &GitCommand{
|
||||||
Branch: branchCommands,
|
Branch: branchCommands,
|
||||||
|
@ -117,6 +117,16 @@ func (self *RebaseCommands) InteractiveRebase(commits []*models.Commit, index in
|
|||||||
return self.PrepareInteractiveRebaseCommand(sha, todo, true).Run()
|
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
|
// PrepareInteractiveRebaseCommand returns the cmd for an interactive rebase
|
||||||
// we tell git to run lazygit to edit the todo list, and we pass the client
|
// 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
|
// lazygit a todo string to write to the todo file
|
||||||
@ -400,5 +410,9 @@ type TodoLine struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (self *TodoLine) ToString() string {
|
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"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,8 +1,6 @@
|
|||||||
package git_commands
|
package git_commands
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
|
||||||
|
|
||||||
"github.com/jesseduffield/generics/slices"
|
"github.com/jesseduffield/generics/slices"
|
||||||
"github.com/jesseduffield/lazygit/pkg/commands/models"
|
"github.com/jesseduffield/lazygit/pkg/commands/models"
|
||||||
"github.com/jesseduffield/lazygit/pkg/commands/oscommands"
|
"github.com/jesseduffield/lazygit/pkg/commands/oscommands"
|
||||||
@ -12,31 +10,23 @@ import (
|
|||||||
|
|
||||||
type TagLoader struct {
|
type TagLoader struct {
|
||||||
*common.Common
|
*common.Common
|
||||||
version *GitVersion
|
cmd oscommands.ICmdObjBuilder
|
||||||
cmd oscommands.ICmdObjBuilder
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewTagLoader(
|
func NewTagLoader(
|
||||||
common *common.Common,
|
common *common.Common,
|
||||||
version *GitVersion,
|
|
||||||
cmd oscommands.ICmdObjBuilder,
|
cmd oscommands.ICmdObjBuilder,
|
||||||
) *TagLoader {
|
) *TagLoader {
|
||||||
return &TagLoader{
|
return &TagLoader{
|
||||||
Common: common,
|
Common: common,
|
||||||
version: version,
|
cmd: cmd,
|
||||||
cmd: cmd,
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (self *TagLoader) GetTags() ([]*models.Tag, error) {
|
func (self *TagLoader) GetTags() ([]*models.Tag, error) {
|
||||||
// get remote branches, sorted by creation date (descending)
|
// get remote branches, sorted by creation date (descending)
|
||||||
// see: https://git-scm.com/docs/git-tag#Documentation/git-tag.txt---sortltkeygt
|
// see: https://git-scm.com/docs/git-tag#Documentation/git-tag.txt---sortltkeygt
|
||||||
sortKey := "-creatordate"
|
tagsOutput, err := self.cmd.New(`git tag --list --sort=-creatordate`).DontLog().RunWithOutput()
|
||||||
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()
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -20,7 +20,6 @@ testtag
|
|||||||
func TestGetTags(t *testing.T) {
|
func TestGetTags(t *testing.T) {
|
||||||
type scenario struct {
|
type scenario struct {
|
||||||
testName string
|
testName string
|
||||||
gitVersion *GitVersion
|
|
||||||
runner *oscommands.FakeCmdObjRunner
|
runner *oscommands.FakeCmdObjRunner
|
||||||
expectedTags []*models.Tag
|
expectedTags []*models.Tag
|
||||||
expectedError error
|
expectedError error
|
||||||
@ -28,24 +27,14 @@ func TestGetTags(t *testing.T) {
|
|||||||
|
|
||||||
scenarios := []scenario{
|
scenarios := []scenario{
|
||||||
{
|
{
|
||||||
testName: "should return no tags if there are none",
|
testName: "should return no tags if there are none",
|
||||||
gitVersion: &GitVersion{2, 7, 0, ""},
|
|
||||||
runner: oscommands.NewFakeRunner(t).
|
runner: oscommands.NewFakeRunner(t).
|
||||||
Expect(`git tag --list --sort=-creatordate`, "", nil),
|
Expect(`git tag --list --sort=-creatordate`, "", nil),
|
||||||
expectedTags: []*models.Tag{},
|
expectedTags: []*models.Tag{},
|
||||||
expectedError: nil,
|
expectedError: nil,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
testName: "should return no tags if there are none (< 2.7.0)",
|
testName: "should return tags if present",
|
||||||
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, ""},
|
|
||||||
runner: oscommands.NewFakeRunner(t).
|
runner: oscommands.NewFakeRunner(t).
|
||||||
Expect(`git tag --list --sort=-creatordate`, tagsOutput, nil),
|
Expect(`git tag --list --sort=-creatordate`, tagsOutput, nil),
|
||||||
expectedTags: []*models.Tag{
|
expectedTags: []*models.Tag{
|
||||||
@ -58,31 +47,15 @@ func TestGetTags(t *testing.T) {
|
|||||||
},
|
},
|
||||||
expectedError: nil,
|
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 {
|
for _, scenario := range scenarios {
|
||||||
scenario := scenario
|
scenario := scenario
|
||||||
t.Run(scenario.testName, func(t *testing.T) {
|
t.Run(scenario.testName, func(t *testing.T) {
|
||||||
loader := NewTagLoader(
|
loader := &TagLoader{
|
||||||
utils.NewDummyCommon(),
|
Common: utils.NewDummyCommon(),
|
||||||
scenario.gitVersion,
|
cmd: oscommands.NewDummyCmdObjBuilder(scenario.runner),
|
||||||
oscommands.NewDummyCmdObjBuilder(scenario.runner),
|
}
|
||||||
)
|
|
||||||
|
|
||||||
tags, err := loader.GetTags()
|
tags, err := loader.GetTags()
|
||||||
|
|
||||||
|
@ -298,7 +298,8 @@ func (self *LocalCommitsController) edit(commit *models.Commit) error {
|
|||||||
|
|
||||||
return self.c.WithWaitingStatus(self.c.Tr.RebasingStatus, func() error {
|
return self.c.WithWaitingStatus(self.c.Tr.RebasingStatus, func() error {
|
||||||
self.c.LogAction(self.c.Tr.Actions.EditCommit)
|
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)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -395,7 +395,7 @@ func chineseTranslationSet() TranslationSet {
|
|||||||
LcCreateNewBranchFromCommit: "从提交创建新分支",
|
LcCreateNewBranchFromCommit: "从提交创建新分支",
|
||||||
LcBuildingPatch: "正在构建补丁",
|
LcBuildingPatch: "正在构建补丁",
|
||||||
LcViewCommits: "查看提交",
|
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: "正在运行自定义命令",
|
LcRunningCustomCommandStatus: "正在运行自定义命令",
|
||||||
LcSubmoduleStashAndReset: "存放未提交的子模块更改和更新",
|
LcSubmoduleStashAndReset: "存放未提交的子模块更改和更新",
|
||||||
LcAndResetSubmodules: "和重置子模块",
|
LcAndResetSubmodules: "和重置子模块",
|
||||||
|
@ -1072,7 +1072,7 @@ func EnglishTranslationSet() TranslationSet {
|
|||||||
LcCreateNewBranchFromCommit: "create new branch off of commit",
|
LcCreateNewBranchFromCommit: "create new branch off of commit",
|
||||||
LcBuildingPatch: "building patch",
|
LcBuildingPatch: "building patch",
|
||||||
LcViewCommits: "view commits",
|
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",
|
LcRunningCustomCommandStatus: "running custom command",
|
||||||
LcSubmoduleStashAndReset: "stash uncommitted submodule changes and update",
|
LcSubmoduleStashAndReset: "stash uncommitted submodule changes and update",
|
||||||
LcAndResetSubmodules: "and reset submodules",
|
LcAndResetSubmodules: "and reset submodules",
|
||||||
|
@ -405,7 +405,7 @@ func japaneseTranslationSet() TranslationSet {
|
|||||||
LcCreateNewBranchFromCommit: "コミットにブランチを作成",
|
LcCreateNewBranchFromCommit: "コミットにブランチを作成",
|
||||||
LcBuildingPatch: "パッチを構築",
|
LcBuildingPatch: "パッチを構築",
|
||||||
LcViewCommits: "コミットを閲覧",
|
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: "カスタムコマンドを実行",
|
LcRunningCustomCommandStatus: "カスタムコマンドを実行",
|
||||||
// LcSubmoduleStashAndReset: "stash uncommitted submodule changes and update",
|
// LcSubmoduleStashAndReset: "stash uncommitted submodule changes and update",
|
||||||
// LcAndResetSubmodules: "and reset submodules",
|
// LcAndResetSubmodules: "and reset submodules",
|
||||||
|
@ -406,7 +406,7 @@ func koreanTranslationSet() TranslationSet {
|
|||||||
LcCreateNewBranchFromCommit: "커밋에서 새 브랜치를 만듭니다.",
|
LcCreateNewBranchFromCommit: "커밋에서 새 브랜치를 만듭니다.",
|
||||||
LcBuildingPatch: "building patch",
|
LcBuildingPatch: "building patch",
|
||||||
LcViewCommits: "커밋 보기",
|
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: "커스텀 명령어 실행",
|
LcRunningCustomCommandStatus: "커스텀 명령어 실행",
|
||||||
LcSubmoduleStashAndReset: "stash uncommitted submodule changes and update",
|
LcSubmoduleStashAndReset: "stash uncommitted submodule changes and update",
|
||||||
LcAndResetSubmodules: "and reset submodules",
|
LcAndResetSubmodules: "and reset submodules",
|
||||||
|
Reference in New Issue
Block a user