brain: Return empty status without branches

09c463191089d5916cb03d07cc9e078d75b0d8bd
An empty repository has no trunk to select. Return an empty status model
before trunk selection so the CLI can render 'No branches.', while
nonempty repositories still require a trunk.

Assisted-by: Codex:gpt-5.6-sol
Alexis Sellier committed ago 1 parent 4a6561db
crates/brain/src/backend.rs +24 -0
725 725
    }
726 726
727 727
    /// Returns stored review statuses for all brain state refs.
728 728
    fn statuses(repository: &git::Repository) -> Result<Vec<BrainStatus>, Error> {
729 729
        let branches = repository.branches()?;
730 +
        if branches.is_empty() {
731 +
            return Ok(Vec::new());
732 +
        }
733 +
730 734
        let trunk = repository
731 735
            .trunk(&branches)?
732 736
            .ok_or_else(|| Error::Git("no trunk or master branch found".to_owned()))?;
733 737
        let trunk_rev = Rev::from(trunk.head);
734 738
        let mut stored = Brain::stored_reviews(repository)?;
1702 1706
        assert_eq!(rebased.state_ref, brain.state_ref);
1703 1707
        assert_eq!(rebased.target, second.id);
1704 1708
        assert_eq!(rebased.accepted, Accepted::from([second_identity]));
1705 1709
    }
1706 1710
1711 +
    #[test]
1712 +
    fn statuses_are_empty_in_repository_without_commits() {
1713 +
        let fixture = TestRepository::new();
1714 +
1715 +
        let statuses = statuses(fixture.path()).unwrap();
1716 +
1717 +
        assert!(statuses.is_empty());
1718 +
    }
1719 +
1720 +
    #[test]
1721 +
    fn statuses_require_trunk_in_nonempty_repository() {
1722 +
        let fixture = TestRepository::new();
1723 +
        fixture.git(&["branch", "-m", "topic"]);
1724 +
        fixture.git(&["commit", "-q", "--allow-empty", "-m", "topic"]);
1725 +
1726 +
        let error = statuses(fixture.path()).unwrap_err();
1727 +
1728 +
        assert_eq!(error.to_string(), "no trunk or master branch found");
1729 +
    }
1730 +
1707 1731
    #[test]
1708 1732
    fn statuses_match_symbolic_target_to_branch_commit() {
1709 1733
        let fixture = TestRepository::new();
1710 1734
        fixture.git(&["config", "init.defaultBranch", "main"]);
1711 1735
        fixture.git(&["commit", "-q", "--allow-empty", "-m", "base"]);
f +0 -0
new.rs +0 -0
image.png +0 -0
new.txt +0 -0