Skip to content

Commit 6bcf5c2

Browse files
authored
Merge pull request #1816 from contentstack/fix/DX-89
fix: handling ignored content-types
2 parents 5020a96 + 0545320 commit 6bcf5c2

File tree

3 files changed

+31
-5
lines changed

3 files changed

+31
-5
lines changed

packages/contentstack-branches/src/branch/merge-handler.ts

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import os from 'os';
22
import path from 'path';
33
import forEach from 'lodash/forEach';
44
import { cliux } from '@contentstack/cli-utilities';
5+
import chalk from 'chalk';
56
import { MergeInputOptions, MergeSummary } from '../interfaces';
67
import {
78
selectMergeStrategy,
@@ -107,6 +108,10 @@ export default class MergeHandler {
107108
deleted: [],
108109
};
109110
const selectedItems = await selectCustomPreferences(module, this.branchCompareData[module]);
111+
if (!selectedItems.length) {
112+
cliux.print(chalk.red('No items were selected'));
113+
process.exit(1);
114+
}
110115
forEach(selectedItems, (item) => {
111116
this.mergeSettings.mergeContent[module][item.status].push(item.value);
112117
this.mergeSettings.itemMergeStrategies.push(item.value);
@@ -132,8 +137,11 @@ export default class MergeHandler {
132137
} else if (this.strategy === 'overwrite_with_compare') {
133138
this.mergeSettings.strategy = 'overwrite_with_compare';
134139
}
135-
136-
await this.displayMergeSummary();
140+
if (this.checkEmptySelection()) {
141+
cliux.print(chalk.red('No items selected'));
142+
} else {
143+
await this.displayMergeSummary();
144+
}
137145

138146
if (!this.executeOption) {
139147
const executionResponse = await selectMergeExecution();
@@ -152,6 +160,17 @@ export default class MergeHandler {
152160
}
153161
}
154162

163+
checkEmptySelection() {
164+
for (let module in this.branchCompareData) {
165+
if (this.mergeSettings.mergeContent[module]?.modified?.length
166+
|| this.mergeSettings.mergeContent[module]?.added?.length
167+
|| this.mergeSettings.mergeContent[module]?.deleted?.length) {
168+
return false;
169+
}
170+
}
171+
return true;
172+
}
173+
155174
displayMergeSummary() {
156175
if (this.mergeSettings.strategy !== 'ignore') {
157176
for (let module in this.branchCompareData) {

packages/contentstack-branches/src/interfaces/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ export interface BranchDiffRes {
1313
title: string;
1414
type: string;
1515
status: string;
16+
merge_strategy?: string;
1617
}
1718

1819
export interface BranchDiffSummary {

packages/contentstack-branches/src/utils/branch-diff-utility.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -196,15 +196,21 @@ function printCompactTextView(branchTextRes: BranchCompactTextRes): void {
196196
if (branchTextRes.modified?.length || branchTextRes.added?.length || branchTextRes.deleted?.length) {
197197
cliux.print(' ');
198198
forEach(branchTextRes.added, (diff: BranchDiffRes) => {
199-
cliux.print(chalk.green(`+ '${diff.title}' ${startCase(camelCase(diff.type))}`));
199+
if (diff.merge_strategy !== 'ignore') {
200+
cliux.print(chalk.green(`+ '${diff.title}' ${startCase(camelCase(diff.type))}`));
201+
}
200202
});
201203

202204
forEach(branchTextRes.modified, (diff: BranchDiffRes) => {
203-
cliux.print(chalk.blue(`± '${diff.title}' ${startCase(camelCase(diff.type))}`));
205+
if (diff.merge_strategy !== 'ignore') {
206+
cliux.print(chalk.blue(`± '${diff.title}' ${startCase(camelCase(diff.type))}`));
207+
}
204208
});
205209

206210
forEach(branchTextRes.deleted, (diff: BranchDiffRes) => {
207-
cliux.print(chalk.red(`- '${diff.title}' ${startCase(camelCase(diff.type))}`));
211+
if (diff.merge_strategy !== 'ignore') {
212+
cliux.print(chalk.red(`- '${diff.title}' ${startCase(camelCase(diff.type))}`));
213+
}
208214
});
209215
}
210216
}

0 commit comments

Comments
 (0)