Skip to content

Commit

Permalink
✨ Colorize filenames with conflicts when upgrading
Browse files Browse the repository at this point in the history
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 #17947

Differential Revision: D6977042

Pulled By: hramos

fbshipit-source-id: 3c67561ea3acbee227a7a0cf42857af4fb75c75c
  • Loading branch information
alvinthen authored and facebook-github-bot committed Feb 13, 2018
1 parent cc6d093 commit e53a8f7
Showing 1 changed file with 19 additions and 4 deletions.
23 changes: 19 additions & 4 deletions react-native-git-upgrade/cliEntry.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,23 +33,32 @@ log.heading = 'git-upgrade';
/**
* Promisify the callback-based shelljs function exec
* @param logOutput If true, log the stdout of the command.
* @param logger Custom logger to modify the output, invoked with the data and the stream.
* @returns {Promise}
*/
function exec(command, logOutput) {
function exec(command, logOutput, logger = null) {
return new Promise((resolve, reject) => {
let stderr, stdout = '';
const child = shell.exec(command, {async: true, silent: true});

child.stdout.on('data', data => {
stdout += data;
if (logOutput) {
process.stdout.write(data);
if (logger) {
logger(data, process.stdout);
} else {
process.stdout.write(data);
}
}
});

child.stderr.on('data', data => {
stderr += data;
process.stderr.write(data);
if (logger) {
logger(data, process.stderr);
} else {
process.stderr.write(data);
}
});

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

try {
log.info('Apply the patch');
await exec(`git apply --3way ${patchPath}`, true);
await exec(`git apply --3way ${patchPath}`, true, (data, stream) => {
if (data.indexOf('conflicts') >= 0 || data.startsWith('U ')) {
stream.write(`\x1b[31m${data}\x1b[0m`);
} else {
stream.write(data);
}
});
} catch (err) {
log.warn(
'The upgrade process succeeded but there might be conflicts to be resolved. ' +
Expand Down

0 comments on commit e53a8f7

Please sign in to comment.