Remove unused code from scm-utils (#55036)

Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/55036

Changelog: [Internal]

Reviewed By: cortinico

Differential Revision: D90107033

fbshipit-source-id: 701b02801a59ee0c910de772dfa75d924e78860b
This commit is contained in:
Alex Hunt
2026-01-05 04:05:34 -08:00
committed by meta-codesync[bot]
parent a1e434318a
commit f2948fb2ad
3 changed files with 6 additions and 112 deletions
@@ -8,11 +8,10 @@
* @format
*/
const {isTaggedLatest, revertFiles, saveFiles} = require('../scm-utils');
const {isTaggedLatest} = require('../scm-utils');
let execResult = null;
const cpMock = jest.fn();
const mkdirSyncMock = jest.fn();
jest
.mock('shelljs', () => ({
exec: () => {
@@ -26,11 +25,9 @@ jest
exit: exitCode => {
process.exit(exitCode);
},
cp: cpMock,
}))
.mock('fs', () => ({
existsSync: jest.fn().mockImplementation(_ => true),
mkdirSync: mkdirSyncMock,
}))
.mock('path', () => ({
dirname: jest
@@ -58,41 +55,4 @@ describe('scm-utils', () => {
expect(isTaggedLatest('6c19dc3266b8')).toBe(false);
});
});
describe('saveFiles', () => {
it('it should save files in the temp folder', () => {
const tmpFolder = '/tmp';
saveFiles(['package.json', 'android/package.json'], tmpFolder);
expect(mkdirSyncMock).toHaveBeenCalledWith(`${tmpFolder}/android`, {
recursive: true,
});
expect(cpMock).toHaveBeenNthCalledWith(
1,
'package.json',
'/tmp/package.json',
);
expect(cpMock).toHaveBeenNthCalledWith(
2,
'android/package.json',
`${tmpFolder}/android/package.json`,
);
});
});
describe('revertFiles', () => {
it('it should revert files from the temp folder', () => {
const tmpFolder = '/tmp';
revertFiles(['package.json', 'android/package.json'], tmpFolder);
expect(cpMock).toHaveBeenNthCalledWith(
1,
`${tmpFolder}/package.json`,
'package.json',
);
expect(cpMock).toHaveBeenNthCalledWith(
2,
`${tmpFolder}/android/package.json`,
'android/package.json',
);
});
});
});
+4 -66
View File
@@ -10,28 +10,8 @@
'use strict';
const fs = require('fs');
const path = require('path');
const {cp, echo, exec, exit} = require('shelljs');
/*::
type Commit = string;
*/
function isGitRepo() /*: boolean */ {
try {
return (
exec('git rev-parse --is-inside-work-tree', {
silent: true,
}).stdout.trim() === 'true'
);
} catch (error) {
echo(
`It wasn't possible to check if we are in a git repository. Details: ${error}`,
);
}
return false;
}
const isGitRepo = require('../../shared/isGitRepo');
const {echo, exec, exit} = require('shelljs');
function exitIfNotOnGit /*::<T>*/(
command /*: () => T */,
@@ -47,7 +27,7 @@ function exitIfNotOnGit /*::<T>*/(
}
}
function isTaggedLatest(commitSha /*: Commit */) /*: boolean */ {
function isTaggedLatest(commitSha /*: string */) /*: boolean */ {
return (
exec(`git rev-list -1 latest | grep ${commitSha}`, {
silent: true,
@@ -61,7 +41,7 @@ function getBranchName() /*: string */ {
}).stdout.trim();
}
function getCurrentCommit() /*: Commit */ {
function getCurrentCommit() /*: string */ {
return isGitRepo()
? exec('git rev-parse HEAD', {
silent: true,
@@ -69,51 +49,9 @@ function getCurrentCommit() /*: Commit */ {
: 'TEMP';
}
function saveFiles(filePaths /*: Array<string> */, tmpFolder /*: string */) {
for (const filePath of filePaths) {
const dirName = path.dirname(filePath);
if (dirName !== '.') {
const destFolder = `${tmpFolder}/${dirName}`;
fs.mkdirSync(destFolder, {recursive: true});
}
cp(filePath, `${tmpFolder}/${filePath}`);
}
}
function revertFiles(filePaths /*: Array<string> */, tmpFolder /*: string */) {
for (const filePath of filePaths) {
const absoluteTmpPath = `${tmpFolder}/${filePath}`;
if (fs.existsSync(absoluteTmpPath)) {
cp(absoluteTmpPath, filePath);
} else {
echo(
`It was not possible to revert ${filePath} since ${absoluteTmpPath} does not exist.`,
);
exit(1);
}
}
}
// git restore for local path
function restore(repoPath /*: string */) {
const result = exec('git restore .', {
cwd: repoPath,
});
if (result.code !== 0) {
throw new Error(result.stderr);
}
return;
}
module.exports = {
exitIfNotOnGit,
getCurrentCommit,
getBranchName,
isGitRepo,
isTaggedLatest,
revertFiles,
saveFiles,
restore,
};
-4
View File
@@ -12,10 +12,6 @@
const childProcess = require('child_process');
/*::
type Commit = string;
*/
function isGitRepo() /*: boolean */ {
try {
const result = childProcess.execSync(