-
Notifications
You must be signed in to change notification settings - Fork 0
/
repro.ts
47 lines (38 loc) · 1.18 KB
/
repro.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
import * as shell from "shelljs";
const REPO = "politics-rewired/shelljs-repro";
const cloneRepo = (cd: boolean) => {
// Shallow clone the manifests
const rand = Math.floor(Math.random() * 1000);
const tmpDir = shell.tempdir() as any;
const localPath = `${tmpDir}/shelljs-repro-${new Date().getTime()}-${rand}`;
shell.set("-e");
const repoRemoteUri = `git@github.com:${REPO}.git`;
const cloneCommand = `git clone --depth 1 ${repoRemoteUri} ${localPath}`;
console.log(`cmd: ${cloneCommand}`);
shell.exec(cloneCommand);
shell.cd(localPath);
// Make changes to the repo
shell.echo("Do stuff in the repo").to("tmp.txt");
// The key line!
if (cd) shell.cd(tmpDir);
// Clean up
shell.rm("-rf", localPath);
};
const attempt = (cd: boolean) => {
try {
cloneRepo(cd);
} catch (err) {
console.error(`error in cd:${cd} attempt 0`, err);
}
try {
cloneRepo(cd);
} catch (err) {
console.error(`error in cd:${cd} attempt 1`, err);
}
};
// Changing directory before removing works for both attempts
attempt(true);
// Changing directory works for first, but fails for second
attempt(false);
// All subsequent exec's fail with same error
attempt(true);