diff options
author | Peter Lundberg <peter.lundberg@soundtrackyourbrand.com> | 2019-04-07 01:10:58 +0200 |
---|---|---|
committer | Jesse Duffield <jessedduffield@gmail.com> | 2019-04-10 17:17:31 +1000 |
commit | 7ff07e145474b1ef3465db94dd57c0aa82353bfb (patch) | |
tree | ec0cf331bdd69929972391a7f4c58d3993ddf64f /pkg | |
parent | 3e779bca8d2cf37b7beeca6f49d64dacce7a65c3 (diff) |
Always include atleast 2 commits when doing squash and fixup
Diffstat (limited to 'pkg')
-rw-r--r-- | pkg/commands/git.go | 38 | ||||
-rw-r--r-- | pkg/i18n/dutch.go | 3 | ||||
-rw-r--r-- | pkg/i18n/english.go | 3 | ||||
-rw-r--r-- | pkg/i18n/polish.go | 3 |
4 files changed, 32 insertions, 15 deletions
diff --git a/pkg/commands/git.go b/pkg/commands/git.go index 9024e1479..e3fe4ba74 100644 --- a/pkg/commands/git.go +++ b/pkg/commands/git.go @@ -613,12 +613,12 @@ func (c *GitCommand) GenericMerge(commandType string, command string) error { } func (c *GitCommand) RewordCommit(commits []*Commit, index int) (*exec.Cmd, error) { - todo, err := c.GenerateGenericRebaseTodo(commits, index, "reword") + todo, sha, err := c.GenerateGenericRebaseTodo(commits, index, "reword") if err != nil { return nil, err } - return c.PrepareInteractiveRebaseCommand(commits[index+1].Sha, todo, false) + return c.PrepareInteractiveRebaseCommand(sha, todo, false) } func (c *GitCommand) MoveCommitDown(commits []*Commit, index int) error { @@ -643,12 +643,12 @@ func (c *GitCommand) MoveCommitDown(commits []*Commit, index int) error { } func (c *GitCommand) InteractiveRebase(commits []*Commit, index int, action string) error { - todo, err := c.GenerateGenericRebaseTodo(commits, index, action) + todo, sha, err := c.GenerateGenericRebaseTodo(commits, index, action) if err != nil { return err } - cmd, err := c.PrepareInteractiveRebaseCommand(commits[index+1].Sha, todo, true) + cmd, err := c.PrepareInteractiveRebaseCommand(sha, todo, true) if err != nil { return err } @@ -702,21 +702,31 @@ func (c *GitCommand) SoftReset(baseSha string) error { return c.OSCommand.RunCommand("git reset --soft " + baseSha) } -func (c *GitCommand) GenerateGenericRebaseTodo(commits []*Commit, index int, action string) (string, error) { - if len(commits) <= index+1 { - // assuming they aren't picking the bottom commit - return "", errors.New(c.Tr.SLocalize("CannotRebaseOntoFirstCommit")) +func (c *GitCommand) GenerateGenericRebaseTodo(commits []*Commit, actionIndex int, action string) (string, string, error) { + baseIndex := actionIndex + 1 + + if len(commits) <= baseIndex { + return "", "", errors.New(c.Tr.SLocalize("CannotRebaseOntoFirstCommit")) + } + + if action == "squash" || action == "fixup" { + baseIndex++ + + if len(commits) <= baseIndex { + return "", "", errors.New(c.Tr.SLocalize("CannotSquashOntoSecondCommit")) + } } todo := "" - for i, commit := range commits[0 : index+1] { + for i, commit := range commits[0:baseIndex] { a := "pick" - if i == index { + if i == actionIndex { a = action } todo = a + " " + commit.Sha + " " + commit.Name + "\n" + todo } - return todo, nil + + return todo, commits[baseIndex].Sha, nil } // AmendTo amends the given commit with whatever files are staged @@ -845,14 +855,12 @@ func (c *GitCommand) DiscardOldFileChanges(commits []*Commit, commitIndex int, f return errors.New(c.Tr.SLocalize("DisabledForGPG")) } - commitSha := commits[commitIndex].Sha - - todo, err := c.GenerateGenericRebaseTodo(commits, commitIndex, "edit") + todo, sha, err := c.GenerateGenericRebaseTodo(commits, commitIndex, "edit") if err != nil { return err } - cmd, err := c.PrepareInteractiveRebaseCommand(commitSha+"^", todo, true) + cmd, err := c.PrepareInteractiveRebaseCommand(sha+"^", todo, true) if err != nil { return err } diff --git a/pkg/i18n/dutch.go b/pkg/i18n/dutch.go index a7c6efd23..3da767bf3 100644 --- a/pkg/i18n/dutch.go +++ b/pkg/i18n/dutch.go @@ -566,6 +566,9 @@ func addDutch(i18nObject *i18n.Bundle) error { ID: "CannotRebaseOntoFirstCommit", Other: "You cannot interactive rebase onto the first commit", }, &i18n.Message{ + ID: "CannotSquashOntoSecondCommit", + Other: "You cannot squash/fixup onto the second commit", + }, &i18n.Message{ ID: "Donate", Other: "Donate", }, &i18n.Message{ diff --git a/pkg/i18n/english.go b/pkg/i18n/english.go index b64cc582f..3b61ac3a7 100644 --- a/pkg/i18n/english.go +++ b/pkg/i18n/english.go @@ -589,6 +589,9 @@ func addEnglish(i18nObject *i18n.Bundle) error { ID: "CannotRebaseOntoFirstCommit", Other: "You cannot interactive rebase onto the first commit", }, &i18n.Message{ + ID: "CannotSquashOntoSecondCommit", + Other: "You cannot squash/fixup onto the second commit", + }, &i18n.Message{ ID: "Donate", Other: "Donate", }, &i18n.Message{ diff --git a/pkg/i18n/polish.go b/pkg/i18n/polish.go index fc17323b9..372f4c090 100644 --- a/pkg/i18n/polish.go +++ b/pkg/i18n/polish.go @@ -549,6 +549,9 @@ func addPolish(i18nObject *i18n.Bundle) error { ID: "CannotRebaseOntoFirstCommit", Other: "You cannot interactive rebase onto the first commit", }, &i18n.Message{ + ID: "CannotSquashOntoSecondCommit", + Other: "You cannot squash/fixup onto the second commit", + }, &i18n.Message{ ID: "Donate", Other: "Donate", }, &i18n.Message{ |