(c230d2c) Fix mv corrupting the Status metadata field
cmd_mv spliced the metadata line by byte offset and wrote the field name as **-Status**, because the format string re-added the "- " prefix that the preceding slice already carried. parse_ticket_field could never read Status back, and the next move failed to find "- **Status**" so it silently skipped the rewrite, leaving the ticket in one status directory while its metadata claimed another. Replace the splicing with set_status_field, a line based rewrite that keeps every other line verbatim, inserts no stray newline, and errors when the Metadata section has no Status field. It also accepts the **-Status** spelling so tickets damaged by the old code are repaired as they move. The content is now computed before the rename, so a ticket without a Status field is never half-moved. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5
parent
12f34a3442
commit
8ff64614fc
+8
-22
@@ -328,32 +328,18 @@ pub fn cmd_mv(ticket_id: &str, target_status: &str, force: bool, start: &Path) -
|
||||
));
|
||||
}
|
||||
|
||||
// Read and update the ticket content
|
||||
let mut content = fs::read_to_string(current_path.join(&found_filename))?;
|
||||
|
||||
// Update Status in Metadata section
|
||||
if let Some(start_pos) = content.find("- **Status**") {
|
||||
// Skip "- " to find "**Status**"
|
||||
let status_start = start_pos + 2;
|
||||
let after_status = &content[status_start + "**Status**".len()..]; // after "**Status**"
|
||||
if after_status.starts_with(": ") {
|
||||
let rest = &after_status[2..];
|
||||
let value_end = rest.find('\n').unwrap_or(rest.len());
|
||||
let _value = &rest[..value_end];
|
||||
let before = &content[..status_start];
|
||||
let after = &rest[value_end..];
|
||||
content = format!("{}**-Status**: {}\n{}", before, target_status, after);
|
||||
}
|
||||
}
|
||||
// Read and update the ticket content before touching the filesystem, so a ticket
|
||||
// without a Status field is never half-moved.
|
||||
let source_path = current_path.join(&found_filename);
|
||||
let content = fs::read_to_string(&source_path)?;
|
||||
let content = set_status_field(&content, target_status, &title)?;
|
||||
|
||||
// Move the file
|
||||
fs::rename(
|
||||
current_path.join(&found_filename),
|
||||
target_path.join(&found_filename),
|
||||
)?;
|
||||
let dest_path = target_path.join(&found_filename);
|
||||
fs::rename(&source_path, &dest_path)?;
|
||||
|
||||
// Write back updated content
|
||||
fs::write(target_path.join(&found_filename), content)?;
|
||||
fs::write(&dest_path, content)?;
|
||||
|
||||
println!(
|
||||
"Moved ticket '{}' from {} to {}",
|
||||
|
||||
Reference in New Issue
Block a user