Skip to content

Commit e53a8f7

Browse files
alvinthenfacebook-github-bot
authored andcommitted
✨ Colorize filenames with conflicts when upgrading
Summary: Visually show files merged with conflicts when running `react-native-git-upgrade`. <!-- Thank you for sending the PR! We appreciate you spending the time to work on these changes. Help us understand your motivation by explaining why you decided to make this change. You can learn more about contributing to React Native here: http://facebook.github.io/react-native/docs/contributing.html Happy contributing! --> After running `react-native-git-upgrade`, files with conflicts are not immediately recognised visually. With this patch, files with conflicts are highlighted in red. ![image](https://user-images.githubusercontent.com/771989/36086385-fc183baa-1006-11e8-8862-0867b82b7ec1.png) <!-- Help reviewers and the release process by writing your own release notes **INTERNAL and MINOR tagged notes will not be included in the next version's final release notes.** CATEGORY [----------] TYPE [ CLI ] [-------------] LOCATION [ DOCS ] [ BREAKING ] [-------------] [ GENERAL ] [ BUGFIX ] [-{Component}-] [ INTERNAL ] [ ENHANCEMENT ] [ {File} ] [ IOS ] [ FEATURE ] [ {Directory} ] |-----------| [ ANDROID ] [ MINOR ] [ {Framework} ] - | {Message} | [----------] [-------------] [-------------] |-----------| [CATEGORY] [TYPE] [LOCATION] - MESSAGE EXAMPLES: [IOS] [BREAKING] [FlatList] - Change a thing that breaks other things [ANDROID] [BUGFIX] [TextInput] - Did a thing to TextInput [CLI] [FEATURE] [local-cli/info/info.js] - CLI easier to do things with [DOCS] [BUGFIX] [GettingStarted.md] - Accidentally a thing/word [GENERAL] [ENHANCEMENT] [Yoga] - Added new yoga thing/position [INTERNAL] [FEATURE] [./scripts] - Added thing to script that nobody will see --> [CLI] [ENHANCEMENT] [react-native-git-upgrade/cliEntry.js] - Print files with conflicts in red. Closes facebook#17947 Differential Revision: D6977042 Pulled By: hramos fbshipit-source-id: 3c67561ea3acbee227a7a0cf42857af4fb75c75c
1 parent cc6d093 commit e53a8f7

File tree

1 file changed

+19
-4
lines changed

1 file changed

+19
-4
lines changed

react-native-git-upgrade/cliEntry.js

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,23 +33,32 @@ log.heading = 'git-upgrade';
3333
/**
3434
* Promisify the callback-based shelljs function exec
3535
* @param logOutput If true, log the stdout of the command.
36+
* @param logger Custom logger to modify the output, invoked with the data and the stream.
3637
* @returns {Promise}
3738
*/
38-
function exec(command, logOutput) {
39+
function exec(command, logOutput, logger = null) {
3940
return new Promise((resolve, reject) => {
4041
let stderr, stdout = '';
4142
const child = shell.exec(command, {async: true, silent: true});
4243

4344
child.stdout.on('data', data => {
4445
stdout += data;
4546
if (logOutput) {
46-
process.stdout.write(data);
47+
if (logger) {
48+
logger(data, process.stdout);
49+
} else {
50+
process.stdout.write(data);
51+
}
4752
}
4853
});
4954

5055
child.stderr.on('data', data => {
5156
stderr += data;
52-
process.stderr.write(data);
57+
if (logger) {
58+
logger(data, process.stderr);
59+
} else {
60+
process.stderr.write(data);
61+
}
5362
});
5463

5564
child.on('exit', (code, signal) => {
@@ -359,7 +368,13 @@ async function run(requestedVersion, cliArgs) {
359368

360369
try {
361370
log.info('Apply the patch');
362-
await exec(`git apply --3way ${patchPath}`, true);
371+
await exec(`git apply --3way ${patchPath}`, true, (data, stream) => {
372+
if (data.indexOf('conflicts') >= 0 || data.startsWith('U ')) {
373+
stream.write(`\x1b[31m${data}\x1b[0m`);
374+
} else {
375+
stream.write(data);
376+
}
377+
});
363378
} catch (err) {
364379
log.warn(
365380
'The upgrade process succeeded but there might be conflicts to be resolved. ' +

0 commit comments

Comments
 (0)