{"record":{"id":"9a511b64458ae55f","repo":"GitoxideLabs/gitoxide","slug":"the-rebase-state-repeats-its-head-ref","errorCode":null,"errorMessage":"the rebase state repeats its HEAD ref","messagePattern":"the rebase state repeats its HEAD ref","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"gix-tix/src/edit/todo.rs","lineNumber":715,"sourceCode":"                    anyhow::bail!(\"the rebase state repeats marker-required\");\n                }\n            }\n            \"checkout-allowed\" => {\n                if checkout_allowed.replace(value.parse()?).is_some() {\n                    anyhow::bail!(\"the rebase state repeats checkout-allowed\");\n                }\n            }\n            \"head-ref\" => {\n                let encoded = value.as_bytes().as_bstr();\n                let (name, consumed) = gix::quote::ansi_c::undo(encoded)\n                    .map_err(gix::Exn::into_error)\n                    .context(\"could not unquote the recorded HEAD ref\")?;\n                if !encoded[consumed..].trim().is_empty() {\n                    anyhow::bail!(\"the recorded HEAD ref has trailing data\");\n                }\n                let name = gix::refs::FullName::try_from(name.as_ref()).context(\"the recorded HEAD ref is invalid\")?;\n                if head_ref.replace(name).is_some() {\n                    anyhow::bail!(\"the rebase state repeats its HEAD ref\");\n                }\n            }\n            \"edit-refs\" => edit_refs = value.parse()?,\n            \"ref\" => {\n                let (old, value) = value.split_once(' ').context(\"a captured ref has no target\")?;\n                let (target, value) = value.split_once(' ').context(\"a captured ref has no follow mode\")?;\n                let old = (old != \"-\").then(|| ObjectId::from_hex(old.as_bytes())).transpose()?;\n                let target = ObjectId::from_hex(target.as_bytes())?;\n                let (follows_tip, value) = value.split_once(' ').context(\"a captured ref has no name\")?;\n                let follows_tip = follows_tip.parse()?;\n                let (editable, name) = value\n                    .split_once(' ')\n                    .and_then(|(editable, name)| editable.parse::<bool>().ok().map(|editable| (editable, name)))\n                    .unwrap_or((false, value));\n                let encoded_name = name.as_bytes().as_bstr();\n                let (name, consumed) = gix::quote::ansi_c::undo(encoded_name)\n                    .map_err(gix::Exn::into_error)\n                    .context(\"could not unquote a captured ref name\")?;","sourceCodeStart":697,"sourceCodeEnd":733,"githubUrl":"https://github.com/GitoxideLabs/gitoxide/blob/e73179060badf27222d790981fac3f84c1830a7e/gix-tix/src/edit/todo.rs#L697-L733","documentation":"`parse_state` allows the `head-ref` field only once per rebase state file. When a second `head-ref` line is parsed, the `head_ref.replace(...)` returns `Some`, indicating a repeat, and parsing aborts. This guards the single-valued field against silent overwrite of the recorded HEAD reference.","triggerScenarios":"`parse_state` (gix-tix/src/edit/todo.rs:715) reading a state file with two `head-ref` lines — from hand edits, corrupted state, or tooling that appends fields.","commonSituations":"Merged state files from conflicting edits; duplicated lines from faulty scripts or editors; copying state between worktrees and concatenating content.","solutions":["Remove the duplicate `head-ref` line, keeping exactly one valid fully-qualified ref name.","Restart the rebase/edit operation to regenerate clean state.","Audit any scripts or automation that modify the state file to ensure they replace rather than append fields."],"exampleFix":"// before (state file)\nhead-ref \"refs/heads/main\"\nhead-ref \"refs/heads/other\"\n// after\nhead-ref \"refs/heads/main\"","handlingStrategy":"validation","validationCode":"fn state_file_is_clean(text: &str) -> bool {\n    text.lines().filter(|l| l.starts_with(\"head-ref \")).count() <= 1\n}","typeGuard":null,"tryCatchPattern":"match todo::parse(state_text) {\n    Ok(state) => apply(state),\n    Err(e) if e.to_string().contains(\"repeats its HEAD ref\") => {\n        eprintln!(\"corrupt state: duplicate head-ref; keep exactly one\");\n    }\n    Err(e) => return Err(e),\n}","preventionTips":["Use replace-not-append semantics when updating head-ref programmatically.","Run a duplicate-key lint over generated state files.","Avoid merging state files from separate sessions."],"tags":["rebase","state-parsing","duplicate-field","git"],"backgroundTag":"schema-validation-failed","analyzedSha":"e73179060badf27222d790981fac3f84c1830a7e","analyzedAt":"2026-09-08T11:26:50.865Z","contentChangedAt":"2026-09-08T11:26:50.865Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}