Skip to content

feat(switch), introduce "--force-ours" and "--force-theirs" flags #9048

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

Merged
merged 2 commits into from
Jul 17, 2024
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
20 changes: 20 additions & 0 deletions e2e/harmony/lanes/switch-lanes.e2e.ts
Original file line number Diff line number Diff line change
Expand Up @@ -384,4 +384,24 @@ describe('bit lane command', function () {
expect(bitmap.comp1.version).to.equal(firstSnap);
});
});
describe('switch with --force-ours', () => {
before(() => {
helper.scopeHelper.setNewLocalAndRemoteScopes();
helper.fixtures.populateComponents(1);
helper.command.tagAllWithoutBuild();
helper.command.export();
helper.command.createLane();
helper.fixtures.populateComponents(1, undefined, 'v2');
helper.command.snapAllComponentsWithoutBuild();
helper.command.export();
helper.command.switchLocalLane('main', '-x --force-ours');
});
it('should switch successfully', () => {
helper.command.expectCurrentLaneToBe('main');
});
it('should not change the files and keep them same as the lane', () => {
const fileContent = helper.fs.readFile('comp1/index.js');
expect(fileContent).to.include('v2');
});
});
});
15 changes: 14 additions & 1 deletion scopes/lanes/lanes/lanes.main.runtime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,8 @@ export type SwitchLaneOptions = {
head?: boolean;
alias?: string;
merge?: MergeStrategy;
forceOurs?: boolean;
forceTheirs?: boolean;
workspaceOnly?: boolean;
pattern?: string;
skipDependencyInstallation?: boolean;
Expand Down Expand Up @@ -562,7 +564,16 @@ please create a new lane instead, which will include all components of this lane
*/
async switchLanes(
laneName: string,
{ alias, merge, pattern, workspaceOnly, skipDependencyInstallation = false, head }: SwitchLaneOptions
{
alias,
merge,
forceOurs,
forceTheirs,
pattern,
workspaceOnly,
skipDependencyInstallation = false,
head,
}: SwitchLaneOptions
) {
if (!this.workspace) {
throw new BitError(`unable to switch lanes outside of Bit workspace`);
Expand All @@ -588,6 +599,8 @@ please create a new lane instead, which will include all components of this lane
};
const checkoutProps = {
mergeStrategy,
forceOurs,
forceTheirs,
skipNpmInstall: skipDependencyInstallation,
isLane: true,
promptMergeOptions: false,
Expand Down
8 changes: 8 additions & 0 deletions scopes/lanes/lanes/switch.cmd.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ export class SwitchCmd implements Command {
'auto-merge-resolve <merge-strategy>',
'merge local changes with the checked out version. strategy should be "theirs", "ours" or "manual"',
],
['', 'force-ours', 'do not merge, preserve local files as is'],
['', 'force-theirs', 'do not merge, just overwrite with incoming files'],
['a', 'get-all', 'DEPRECATED. this is currently the default behavior'],
['', 'workspace-only', 'checkout only the components in the workspace to the selected lane'],
['x', 'skip-dependency-installation', 'do not install dependencies of the imported components'],
Expand All @@ -50,6 +52,8 @@ ${COMPONENT_PATTERN_HELP}`,
head,
alias,
autoMergeResolve,
forceOurs,
forceTheirs,
getAll = false,
workspaceOnly = false,
skipDependencyInstallation = false,
Expand All @@ -59,6 +63,8 @@ ${COMPONENT_PATTERN_HELP}`,
head?: boolean;
alias?: string;
autoMergeResolve?: MergeStrategy;
forceOurs?: boolean;
forceTheirs?: boolean;
getAll?: boolean;
workspaceOnly?: boolean;
skipDependencyInstallation?: boolean;
Expand All @@ -71,6 +77,8 @@ ${COMPONENT_PATTERN_HELP}`,
head,
alias,
merge: autoMergeResolve,
forceOurs,
forceTheirs,
workspaceOnly,
pattern,
skipDependencyInstallation,
Expand Down