gitoxide_core/repository/
worktree.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
use crate::OutputFormat;
use anyhow::bail;

pub fn list(repo: gix::Repository, out: &mut dyn std::io::Write, format: OutputFormat) -> anyhow::Result<()> {
    if format != OutputFormat::Human {
        bail!("JSON output isn't implemented yet");
    }

    if let Some(worktree) = repo.worktree() {
        writeln!(
            out,
            "{base} [{branch}]",
            base = gix::path::realpath(worktree.base())?.display(),
            branch = repo
                .head_name()?
                .map_or("<detached>".into(), |name| name.shorten().to_owned()),
        )?;
    }
    for proxy in repo.worktrees()? {
        writeln!(
            out,
            "{base} [{name}]",
            base = proxy.base()?.display(),
            name = proxy.id()
        )?;
    }
    Ok(())
}