{"record":{"id":"2afed5bdb4af8cd9","repo":"gitbutlerapp/gitbutler","slug":"cannot-mark-files-from-multiple-commits","errorCode":null,"errorMessage":"cannot mark files from multiple commits","messagePattern":"cannot mark files from multiple commits","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/but/src/command/legacy/status/tui/app/mark.rs","lineNumber":430,"sourceCode":"}\n\nimpl MarkStore<CommittedFileId> for Marks {\n    type Error = anyhow::Error;\n\n    fn contains_mark(&self, mark: &CommittedFileId) -> bool {\n        self.as_committed_files()\n            .is_some_and(|files| files.iter().any(|file| file == mark))\n    }\n\n    fn insert_mark(&mut self, mark: CommittedFileId) -> Result<(), Self::Error> {\n        if self.contains_mark(&mark) {\n            return Ok(());\n        }\n        match self {\n            Self::Empty => *self = Self::CommittedFiles(NonEmpty::new(mark)),\n            Self::CommittedFiles(files) => {\n                if files.head.commit_id != mark.commit_id {\n                    anyhow::bail!(\"cannot mark files from multiple commits\");\n                }\n                files.push(mark);\n            }\n            _ => anyhow::bail!(\"cannot mix mark sources\"),\n        }\n        Ok(())\n    }\n\n    fn remove_mark(&mut self, mark: &CommittedFileId) {\n        let Self::CommittedFiles(files) = self else {\n            return;\n        };\n\n        if remove_from_non_empty(files, |marked| marked == mark) {\n            *self = Self::Empty;\n        }\n    }\n}","sourceCodeStart":412,"sourceCodeEnd":448,"githubUrl":"https://github.com/gitbutlerapp/gitbutler/blob/58e5313667b857ef39a730e380af31816a7b1768/crates/but/src/command/legacy/status/tui/app/mark.rs#L412-L448","documentation":"Committed-file marks are additionally constrained to a single commit: the `CommittedFiles` list stores a `commit_id` on its head, and inserting a file from a different commit would silently create a mixed-selection apply. The code bails with 'cannot mark files from multiple commits' (and a foreign variant still bails with 'cannot mix mark sources').","triggerScenarios":"Inserting a `CommittedFileId` whose `commit_id` differs from the commit of the currently held `CommittedFiles` head — e.g. marking files from commit A, then marking a file from commit B in the same selection.","commonSituations":"TUI multi-commit list where the user marks files across several commits then applies; a mouse-drag or shift-click range spanning commits.","solutions":["Unmark the current committed files before marking files from a different commit.","Perform one apply per commit: mark files of commit A, apply, then commit B.","Fix selection UI to reset marks when the focused commit changes."],"exampleFix":"// before: spanning commits\nmark(file_from_commit_b)?; // head.commit_id == A -> bail\n// after\nif marks_head_commit() != Some(file.commit_id) {\n    marks = Marks::Empty;\n}\nmark(file)?;","handlingStrategy":"try-catch","validationCode":"fn can_insert_committed_file(marks: &Marks, f: &CommittedFileId) -> bool {\n    match marks {\n        Marks::Empty => true,\n        Marks::CommittedFiles(files) => files.head.commit_id == f.commit_id,\n        _ => false,\n    }\n}","typeGuard":"fn same_commit(m: &Marks, f: &CommittedFileId) -> bool {\n    match m {\n        Marks::Empty => true,\n        Marks::CommittedFiles(files) => files.head.commit_id == f.commit_id,\n        _ => false,\n    }\n}","tryCatchPattern":"if let Err(e) = marks.insert_committed_file(file) {\n    let msg = e.to_string();\n    if msg.contains(\"multiple commits\") || msg.contains(\"cannot mix mark sources\") {\n        marks = Marks::Empty;\n        marks.insert_committed_file(file)?;\n    } else { return Err(e); }\n}","preventionTips":["Reset committed-file marks when the selected commit changes","Prevent range-selection from spanning commits in the TUI","Apply per commit rather than batching files across commits"],"tags":["tui","state-machine","selection","marks"],"backgroundTag":"invalid-state-transition","analyzedSha":"58e5313667b857ef39a730e380af31816a7b1768","analyzedAt":"2026-09-18T06:50:32.052Z","contentChangedAt":"2026-09-18T06:50:32.052Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}