gitbutlerapp/gitbutler · error
cannot mix mark sources
Error message
cannot mix mark sources
What it means
The TUI status `Marks` enum is a single-variant-of-each state machine: it can hold marks of exactly one source kind (hunks/files vs commits vs committed files). `insert_mark` for `UncommittedHunkOrFile` only supports `Empty` and `Hunks`; any other variant is a state-machine violation and bails with 'cannot mix mark sources'.
Solutions
- Clear the current marks (unmark / press the clear-marks key) before marking items of a different source kind.
- Mark only items from one source (uncommitted hunks/files OR commits OR committed files) per apply operation.
- If this fires from a keybinding path, fix the caller to call `remove_mark`/clear before switching mark domains.
Example fix
// before: app code inserting without clearing
marks.insert_hunk_or_file(hunk)?; // marks currently Commits -> bail
// after
if !matches!(marks, Marks::Empty | Marks::Hunks(_)) {
marks = Marks::Empty;
}
marks.insert_hunk_or_file(hunk)?; Defensive patterns
Strategy: try-catch
Validate before calling
fn can_insert_hunk_or_file(marks: &Marks) -> bool {
matches!(marks, Marks::Empty | Marks::Hunks(_))
} Type guard
fn is_hunk_or_file_state(m: &Marks) -> bool {
matches!(m, Marks::Empty | Marks::Hunks(_))
} Try / catch
if let Err(e) = marks.insert_hunk_or_file(mark) {
if e.to_string().contains("cannot mix mark sources") {
marks = Marks::Empty;
marks.insert_hunk_or_file(mark)?;
} else { return Err(e); }
} Prevention
- Clear the mark set whenever the TUI focus moves between source panes
- Only one mark source per apply operation
- Add a UI-level guard that unmarks before switching domains
When it happens
Trigger: Inserting an uncommitted hunk/file mark while the marks state currently holds `Commits` or `CommittedFiles` — i.e. the user (or a TUI keybinding) marks a commit, then attempts to mark a working-tree hunk/file without clearing first.
Common situations: In the `but` TUI: selecting commits in one pane, then marking hunks/files from the uncommitted-changes pane; a keyboard shortcut or mouse path that skips the implicit clear of prior marks.
Understand the failure class
Background: "Invalid state transition" errors: "status must be X, actually Y", "already rejected/charging/uninstalled", "cannot ... while running" — what they mean when a library rejects your call — this error's family across 31 libraries.
Related errors
- cannot mark files from multiple commits
- command exited with status
- Commit has no conflicted files to resolve
- commits cannot be moved to the merge base
- committing stack assignments is not supported. Use `but…
AI-assisted analysis of gitbutlerapp/gitbutler@58e5313667 (2026-09-18).
Data as JSON: /api/errors/e9343162fec7ea3d.
Report an issue: GitHub.
Appendix: source
Thrown at crates/but/src/command/legacy/status/tui/app/mark.rs:367
}
}
impl MarkStore<UncommittedHunkOrFile> for Marks {
type Error = anyhow::Error;
fn contains_mark(&self, mark: &UncommittedHunkOrFile) -> bool {
self.as_hunks()
.is_some_and(|hunks| hunks.iter().any(|hunk| hunk == mark))
}
fn insert_mark(&mut self, mark: UncommittedHunkOrFile) -> Result<(), Self::Error> {
if self.contains_mark(&mark) {
return Ok(());
}
match self {
Self::Empty => *self = Self::Hunks(NonEmpty::new(mark)),
Self::Hunks(hunks) => hunks.push(mark),
_ => anyhow::bail!("cannot mix mark sources"),
}
Ok(())
}
fn remove_mark(&mut self, mark: &UncommittedHunkOrFile) {
let Self::Hunks(hunks) = self else {
return;
};
if remove_from_non_empty(hunks, |marked| marked == mark) {
*self = Self::Empty;
}
}
}
impl MarkStore<CommitId> for Marks {
type Error = anyhow::Error;
View on GitHub (pinned to 58e5313667)