pijul 1.0.0-alpha

The sound distributed version control system.
use crate::repository::Repository;
use libanu::pristine::{MutTxnT, TxnT};
use libanu::MutTxnTExt;
use std::path::PathBuf;

#[derive(Clap, Debug)]
pub struct Checkout {
    #[clap(long = "repository")]
    repo_path: Option<PathBuf>,
    channel: String,
}

impl Checkout {
    pub fn run(self) -> Result<(), anyhow::Error> {
        let mut repo = Repository::find_root(self.repo_path)?;
        debug!("{:?}", repo.config);
        let mut txn = repo.pristine.mut_txn_begin();
        if let Some(mut channel) = txn.load_channel(&self.channel) {
            txn.output_repository_no_pending(
                &mut repo.working_copy,
                &repo.changes,
                &mut channel,
                "",
                true,
            )?;
        }
        txn.commit()?;
        repo.config.current_channel = Some(self.channel);
        repo.save_config()?;
        Ok(())
    }
}