Skip to content
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
23 changes: 21 additions & 2 deletions packages/contentstack-branches/src/branch/merge-handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import os from 'os';
import path from 'path';
import forEach from 'lodash/forEach';
import { cliux } from '@contentstack/cli-utilities';
import chalk from 'chalk';
import { MergeInputOptions, MergeSummary } from '../interfaces';
import {
selectMergeStrategy,
Expand Down Expand Up @@ -107,6 +108,10 @@ export default class MergeHandler {
deleted: [],
};
const selectedItems = await selectCustomPreferences(module, this.branchCompareData[module]);
if (!selectedItems.length) {
cliux.print(chalk.red('No items were selected'));
process.exit(1);
}
forEach(selectedItems, (item) => {
this.mergeSettings.mergeContent[module][item.status].push(item.value);
this.mergeSettings.itemMergeStrategies.push(item.value);
Expand All @@ -132,8 +137,11 @@ export default class MergeHandler {
} else if (this.strategy === 'overwrite_with_compare') {
this.mergeSettings.strategy = 'overwrite_with_compare';
}

await this.displayMergeSummary();
if (this.checkEmptySelection()) {
cliux.print(chalk.red('No items selected'));
} else {
await this.displayMergeSummary();
}

if (!this.executeOption) {
const executionResponse = await selectMergeExecution();
Expand All @@ -152,6 +160,17 @@ export default class MergeHandler {
}
}

checkEmptySelection() {
for (let module in this.branchCompareData) {
if (this.mergeSettings.mergeContent[module]?.modified?.length
|| this.mergeSettings.mergeContent[module]?.added?.length
|| this.mergeSettings.mergeContent[module]?.deleted?.length) {
return false;
}
}
return true;
}

displayMergeSummary() {
if (this.mergeSettings.strategy !== 'ignore') {
for (let module in this.branchCompareData) {
Expand Down
1 change: 1 addition & 0 deletions packages/contentstack-branches/src/interfaces/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export interface BranchDiffRes {
title: string;
type: string;
status: string;
merge_strategy?: string;
}

export interface BranchDiffSummary {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -196,15 +196,21 @@ function printCompactTextView(branchTextRes: BranchCompactTextRes): void {
if (branchTextRes.modified?.length || branchTextRes.added?.length || branchTextRes.deleted?.length) {
cliux.print(' ');
forEach(branchTextRes.added, (diff: BranchDiffRes) => {
cliux.print(chalk.green(`+ '${diff.title}' ${startCase(camelCase(diff.type))}`));
if (diff.merge_strategy !== 'ignore') {
cliux.print(chalk.green(`+ '${diff.title}' ${startCase(camelCase(diff.type))}`));
}
});

forEach(branchTextRes.modified, (diff: BranchDiffRes) => {
cliux.print(chalk.blue(`± '${diff.title}' ${startCase(camelCase(diff.type))}`));
if (diff.merge_strategy !== 'ignore') {
cliux.print(chalk.blue(`± '${diff.title}' ${startCase(camelCase(diff.type))}`));
}
});

forEach(branchTextRes.deleted, (diff: BranchDiffRes) => {
cliux.print(chalk.red(`- '${diff.title}' ${startCase(camelCase(diff.type))}`));
if (diff.merge_strategy !== 'ignore') {
cliux.print(chalk.red(`- '${diff.title}' ${startCase(camelCase(diff.type))}`));
}
});
}
}
Expand Down
Loading