use clap::Parser;
use pijul_core::TxnT;
use pijul_repository::Repository;
use std::io::Write;
use std::path::{Path, PathBuf};
use crate::commands::common_opts::RepoAndChannel;
#[derive(Parser, Debug)]
pub struct Status {
#[clap(flatten)]
pub base: RepoAndChannel,
#[clap(long = "tag")]
pub tag: bool,
#[clap(short = 'u', long = "untracked")]
pub untracked: bool,
#[clap(short = 'U', long = "only-untracked")]
pub only_untracked: bool,
pub prefixes: Vec<PathBuf>,
}
impl Status {
pub fn repository_path(&self) -> Option<&Path> {
self.base.repo_path()
}
pub fn run(self, config: &pijul_config::Config) -> Result<(), anyhow::Error> {
let repo = Repository::find_root(self.base.repo_path())?;
let mut stdout = std::io::stdout();
{
let txn = repo.pristine.txn_begin()?;
let current = txn.current_channel().ok();
writeln!(
stdout,
"{}",
current.map_or_else(|| "Not on a channel".into(), |c| format!("On channel: {c}"))
)?;
}
if self.only_untracked {
let txn = repo.pristine.arc_txn_begin()?;
return super::diff::print_untracked_files(&repo, txn);
}
let diff = super::Diff {
base: self.base,
json: false,
tag: self.tag,
short: true,
untracked: self.untracked,
prefixes: self.prefixes,
patience: false,
histogram: false,
};
diff.run(config)
}
}