Skip to content

Commit

Permalink
feat: add commit to squash
Browse files Browse the repository at this point in the history
fix: type and rename files

add refresh

remove current branch in squashFiles tooltip
  • Loading branch information
noahfraiture committed May 19, 2024
1 parent a01befd commit 49b760e
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 8 deletions.
7 changes: 7 additions & 0 deletions pkg/commands/git_commands/commit.go
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,13 @@ func (self *CommitCommands) CreateAmendCommit(originalSubject, newSubject, newDe
return self.cmd.New(cmdArgs).Run()
}

func (self *CommitCommands) CreateSquashCommit(checkedOutBranch, selectedBranch string) error {
cmdArgs := NewGitCmd("commit").
Arg("-m", fmt.Sprintf("Squash branch %s into %s", selectedBranch, checkedOutBranch)).
ToArgv()
return self.cmd.New(cmdArgs).Run()
}

// a value of 0 means the head commit, 1 is the parent commit, etc
func (self *CommitCommands) GetCommitMessageFromHistory(value int) (string, error) {
cmdArgs := NewGitCmd("log").Arg("-1", fmt.Sprintf("--skip=%d", value), "--pretty=%H").
Expand Down
18 changes: 12 additions & 6 deletions pkg/gui/controllers/helpers/merge_and_rebase_helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -330,12 +330,11 @@ func (self *MergeAndRebaseHelper) SquashBranch(refName string) error {
Items: []*types.MenuItem{
{
Label: self.c.Tr.SquashInFilesTitle,
OnPress: self.SquashRefIntoWorkingTree(refName),
OnPress: self.SquashInFiles(refName),
Key: 's',
Tooltip: utils.ResolvePlaceholderString(
self.c.Tr.SquashInFiles,
map[string]string{
"checkOutBranch": self.refsHelper.GetCheckedOutRef().Name,
"selectedBranch": refName,
},
),
Expand All @@ -347,16 +346,16 @@ func (self *MergeAndRebaseHelper) SquashBranch(refName string) error {
Tooltip: utils.ResolvePlaceholderString(
self.c.Tr.SquashInCommit,
map[string]string{
"checkOutBranch": self.refsHelper.GetCheckedOutRef().Name,
"selectedBranch": refName,
"checkedOutBranch": self.refsHelper.GetCheckedOutRef().Name,
"selectedBranch": refName,
},
),
},
},
})
}

func (self *MergeAndRebaseHelper) SquashRefIntoWorkingTree(refName string) func() error {
func (self *MergeAndRebaseHelper) SquashInFiles(refName string) func() error {
checkedOutBranchName := self.refsHelper.GetCheckedOutRef().Name
if checkedOutBranchName == refName {
return func() error { return errors.New(self.c.Tr.CantMergeBranchIntoItself) }
Expand All @@ -378,7 +377,14 @@ func (self *MergeAndRebaseHelper) SquashIntoNewCommit(refName string) func() err
return func() error {
self.c.LogAction(self.c.Tr.Actions.SquashBranch)
err := self.c.Git().Branch.Merge(refName, git_commands.MergeOpts{Squash: true})
return self.CheckMergeOrRebase(err)
if err = self.CheckMergeOrRebase(err); err != nil {
return err
}
err = self.c.Git().Commit.CreateSquashCommit(refName, checkedOutBranchName)
if err != nil {
return err
}
return self.c.Refresh(types.RefreshOptions{Mode: types.ASYNC})
}
}

Expand Down
4 changes: 2 additions & 2 deletions pkg/i18n/english.go
Original file line number Diff line number Diff line change
Expand Up @@ -1267,8 +1267,8 @@ func EnglishTranslationSet() TranslationSet {
InteractiveRebaseTooltip: "Begin an interactive rebase with a break at the start, so you can update the TODO commits before continuing.",
MustSelectTodoCommits: "When rebasing, this action only works on a selection of TODO commits.",
ConfirmMerge: "Are you sure you want to merge '{{.selectedBranch}}' into '{{.checkedOutBranch}}'?",
SquashInFiles: "Are you sure you want to squash '{{.selectedBranch}}' into '{{.checkedOutBranch}}'?",
SquashInCommit: "Are you sure you want to squash '{{.selectedBranch}}' into '{{.checkedOutBranch}}'?",
SquashInFiles: "Are you sure you want to squash '{{.selectedBranch}}' into current working tree?",
SquashInCommit: "Are you sure you want to squash '{{.selectedBranch}}' into '{{.checkedOutBranch}}' in a new commit?",
FwdNoUpstream: "Cannot fast-forward a branch with no upstream",
FwdNoLocalUpstream: "Cannot fast-forward a branch whose remote is not registered locally",
FwdCommitsToPush: "Cannot fast-forward a branch with commits to push",
Expand Down

0 comments on commit 49b760e

Please sign in to comment.