diff options
author | Stefan Haller <stefan@haller-berlin.de> | 2023-06-11 08:08:55 +0200 |
---|---|---|
committer | Stefan Haller <stefan@haller-berlin.de> | 2023-07-31 08:41:41 +0200 |
commit | 66de981e9108c83ddb1d778eb92e948050c85311 (patch) | |
tree | fcc5c35ee5909cd71157c331ef10beb200fe05ee /pkg/commands | |
parent | 375451785c2f72da368e0cafaff9dc2e9f40a5b4 (diff) |
Add a "Mark commit as base commit for rebase" command
This allows to do the equivalent of "git rebase --onto <target> <base>", by
first marking the <base> commit with the new command, and then selecting the
target branch and invoking the usual rebase command there.
Diffstat (limited to 'pkg/commands')
-rw-r--r-- | pkg/commands/git_commands/rebase.go | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/pkg/commands/git_commands/rebase.go b/pkg/commands/git_commands/rebase.go index 83c3fbe09..d491b6f5e 100644 --- a/pkg/commands/git_commands/rebase.go +++ b/pkg/commands/git_commands/rebase.go @@ -156,6 +156,15 @@ func (self *RebaseCommands) EditRebase(branchRef string) error { }).Run() } +func (self *RebaseCommands) EditRebaseFromBaseCommit(targetBranchName string, baseCommit string) error { + self.os.LogCommand(fmt.Sprintf("Beginning interactive rebase from '%s' onto '%s", baseCommit, targetBranchName), false) + return self.PrepareInteractiveRebaseCommand(PrepareInteractiveRebaseCommandOpts{ + baseShaOrRoot: baseCommit, + onto: targetBranchName, + instruction: daemon.NewInsertBreakInstruction(), + }).Run() +} + func logTodoChanges(changes []daemon.ChangeTodoAction) string { changeTodoStr := strings.Join(lo.Map(changes, func(c daemon.ChangeTodoAction, _ int) string { return fmt.Sprintf("%s:%s", c.Sha, c.NewAction) @@ -165,6 +174,7 @@ func logTodoChanges(changes []daemon.ChangeTodoAction) string { type PrepareInteractiveRebaseCommandOpts struct { baseShaOrRoot string + onto string instruction daemon.Instruction overrideEditor bool keepCommitsThatBecomeEmpty bool @@ -183,6 +193,7 @@ func (self *RebaseCommands) PrepareInteractiveRebaseCommand(opts PrepareInteract ArgIf(opts.keepCommitsThatBecomeEmpty && !self.version.IsOlderThan(2, 26, 0), "--empty=keep"). Arg("--no-autosquash"). ArgIf(!self.version.IsOlderThan(2, 22, 0), "--rebase-merges"). + ArgIf(opts.onto != "", "--onto", opts.onto). Arg(opts.baseShaOrRoot). ToArgv() @@ -306,6 +317,13 @@ func (self *RebaseCommands) RebaseBranch(branchName string) error { return self.PrepareInteractiveRebaseCommand(PrepareInteractiveRebaseCommandOpts{baseShaOrRoot: branchName}).Run() } +func (self *RebaseCommands) RebaseBranchFromBaseCommit(targetBranchName string, baseCommit string) error { + return self.PrepareInteractiveRebaseCommand(PrepareInteractiveRebaseCommandOpts{ + baseShaOrRoot: baseCommit, + onto: targetBranchName, + }).Run() +} + func (self *RebaseCommands) GenericMergeOrRebaseActionCmdObj(commandType string, command string) oscommands.ICmdObj { cmdArgs := NewGitCmd(commandType).Arg("--" + command).ToArgv() |