gitoxide_core/repository/
worktree.rs

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