@regressionproof/snapshotter 0.5.4 → 0.5.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/esm/git.js +28 -11
- package/build/git.js +26 -10
- package/package.json +2 -2
package/build/esm/git.js
CHANGED
|
@@ -8,7 +8,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
8
8
|
});
|
|
9
9
|
};
|
|
10
10
|
import { exec } from 'child_process';
|
|
11
|
-
import { existsSync } from 'fs';
|
|
11
|
+
import { existsSync, unlinkSync } from 'fs';
|
|
12
12
|
import path from 'path';
|
|
13
13
|
import { promisify } from 'util';
|
|
14
14
|
import SpruceError from './errors/SpruceError.js.js';
|
|
@@ -20,6 +20,7 @@ export function gitCommit(mirrorPath, log) {
|
|
|
20
20
|
if (!existsSync(gitDir)) {
|
|
21
21
|
yield execOrThrow(`git -C "${mirrorPath}" init`, log);
|
|
22
22
|
}
|
|
23
|
+
cleanupGitLockFiles(mirrorPath, log);
|
|
23
24
|
yield execOrThrow(`git -C "${mirrorPath}" add -A`, log);
|
|
24
25
|
const { stdout } = yield execOrThrow(`git -C "${mirrorPath}" status --porcelain`);
|
|
25
26
|
if (!stdout.trim()) {
|
|
@@ -33,14 +34,15 @@ export function gitCommit(mirrorPath, log) {
|
|
|
33
34
|
}
|
|
34
35
|
export function gitPush(mirrorPath, remote, log) {
|
|
35
36
|
return __awaiter(this, void 0, void 0, function* () {
|
|
37
|
+
cleanupGitLockFiles(mirrorPath, log);
|
|
36
38
|
const authedUrl = remote.url.replace('://', `://${remote.token}@`);
|
|
37
|
-
const
|
|
38
|
-
if (
|
|
39
|
-
yield execOrThrow(`git -C "${mirrorPath}" remote set-url origin "${authedUrl}"`);
|
|
40
|
-
}
|
|
41
|
-
else {
|
|
39
|
+
const currentUrl = yield getRemoteUrl(mirrorPath, 'origin');
|
|
40
|
+
if (currentUrl === null) {
|
|
42
41
|
yield execOrThrow(`git -C "${mirrorPath}" remote add origin "${authedUrl}"`);
|
|
43
42
|
}
|
|
43
|
+
else if (currentUrl !== authedUrl) {
|
|
44
|
+
yield execOrThrow(`git -C "${mirrorPath}" remote set-url origin "${authedUrl}"`);
|
|
45
|
+
}
|
|
44
46
|
yield pullFromRemote(mirrorPath, log);
|
|
45
47
|
yield execOrThrow(`git -C "${mirrorPath}" push -u origin HEAD`, log);
|
|
46
48
|
});
|
|
@@ -72,18 +74,33 @@ function checkRemoteBranchExists(mirrorPath, branch) {
|
|
|
72
74
|
}
|
|
73
75
|
});
|
|
74
76
|
}
|
|
75
|
-
function
|
|
77
|
+
function getRemoteUrl(mirrorPath, remoteName) {
|
|
76
78
|
return __awaiter(this, void 0, void 0, function* () {
|
|
77
79
|
try {
|
|
78
|
-
const { stdout } = yield execAsync(`git -C "${mirrorPath}" remote`);
|
|
79
|
-
|
|
80
|
-
return remotes.includes(remoteName);
|
|
80
|
+
const { stdout } = yield execAsync(`git -C "${mirrorPath}" remote get-url ${remoteName}`);
|
|
81
|
+
return stdout.trim();
|
|
81
82
|
}
|
|
82
83
|
catch (_a) {
|
|
83
|
-
return
|
|
84
|
+
return null;
|
|
84
85
|
}
|
|
85
86
|
});
|
|
86
87
|
}
|
|
88
|
+
function cleanupGitLockFiles(mirrorPath, log) {
|
|
89
|
+
var _a;
|
|
90
|
+
const lockFiles = ['config.lock', 'index.lock', 'HEAD.lock'];
|
|
91
|
+
for (const lockFile of lockFiles) {
|
|
92
|
+
const lockPath = path.join(mirrorPath, '.git', lockFile);
|
|
93
|
+
if (existsSync(lockPath)) {
|
|
94
|
+
try {
|
|
95
|
+
unlinkSync(lockPath);
|
|
96
|
+
log === null || log === void 0 ? void 0 : log.info(`Removed stale lock file: ${lockFile}`);
|
|
97
|
+
}
|
|
98
|
+
catch (_b) {
|
|
99
|
+
(_a = log === null || log === void 0 ? void 0 : log.warn) === null || _a === void 0 ? void 0 : _a.call(log, `Failed to remove lock file: ${lockFile}`);
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
}
|
|
87
104
|
function execOrThrow(command, log) {
|
|
88
105
|
return __awaiter(this, void 0, void 0, function* () {
|
|
89
106
|
var _a, _b;
|
package/build/git.js
CHANGED
|
@@ -17,6 +17,7 @@ async function gitCommit(mirrorPath, log) {
|
|
|
17
17
|
if (!(0, fs_1.existsSync)(gitDir)) {
|
|
18
18
|
await execOrThrow(`git -C "${mirrorPath}" init`, log);
|
|
19
19
|
}
|
|
20
|
+
cleanupGitLockFiles(mirrorPath, log);
|
|
20
21
|
await execOrThrow(`git -C "${mirrorPath}" add -A`, log);
|
|
21
22
|
const { stdout } = await execOrThrow(`git -C "${mirrorPath}" status --porcelain`);
|
|
22
23
|
if (!stdout.trim()) {
|
|
@@ -28,14 +29,15 @@ async function gitCommit(mirrorPath, log) {
|
|
|
28
29
|
return true;
|
|
29
30
|
}
|
|
30
31
|
async function gitPush(mirrorPath, remote, log) {
|
|
32
|
+
cleanupGitLockFiles(mirrorPath, log);
|
|
31
33
|
const authedUrl = remote.url.replace('://', `://${remote.token}@`);
|
|
32
|
-
const
|
|
33
|
-
if (
|
|
34
|
-
await execOrThrow(`git -C "${mirrorPath}" remote set-url origin "${authedUrl}"`);
|
|
35
|
-
}
|
|
36
|
-
else {
|
|
34
|
+
const currentUrl = await getRemoteUrl(mirrorPath, 'origin');
|
|
35
|
+
if (currentUrl === null) {
|
|
37
36
|
await execOrThrow(`git -C "${mirrorPath}" remote add origin "${authedUrl}"`);
|
|
38
37
|
}
|
|
38
|
+
else if (currentUrl !== authedUrl) {
|
|
39
|
+
await execOrThrow(`git -C "${mirrorPath}" remote set-url origin "${authedUrl}"`);
|
|
40
|
+
}
|
|
39
41
|
await pullFromRemote(mirrorPath, log);
|
|
40
42
|
await execOrThrow(`git -C "${mirrorPath}" push -u origin HEAD`, log);
|
|
41
43
|
}
|
|
@@ -60,14 +62,28 @@ async function checkRemoteBranchExists(mirrorPath, branch) {
|
|
|
60
62
|
return false;
|
|
61
63
|
}
|
|
62
64
|
}
|
|
63
|
-
async function
|
|
65
|
+
async function getRemoteUrl(mirrorPath, remoteName) {
|
|
64
66
|
try {
|
|
65
|
-
const { stdout } = await execAsync(`git -C "${mirrorPath}" remote`);
|
|
66
|
-
|
|
67
|
-
return remotes.includes(remoteName);
|
|
67
|
+
const { stdout } = await execAsync(`git -C "${mirrorPath}" remote get-url ${remoteName}`);
|
|
68
|
+
return stdout.trim();
|
|
68
69
|
}
|
|
69
70
|
catch {
|
|
70
|
-
return
|
|
71
|
+
return null;
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
function cleanupGitLockFiles(mirrorPath, log) {
|
|
75
|
+
const lockFiles = ['config.lock', 'index.lock', 'HEAD.lock'];
|
|
76
|
+
for (const lockFile of lockFiles) {
|
|
77
|
+
const lockPath = path_1.default.join(mirrorPath, '.git', lockFile);
|
|
78
|
+
if ((0, fs_1.existsSync)(lockPath)) {
|
|
79
|
+
try {
|
|
80
|
+
(0, fs_1.unlinkSync)(lockPath);
|
|
81
|
+
log?.info(`Removed stale lock file: ${lockFile}`);
|
|
82
|
+
}
|
|
83
|
+
catch {
|
|
84
|
+
log?.warn?.(`Failed to remove lock file: ${lockFile}`);
|
|
85
|
+
}
|
|
86
|
+
}
|
|
71
87
|
}
|
|
72
88
|
}
|
|
73
89
|
async function execOrThrow(command, log) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@regressionproof/snapshotter",
|
|
3
|
-
"version": "0.5.
|
|
3
|
+
"version": "0.5.5",
|
|
4
4
|
"publishConfig": {
|
|
5
5
|
"access": "public"
|
|
6
6
|
},
|
|
@@ -94,5 +94,5 @@
|
|
|
94
94
|
"@sprucelabs/spruce-core-schemas": "^42.1.3",
|
|
95
95
|
"@sprucelabs/spruce-skill-utils": "^34.0.3"
|
|
96
96
|
},
|
|
97
|
-
"gitHead": "
|
|
97
|
+
"gitHead": "960e13b1ccdd3227d7e0aad8451e6eb851189746"
|
|
98
98
|
}
|