Skip to content

Commit f2948fb

Browse files
huntiemeta-codesync[bot]
authored andcommitted
Remove unused code from scm-utils (#55036)
Summary: Pull Request resolved: #55036 Changelog: [Internal] Reviewed By: cortinico Differential Revision: D90107033 fbshipit-source-id: 701b02801a59ee0c910de772dfa75d924e78860b
1 parent a1e4343 commit f2948fb

3 files changed

Lines changed: 6 additions & 112 deletions

File tree

scripts/releases/utils/__tests__/scm-utils-test.js

Lines changed: 2 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,10 @@
88
* @format
99
*/
1010

11-
const {isTaggedLatest, revertFiles, saveFiles} = require('../scm-utils');
11+
const {isTaggedLatest} = require('../scm-utils');
1212

1313
let execResult = null;
14-
const cpMock = jest.fn();
15-
const mkdirSyncMock = jest.fn();
14+
1615
jest
1716
.mock('shelljs', () => ({
1817
exec: () => {
@@ -26,11 +25,9 @@ jest
2625
exit: exitCode => {
2726
process.exit(exitCode);
2827
},
29-
cp: cpMock,
3028
}))
3129
.mock('fs', () => ({
3230
existsSync: jest.fn().mockImplementation(_ => true),
33-
mkdirSync: mkdirSyncMock,
3431
}))
3532
.mock('path', () => ({
3633
dirname: jest
@@ -58,41 +55,4 @@ describe('scm-utils', () => {
5855
expect(isTaggedLatest('6c19dc3266b8')).toBe(false);
5956
});
6057
});
61-
62-
describe('saveFiles', () => {
63-
it('it should save files in the temp folder', () => {
64-
const tmpFolder = '/tmp';
65-
saveFiles(['package.json', 'android/package.json'], tmpFolder);
66-
expect(mkdirSyncMock).toHaveBeenCalledWith(`${tmpFolder}/android`, {
67-
recursive: true,
68-
});
69-
expect(cpMock).toHaveBeenNthCalledWith(
70-
1,
71-
'package.json',
72-
'/tmp/package.json',
73-
);
74-
expect(cpMock).toHaveBeenNthCalledWith(
75-
2,
76-
'android/package.json',
77-
`${tmpFolder}/android/package.json`,
78-
);
79-
});
80-
});
81-
82-
describe('revertFiles', () => {
83-
it('it should revert files from the temp folder', () => {
84-
const tmpFolder = '/tmp';
85-
revertFiles(['package.json', 'android/package.json'], tmpFolder);
86-
expect(cpMock).toHaveBeenNthCalledWith(
87-
1,
88-
`${tmpFolder}/package.json`,
89-
'package.json',
90-
);
91-
expect(cpMock).toHaveBeenNthCalledWith(
92-
2,
93-
`${tmpFolder}/android/package.json`,
94-
'android/package.json',
95-
);
96-
});
97-
});
9858
});

scripts/releases/utils/scm-utils.js

Lines changed: 4 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -10,28 +10,8 @@
1010

1111
'use strict';
1212

13-
const fs = require('fs');
14-
const path = require('path');
15-
const {cp, echo, exec, exit} = require('shelljs');
16-
17-
/*::
18-
type Commit = string;
19-
*/
20-
21-
function isGitRepo() /*: boolean */ {
22-
try {
23-
return (
24-
exec('git rev-parse --is-inside-work-tree', {
25-
silent: true,
26-
}).stdout.trim() === 'true'
27-
);
28-
} catch (error) {
29-
echo(
30-
`It wasn't possible to check if we are in a git repository. Details: ${error}`,
31-
);
32-
}
33-
return false;
34-
}
13+
const isGitRepo = require('../../shared/isGitRepo');
14+
const {echo, exec, exit} = require('shelljs');
3515

3616
function exitIfNotOnGit /*::<T>*/(
3717
command /*: () => T */,
@@ -47,7 +27,7 @@ function exitIfNotOnGit /*::<T>*/(
4727
}
4828
}
4929

50-
function isTaggedLatest(commitSha /*: Commit */) /*: boolean */ {
30+
function isTaggedLatest(commitSha /*: string */) /*: boolean */ {
5131
return (
5232
exec(`git rev-list -1 latest | grep ${commitSha}`, {
5333
silent: true,
@@ -61,59 +41,17 @@ function getBranchName() /*: string */ {
6141
}).stdout.trim();
6242
}
6343

64-
function getCurrentCommit() /*: Commit */ {
44+
function getCurrentCommit() /*: string */ {
6545
return isGitRepo()
6646
? exec('git rev-parse HEAD', {
6747
silent: true,
6848
}).stdout.trim()
6949
: 'TEMP';
7050
}
7151

72-
function saveFiles(filePaths /*: Array<string> */, tmpFolder /*: string */) {
73-
for (const filePath of filePaths) {
74-
const dirName = path.dirname(filePath);
75-
if (dirName !== '.') {
76-
const destFolder = `${tmpFolder}/${dirName}`;
77-
fs.mkdirSync(destFolder, {recursive: true});
78-
}
79-
cp(filePath, `${tmpFolder}/${filePath}`);
80-
}
81-
}
82-
83-
function revertFiles(filePaths /*: Array<string> */, tmpFolder /*: string */) {
84-
for (const filePath of filePaths) {
85-
const absoluteTmpPath = `${tmpFolder}/${filePath}`;
86-
if (fs.existsSync(absoluteTmpPath)) {
87-
cp(absoluteTmpPath, filePath);
88-
} else {
89-
echo(
90-
`It was not possible to revert ${filePath} since ${absoluteTmpPath} does not exist.`,
91-
);
92-
exit(1);
93-
}
94-
}
95-
}
96-
97-
// git restore for local path
98-
function restore(repoPath /*: string */) {
99-
const result = exec('git restore .', {
100-
cwd: repoPath,
101-
});
102-
103-
if (result.code !== 0) {
104-
throw new Error(result.stderr);
105-
}
106-
107-
return;
108-
}
109-
11052
module.exports = {
11153
exitIfNotOnGit,
11254
getCurrentCommit,
11355
getBranchName,
114-
isGitRepo,
11556
isTaggedLatest,
116-
revertFiles,
117-
saveFiles,
118-
restore,
11957
};

scripts/shared/isGitRepo.js

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,6 @@
1212

1313
const childProcess = require('child_process');
1414

15-
/*::
16-
type Commit = string;
17-
*/
18-
1915
function isGitRepo() /*: boolean */ {
2016
try {
2117
const result = childProcess.execSync(

0 commit comments

Comments
 (0)