(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:
Ansho Rei
2026-08-20 13:33:44 +02:00
co-authored by Claude Opus 5
parent 12f34a3442
commit 8ff64614fc
3 changed files with 142 additions and 25 deletions
+31
View File
@@ -348,6 +348,37 @@ pub fn parse_ticket_field(content: &str, field: &str) -> String {
.unwrap_or("_Not set_".to_string())
}
fn is_status_line(line: &str) -> bool {
// The second spelling is what earlier versions wrote, repair it on the way through.
line.starts_with("- **Status**:") || line.starts_with("- **-Status**:")
}
// Rewrite the Status field in the Metadata section, leaving every other line untouched.
pub fn set_status_field(content: &str, target_status: &str, title: &str) -> Result<String> {
let mut updated = String::with_capacity(content.len());
let mut found = false;
for line in content.lines() {
if !found && is_status_line(line) {
updated.push_str("- **Status**: ");
updated.push_str(target_status);
found = true;
} else {
updated.push_str(line);
}
updated.push('\n');
}
if !found {
return Err(anyhow!(
"Ticket '{}' has no Status field in its Metadata section",
title
));
}
Ok(updated)
}
// Format created_at for display with proper spacing and formatting.
pub fn format_created_at(created_at: &str) -> String {
if created_at == "_Not set_" || created_at.is_empty() {