diff options
author | Stefan Haller <stefan@haller-berlin.de> | 2023-04-06 15:33:00 +0200 |
---|---|---|
committer | Stefan Haller <stefan@haller-berlin.de> | 2023-09-18 10:50:19 +0200 |
commit | a642395e9f7794e77eac350b063cb975a49ba6f4 (patch) | |
tree | 20d7c27a1142359aadfb695853c604080e0c1d1f /pkg/commands | |
parent | 70bfeddc907037d1aa6ae9fc869441f3429c388a (diff) |
Allow cherry-picking commits during a rebase
This can be useful when you know that a cherry-picked commit would conflict at
the tip of your branch, but doesn't at the beginning of the branch (or
somewhere in the middle). In that case you want to be able to edit the commit
before where you want to insert the cherry-picked commits, and then paste to
insert them into the todo list at that point.
Diffstat (limited to 'pkg/commands')
-rw-r--r-- | pkg/commands/git_commands/rebase.go | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/pkg/commands/git_commands/rebase.go b/pkg/commands/git_commands/rebase.go index 66adee2af..2dd1ee886 100644 --- a/pkg/commands/git_commands/rebase.go +++ b/pkg/commands/git_commands/rebase.go @@ -457,6 +457,20 @@ func (self *RebaseCommands) CherryPickCommits(commits []*models.Commit) error { }).Run() } +// CherryPickCommitsDuringRebase simply prepends the given commits to the existing git-rebase-todo file +func (self *RebaseCommands) CherryPickCommitsDuringRebase(commits []*models.Commit) error { + todoLines := lo.Map(commits, func(commit *models.Commit, _ int) daemon.TodoLine { + return daemon.TodoLine{ + Action: "pick", + Commit: commit, + } + }) + + todo := daemon.TodoLinesToString(todoLines) + filePath := filepath.Join(self.repoPaths.worktreeGitDirPath, "rebase-merge/git-rebase-todo") + return utils.PrependStrToTodoFile(filePath, []byte(todo)) +} + // we can't start an interactive rebase from the first commit without passing the // '--root' arg func getBaseShaOrRoot(commits []*models.Commit, index int) string { |