Skip to content
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

✨ Colorize filenames with conflicts when upgrading #17947

Closed
wants to merge 1 commit into from
Closed
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: 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