From 51cb202cc65d8cef631258fb0aa7cbf932c2bfee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Pierzcha=C5=82a?= Date: Mon, 17 Jun 2019 12:56:13 +0200 Subject: [PATCH 1/2] feat: allow upgrading with binary files in the diff --- packages/cli/src/commands/upgrade/upgrade.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/packages/cli/src/commands/upgrade/upgrade.js b/packages/cli/src/commands/upgrade/upgrade.js index 8f48537b8..ba6875bd5 100644 --- a/packages/cli/src/commands/upgrade/upgrade.js +++ b/packages/cli/src/commands/upgrade/upgrade.js @@ -5,7 +5,7 @@ import chalk from 'chalk'; import semver from 'semver'; import execa from 'execa'; import type {ConfigT} from 'types'; -import {logger} from '@react-native-community/cli-tools'; +import {logger, CLIError} from '@react-native-community/cli-tools'; import * as PackageManager from '../../tools/packageManager'; import {fetch} from '../../tools/fetch'; import legacyUpgrade from './legacyUpgrade'; @@ -179,6 +179,10 @@ const applyPatch = async ( ); await execa('git', [ 'apply', + // According to git documentation, `--binary` flag is turned on by + // default. However it's necessary when running `git apply --check` to + // actually accept binary files, maybe a bug in git? + '--binary', '--check', tmpPatchFile, ...excludes, @@ -307,7 +311,7 @@ async function upgrade(argv: Array, ctx: ConfigT, args: FlagsT) { `${rnDiffPurgeRawDiffsUrl}/${currentVersion}..${newVersion}.diff`, )}`); - throw new Error( + throw new CLIError( 'Upgrade failed. Please see the messages above for details', ); } From 3fe91915ea11609303fdc29718a66cd6e69ac5ac Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Pierzcha=C5=82a?= Date: Mon, 17 Jun 2019 13:23:11 +0200 Subject: [PATCH 2/2] fix tests --- jest/setupUnitTests.js | 14 +------------- .../src/commands/upgrade/__tests__/upgrade.test.js | 7 ++++--- 2 files changed, 5 insertions(+), 16 deletions(-) diff --git a/jest/setupUnitTests.js b/jest/setupUnitTests.js index 4c31f817a..cff360d25 100644 --- a/jest/setupUnitTests.js +++ b/jest/setupUnitTests.js @@ -2,18 +2,6 @@ * @flow */ -jest.mock('@react-native-community/cli-tools', () => ({ - ...jest.requireActual('@react-native-community/cli-tools'), - logger: { - success: jest.fn(), - info: jest.fn(), - warn: jest.fn(), - error: jest.fn(), - debug: jest.fn(), - log: jest.fn(), - setVerbose: jest.fn(), - isVerbose: jest.fn(), - }, -})); +jest.mock('@react-native-community/cli-tools'); jest.setTimeout(20000); diff --git a/packages/cli/src/commands/upgrade/__tests__/upgrade.test.js b/packages/cli/src/commands/upgrade/__tests__/upgrade.test.js index f64b4c47e..a35b0def8 100644 --- a/packages/cli/src/commands/upgrade/__tests__/upgrade.test.js +++ b/packages/cli/src/commands/upgrade/__tests__/upgrade.test.js @@ -47,6 +47,7 @@ jest.mock('../../../tools/fetch', () => ({ fetch: jest.fn(() => Promise.resolve('patch')), })); jest.mock('@react-native-community/cli-tools', () => ({ + ...jest.requireActual('@react-native-community/cli-tools'), logger: { info: jest.fn((...args) => mockPushLog('info', args)), error: jest.fn((...args) => mockPushLog('error', args)), @@ -187,7 +188,7 @@ test('fetches regular patch, adds remote, applies patch, installs deps, removes "info Fetching diff between v0.57.8 and v0.58.4... [fs] write tmp-upgrade-rn.patch $ execa git rev-parse --show-prefix - $ execa git apply --check tmp-upgrade-rn.patch --exclude=package.json -p2 --3way --directory= + $ execa git apply --binary --check tmp-upgrade-rn.patch --exclude=package.json -p2 --3way --directory= info Applying diff... $ execa git apply tmp-upgrade-rn.patch --exclude=package.json -p2 --3way --directory= [fs] unlink tmp-upgrade-rn.patch @@ -219,7 +220,7 @@ test('fetches regular patch, adds remote, applies patch, installs deps, removes "info Fetching diff between v0.57.8 and v0.58.4... [fs] write tmp-upgrade-rn.patch $ execa git rev-parse --show-prefix - $ execa git apply --check tmp-upgrade-rn.patch --exclude=NestedApp/package.json -p2 --3way --directory=NestedApp/ + $ execa git apply --binary --check tmp-upgrade-rn.patch --exclude=NestedApp/package.json -p2 --3way --directory=NestedApp/ info Applying diff... $ execa git apply tmp-upgrade-rn.patch --exclude=NestedApp/package.json -p2 --3way --directory=NestedApp/ [fs] unlink tmp-upgrade-rn.patch @@ -266,7 +267,7 @@ test('cleans up if patching fails,', async () => { "info Fetching diff between v0.57.8 and v0.58.4... [fs] write tmp-upgrade-rn.patch $ execa git rev-parse --show-prefix - $ execa git apply --check tmp-upgrade-rn.patch --exclude=package.json -p2 --3way --directory= + $ execa git apply --binary --check tmp-upgrade-rn.patch --exclude=package.json -p2 --3way --directory= info Applying diff (excluding: package.json, .flowconfig)... $ execa git apply tmp-upgrade-rn.patch --exclude=package.json --exclude=.flowconfig -p2 --3way --directory= error: .flowconfig: does not exist in index