@proagentstore/cli 0.4.140 → 0.4.141
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.
|
@@ -72,6 +72,16 @@ export function parkSnapshot(workDir, runId) {
|
|
|
72
72
|
git(workDir, ["update-ref", ref, snapshot]);
|
|
73
73
|
return { snapshot, files: before.length, clean: changes(workDir).length === 0, ref };
|
|
74
74
|
}
|
|
75
|
+
/** The paths `git apply --check` names when it refuses — "patch failed: <path>:<line>", "<path>: does not match index", … */
|
|
76
|
+
export function applyConflicts(stderr) {
|
|
77
|
+
const out = new Set();
|
|
78
|
+
for (const line of stderr.split("\n")) {
|
|
79
|
+
const m = line.match(/^error: patch failed: (.+):\d+$/) ?? line.match(/^error: (.+): (?:does not match index|already exists in working directory|does not exist in index|No such file or directory)$/);
|
|
80
|
+
if (m?.[1])
|
|
81
|
+
out.add(m[1]);
|
|
82
|
+
}
|
|
83
|
+
return [...out];
|
|
84
|
+
}
|
|
75
85
|
/** Put a parked run's work back by its exact id — only onto a clean tree, only if it applies cleanly. */
|
|
76
86
|
export function parkRestore(workDir, runId, snapshot) {
|
|
77
87
|
checkout(workDir, runId);
|
|
@@ -96,8 +106,9 @@ export function parkRestore(workDir, runId, snapshot) {
|
|
|
96
106
|
try {
|
|
97
107
|
git(workDir, ["apply", "--check"], patch);
|
|
98
108
|
}
|
|
99
|
-
catch {
|
|
100
|
-
|
|
109
|
+
catch (e) {
|
|
110
|
+
const conflicts = applyConflicts(String(e.stderr ?? ""));
|
|
111
|
+
return { restored: false, refused: "the saved work no longer applies cleanly to this checkout (it changed underneath while the run was parked)", conflicts };
|
|
101
112
|
}
|
|
102
113
|
}
|
|
103
114
|
// Untracked files: the stash's third parent. Any that already exists would be refused by git mid-apply.
|
|
@@ -110,7 +121,7 @@ export function parkRestore(workDir, runId, snapshot) {
|
|
|
110
121
|
}
|
|
111
122
|
const clash = untracked.filter((p) => existsSync(join(workDir, p)));
|
|
112
123
|
if (clash.length)
|
|
113
|
-
return { restored: false, refused: `${clash.length} file${clash.length === 1 ? "" : "s"} the saved work would create already exist${clash.length === 1 ? "s" : ""}
|
|
124
|
+
return { restored: false, refused: `${clash.length} file${clash.length === 1 ? "" : "s"} the saved work would create already exist${clash.length === 1 ? "s" : ""}`, conflicts: clash };
|
|
114
125
|
git(workDir, ["stash", "apply", snapshot]);
|
|
115
126
|
git(workDir, ["update-ref", "-d", ref, snapshot]);
|
|
116
127
|
return { restored: true };
|