mirror of
https://github.com/pcottle/learnGitBranching.git
synced 2025-07-10 14:44:28 +02:00
Merge pull request #1035 from gatsbimantico/patch-1
Add support for `git merge --squash {branch}`
This commit is contained in:
commit
b2b2927c79
3 changed files with 23 additions and 5 deletions
|
@ -228,6 +228,13 @@ describe('Git', function() {
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('if squash is specified, will always make a squash merge commit', function() {
|
||||||
|
return expectTreeAsync(
|
||||||
|
'git commit; go -b side HEAD~1; git commit; git merge main; go main; git merge side --squash',
|
||||||
|
'{"branches":{"main":{"target":"C5","id":"main","remoteTrackingBranchID":null},"side":{"target":"C4","id":"side","remoteTrackingBranchID":null}},"commits":{"C0":{"parents":[],"id":"C0","rootCommit":true},"C1":{"parents":["C0"],"id":"C1"},"C2":{"parents":["C1"],"id":"C2"},"C3":{"parents":["C1"],"id":"C3"},"C4":{"parents":["C2","C3"],"id":"C4"},"C5":{"parents":["C2"],"id":"C5"}},"HEAD":{"target":"main","id":"HEAD"}}'
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
it('makes a tag', function() {
|
it('makes a tag', function() {
|
||||||
return expectTreeAsync(
|
return expectTreeAsync(
|
||||||
'git tag v1',
|
'git tag v1',
|
||||||
|
|
|
@ -559,16 +559,20 @@ var commandConfig = {
|
||||||
merge: {
|
merge: {
|
||||||
regex: /^git +merge($|\s)/,
|
regex: /^git +merge($|\s)/,
|
||||||
options: [
|
options: [
|
||||||
'--no-ff'
|
'--no-ff',
|
||||||
|
'--squash'
|
||||||
],
|
],
|
||||||
execute: function(engine, command) {
|
execute: function(engine, command) {
|
||||||
var commandOptions = command.getOptionsMap();
|
var commandOptions = command.getOptionsMap();
|
||||||
var generalArgs = command.getGeneralArgs().concat(commandOptions['--no-ff'] || []);
|
var generalArgs = command.getGeneralArgs().concat(commandOptions['--no-ff'] || []).concat(commandOptions['--squash'] || []);
|
||||||
command.validateArgBounds(generalArgs, 1, 1);
|
command.validateArgBounds(generalArgs, 1, 1);
|
||||||
|
|
||||||
var newCommit = engine.merge(
|
var newCommit = engine.merge(
|
||||||
generalArgs[0],
|
generalArgs[0],
|
||||||
{ noFF: !!commandOptions['--no-ff'] }
|
{
|
||||||
|
noFF: !!commandOptions['--no-ff'],
|
||||||
|
squash: !!commandOptions['--squash']
|
||||||
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
if (newCommit === undefined) {
|
if (newCommit === undefined) {
|
||||||
|
|
|
@ -2474,7 +2474,7 @@ GitEngine.prototype.merge = function(targetSource, options) {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.isUpstreamOf(currentLocation, targetSource) && !options.noFF) {
|
if (this.isUpstreamOf(currentLocation, targetSource) && !options.noFF && !options.squash) {
|
||||||
// just set the target of this current location to the source
|
// just set the target of this current location to the source
|
||||||
this.setTargetLocation(currentLocation, this.getCommitFromRef(targetSource));
|
this.setTargetLocation(currentLocation, this.getCommitFromRef(targetSource));
|
||||||
// get fresh animation to happen
|
// get fresh animation to happen
|
||||||
|
@ -2496,8 +2496,15 @@ GitEngine.prototype.merge = function(targetSource, options) {
|
||||||
);
|
);
|
||||||
// since we specify parent 1 as the first parent, it is the "main" parent
|
// since we specify parent 1 as the first parent, it is the "main" parent
|
||||||
// and the node will be displayed below that branch / commit / whatever
|
// and the node will be displayed below that branch / commit / whatever
|
||||||
|
var commitParents = [parent1];
|
||||||
|
|
||||||
|
if (!options.squash) {
|
||||||
|
// a squash commit doesn't include the reference to the second parent
|
||||||
|
commitParents.push(parent2);
|
||||||
|
}
|
||||||
|
|
||||||
var mergeCommit = this.makeCommit(
|
var mergeCommit = this.makeCommit(
|
||||||
[parent1, parent2],
|
commitParents,
|
||||||
null,
|
null,
|
||||||
{
|
{
|
||||||
commitMessage: msg
|
commitMessage: msg
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue