@samitouri / QOS-React-2 / commits / 293059e52b

replace-fork should not clear uncommitted changes (#22348)

The replace-fork script depends on ESLint to fix the reconciler imports — `.old` -> `.new` or vice versa. If ESLint crashes, it can leave the imports in an incorrect state. As a convenience, @bvaughn updated the script to automatically run `git checkout -- .` if the ESLint command fails. An unintended consequence of the strategy is that if the working directory is not clean, then any uncommitted changes will be lost. We need a better strategy for this that prevents the accidental loss of work. One option is to exit early if the working directory is not clean before you run the script, though that affects the usability of the script. An ideal solution would reset the working directory back to whatever state it was in before the script ran, perhaps by stashing all the changes and restoring them if the script aborts. Until we think of something better, I've commmented out the branch.

Andrew Clark committed Sep 20, 2021 at 10:07 UTC 293059e52b57f9debdb01a235e29c678cadfc476
1 file changed +18 -6
scripts/merge-fork/replace-fork.js
+18 -6
@@ -22,15 +22,27 @@ async function main() {
22 await Promise.all(oldFilenames.map(unforkFile));
23
24 // Use ESLint to autofix imports
25 - const spawn = spawnSync('yarn', ['linc', '--fix'], {
25 + spawnSync('yarn', ['linc', '--fix'], {
26 stdio: ['inherit', 'inherit', 'pipe'],
27 });
28 - if (spawn.stderr.toString() !== '') {
29 - spawnSync('git', ['checkout', '.']);
28 + // TODO: If eslint crashes, it may not have successfully fixed all
29 + // the imports, which would leave the reconciler files in an inconsistent
30 + // state. So we used to crash and reset the working directory. But that
31 + // solution assumed that the working directory was clean before you run the
32 + // command — if it wasn't, it'll not only reset the synced reconciler files,
33 + // but all the other uncommitted changes.
34 + //
35 + // We need a different strategy to prevent loss of work. For example, we could
36 + // exit early if the working directory is not clean before you run the script.
37 + //
38 + // Until we think of something better, I've commmented out this branch to
39 + // prevent work from accidentally being lost.
40 + // if (spawn.stderr.toString() !== '') {
41 + // spawnSync('git', ['checkout', '.']);
42
31 - console.log(Error(spawn.stderr));
32 - process.exitCode = 1;
33 - }
43 + // console.log(Error(spawn.stderr));
44 + // process.exitCode = 1;
45 + // }
46 }
47
48 async function unforkFile(oldFilename) {