-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add squash merge support #3130
Add squash merge support #3130
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -309,6 +309,30 @@ func (self *MergeAndRebaseHelper) MergeRefIntoCheckedOutBranch(refName string) e | |
}) | ||
} | ||
|
||
func (self *MergeAndRebaseHelper) SquashRefIntoWorkingTree(refName string) error { | ||
checkedOutBranchName := self.refsHelper.GetCheckedOutRef().Name | ||
if checkedOutBranchName == refName { | ||
return self.c.ErrorMsg(self.c.Tr.CantMergeBranchIntoItself) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Our new way of dealing with situations like this is to set a |
||
} | ||
|
||
prompt := utils.ResolvePlaceholderString( | ||
self.c.Tr.ConfirmSquash, | ||
map[string]string{ | ||
"selectedBranch": refName, | ||
}, | ||
) | ||
|
||
return self.c.Confirm(types.ConfirmOpts{ | ||
Title: self.c.Tr.SquashConfirmTitle, | ||
Prompt: prompt, | ||
HandleConfirm: 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) | ||
}, | ||
}) | ||
} | ||
|
||
func (self *MergeAndRebaseHelper) ResetMarkedBaseCommit() error { | ||
self.c.Modes().MarkedBaseCommit.Reset() | ||
return self.c.PostRefreshUpdate(self.c.Contexts().LocalCommits) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be good to check that FastForwardOnly and Squash aren't both true, because that combination doesn't work. (I think it would be appropriate to panic in that case, as that's a programming error; like an
assert
in other languages.)Also, it would be good to also add
--ff
if Squash is true, because it doesn't work otherwise. Yes, that's the default, but people might havemerge.ff false
in their git config (I do), in which case the command would fail. Now you might argue that this is a bug in git (--squash
should imply--ff
), but if we can easily work around it, we should.And finally, we have tests for this function (in
branch_test.go
), would be good to extend these for the new option.