From a8858cbd12bd2ef5766f2436a7d43e4ff1c4ca9f Mon Sep 17 00:00:00 2001 From: Jesse Duffield Duffield Date: Sun, 24 Feb 2019 13:51:52 +1100 Subject: support cherry picking commits --- pkg/commands/commit.go | 12 +++++++++++- pkg/commands/git.go | 15 +++++++++++++++ 2 files changed, 26 insertions(+), 1 deletion(-) (limited to 'pkg/commands') diff --git a/pkg/commands/commit.go b/pkg/commands/commit.go index 1df6afbd0..4253a5495 100644 --- a/pkg/commands/commit.go +++ b/pkg/commands/commit.go @@ -12,6 +12,7 @@ type Commit struct { Status string // one of "unpushed", "pushed", "merged", or "rebasing" DisplayString string Action string // one of "", "pick", "edit", "squash", "reword", "drop", "fixup" + Copied bool // to know if this commit is ready to be cherry-picked somewhere } // GetDisplayStrings is a function. @@ -19,9 +20,14 @@ func (c *Commit) GetDisplayStrings(isFocused bool) []string { red := color.New(color.FgRed) yellow := color.New(color.FgYellow) green := color.New(color.FgGreen) - white := color.New(color.FgWhite) blue := color.New(color.FgBlue) cyan := color.New(color.FgCyan) + white := color.New(color.FgWhite) + + // for some reason, setting the background to blue pads out the other commits + // horizontally. For the sake of accessibility I'm considering this a feature, + // not a bug + copied := color.New(color.FgCyan, color.BgBlue) var shaColor *color.Color switch c.Status { @@ -37,6 +43,10 @@ func (c *Commit) GetDisplayStrings(isFocused bool) []string { shaColor = white } + if c.Copied { + shaColor = copied + } + actionString := "" if c.Action != "" { actionString = cyan.Sprint(utils.WithPadding(c.Action, 7)) + " " diff --git a/pkg/commands/git.go b/pkg/commands/git.go index 7b2c2f2fa..7127a427e 100644 --- a/pkg/commands/git.go +++ b/pkg/commands/git.go @@ -745,3 +745,18 @@ func (c *GitCommand) MoveTodoDown(index int) error { func (c *GitCommand) Revert(sha string) error { return c.OSCommand.RunCommand(fmt.Sprintf("git revert %s", sha)) } + +// CherryPickShas begins an interactive rebase with the given shas being cherry picked onto HEAD +func (c *GitCommand) CherryPickShas(shas []string) error { + todo := "" + for _, sha := range shas { + todo = "pick " + sha + "\n" + todo + } + + cmd, err := c.PrepareInteractiveRebaseCommand("HEAD", todo, false) + if err != nil { + return err + } + + return c.OSCommand.RunPreparedCommand(cmd) +} -- cgit v1.2.3