Skip to content
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

fix(lane-merge), avoid squashing if the distance between the current-lane and the other lane is 1 #7791

Merged
merged 3 commits into from
Aug 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions e2e/harmony/lanes/merge-lanes.e2e.ts
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,25 @@ describe('merge lanes', function () {
expect(log[1].parents[0]).to.equal(headOnMain);
});
});
describe('merge with squash when other lane is ahead by only 1 snap, so no need to squash', () => {
let headOnLane: string;
before(() => {
helper.scopeHelper.setNewLocalAndRemoteScopes();
helper.fixtures.populateComponents(1);
helper.command.tagAllWithoutBuild();
helper.command.export();
helper.command.createLane('dev');
helper.command.snapAllComponentsWithoutBuild('--unmodified');
headOnLane = helper.command.getHeadOfLane('dev', 'comp1');
helper.command.switchLocalLane('main');
helper.command.mergeLane('dev');
});
it('should not add the squashed prop into the version object', () => {
const head = helper.command.catComponent(`comp1@${headOnLane}`);
expect(head).to.not.have.property('squashed');
expect(head.modified).to.have.lengthOf(0);
});
});
describe('merge with squash after exporting and importing the lane to a new workspace', () => {
before(() => {
helper.scopeHelper.setNewLocalAndRemoteScopes();
Expand Down
13 changes: 6 additions & 7 deletions scopes/lanes/merge-lanes/merge-lanes.main.runtime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -775,18 +775,17 @@ alternatively, use "--no-squash" flag to keep the entire history of "${otherLane
.join('\n');
return `${messageTitle}\n${allMessageStr}`;
};
// no need to check this case. even if it has only one snap ahead, we want to do the "squash", and run "addAsOnlyParent"
// to make sure it doesn't not have two parents.
// if (remoteSnaps.length === 1) {
// // nothing to squash. it has only one commit.
// return;
// }
if (!componentFromModel) {
throw new Error('unable to squash, the componentFromModel is missing');
}

const currentParents = componentFromModel.parents;

// if the remote has only one snap, there is nothing to squash.
// other checks here is to make sure `componentFromModel.addAsOnlyParent` call is not needed.
if (remoteSnaps.length === 1 && divergeData.commonSnapBeforeDiverge && currentParents.length === 1) {
return undefined;
}

const doSquash = async () => {
if (divergeData.commonSnapBeforeDiverge) {
componentFromModel.addAsOnlyParent(divergeData.commonSnapBeforeDiverge);
Expand Down