git_psect/commands/
start.rs1use crate::{
2 error::Error,
3 repo,
4 state::{self, Meta, State},
5};
6
7pub fn run() -> Result<(), Error> {
8 let ctx = repo::open()?;
9 let state_path = ctx.state_dir.join("state.toml");
10 if state_path.exists() {
11 return Err(Error::Validation(
12 "session already exists — run 'git psect reset' first".into(),
13 ));
14 }
15
16 let state = State {
17 meta: Meta {
18 tool_version: env!("CARGO_PKG_VERSION").into(),
19 started_at: chrono::Utc::now().to_rfc3339(),
20 },
21 priors: Default::default(),
22 old_revisions: vec![],
23 new_revisions: vec![],
24 samples: vec![],
25 };
26
27 state::write(&ctx.state_dir, &state)?;
28 println!("Session initialized.");
29 println!("{}", super::session::advance(&ctx.repo, &state)?);
30 Ok(())
31}