Refactor path handling in patch_files.js to use user-specified paths for action keys, improving consistency and error messaging. Update CLI to replace commented-out test cases with a new interrogation command in German for business website creation, enhancing functionality.
This commit is contained in:
@@ -238,9 +238,9 @@ class Parser {
|
||||
if (path) {
|
||||
// Resolve path with chroot
|
||||
const resolvedPath = resolvePath(this.chroot, path);
|
||||
|
||||
if (resolvedPath in this.patch.actions) {
|
||||
throw new DiffError(`Duplicate update for file: ${resolvedPath}`);
|
||||
// Use user-specified path as the key to avoid double-resolving later
|
||||
if (path in this.patch.actions) {
|
||||
throw new DiffError(`Duplicate update for file: ${path}`);
|
||||
}
|
||||
const move_to = this.read_str("*** Move to: ");
|
||||
if (!(resolvedPath in this.current_files)) {
|
||||
@@ -248,8 +248,8 @@ class Parser {
|
||||
}
|
||||
const text = this.current_files[resolvedPath];
|
||||
const action = this._parse_update_file(text);
|
||||
action.move_path = move_to ? resolvePath(this.chroot, move_to) : null;
|
||||
this.patch.actions[resolvedPath] = action;
|
||||
action.move_path = move_to ? move_to : null;
|
||||
this.patch.actions[path] = action;
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -258,14 +258,13 @@ class Parser {
|
||||
if (path) {
|
||||
// Resolve path with chroot
|
||||
const resolvedPath = resolvePath(this.chroot, path);
|
||||
|
||||
if (resolvedPath in this.patch.actions) {
|
||||
throw new DiffError(`Duplicate delete for file: ${resolvedPath}`);
|
||||
if (path in this.patch.actions) {
|
||||
throw new DiffError(`Duplicate delete for file: ${path}`);
|
||||
}
|
||||
if (!(resolvedPath in this.current_files)) {
|
||||
throw new DiffError(`Delete File Error - missing file: ${resolvedPath}`);
|
||||
throw new DiffError(`Delete File Error - missing file: ${path}`);
|
||||
}
|
||||
this.patch.actions[resolvedPath] = new PatchAction(ActionType.DELETE);
|
||||
this.patch.actions[path] = new PatchAction(ActionType.DELETE);
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -274,14 +273,13 @@ class Parser {
|
||||
if (path) {
|
||||
// Resolve path with chroot
|
||||
const resolvedPath = resolvePath(this.chroot, path);
|
||||
|
||||
if (resolvedPath in this.patch.actions) {
|
||||
throw new DiffError(`Duplicate add for file: ${resolvedPath}`);
|
||||
if (path in this.patch.actions) {
|
||||
throw new DiffError(`Duplicate add for file: ${path}`);
|
||||
}
|
||||
if (resolvedPath in this.current_files) {
|
||||
throw new DiffError(`Add File Error - file already exists: ${resolvedPath}`);
|
||||
throw new DiffError(`Add File Error - file already exists: ${path}`);
|
||||
}
|
||||
this.patch.actions[resolvedPath] = this._parse_add_file();
|
||||
this.patch.actions[path] = this._parse_add_file();
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -370,7 +368,9 @@ class Parser {
|
||||
if (!s.startsWith("+")) {
|
||||
throw new DiffError(`Invalid Add File line (missing '+'): ${s}`);
|
||||
}
|
||||
lines.push(s.substring(1)); // strip leading '+'
|
||||
// Strip leading '+' and ignore a single optional space immediately after '+'
|
||||
const content = s.substring(1).replace(/^ /, "");
|
||||
lines.push(content);
|
||||
}
|
||||
return new PatchAction(ActionType.ADD, lines.join("\n"));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user