gitoxide_core/repository/
worktree.rs

1use crate::OutputFormat;
2use anyhow::bail;
3
4pub fn list(repo: gix::Repository, out: &mut dyn std::io::Write, format: OutputFormat) -> anyhow::Result<()> {
5    if format != OutputFormat::Human {
6        bail!("JSON output isn't implemented yet");
7    }
8
9    if let Some(worktree) = repo.worktree() {
10        writeln!(
11            out,
12            "{base} [{branch}]",
13            base = gix::path::realpath(worktree.base())?.display(),
14            branch = repo
15                .head_name()?
16                .map_or("<detached>".into(), |name| name.shorten().to_owned()),
17        )?;
18    }
19    for proxy in repo.worktrees()? {
20        writeln!(
21            out,
22            "{base} [{name}]",
23            base = proxy.base()?.display(),
24            name = proxy.id()
25        )?;
26    }
27    Ok(())
28}