gitoxide_core/repository/revision/
previous_branches.rs1use anyhow::Context;
2
3use crate::OutputFormat;
4
5pub fn previous_branches(
6 repo: gix::Repository,
7 mut out: impl std::io::Write,
8 format: OutputFormat,
9) -> anyhow::Result<()> {
10 let branches = repo
11 .head()?
12 .prior_checked_out_branches()?
13 .context("The reflog for HEAD is required")?;
14 match format {
15 OutputFormat::Human => {
16 for (name, id) in branches {
17 writeln!(out, "{id} {name}")?;
18 }
19 }
20 #[cfg(feature = "serde")]
21 OutputFormat::Json => {
22 serde_json::to_writer_pretty(&mut out, &branches)?;
23 }
24 }
25 Ok(())
26}