git_side/commands/
init.rs1use std::path::Path;
2
3use colored::Colorize;
4
5use crate::config;
6use crate::error::Result;
7use crate::git;
8
9pub fn run(path: Option<&Path>) -> Result<()> {
15 let work_tree = git::repo_root()?;
17 let path_hash = config::hash_path(&work_tree);
18
19 let root_sha = if let Some(sha) = config::cache_lookup(&path_hash)? {
21 sha
22 } else {
23 let sha = git::initial_commit_sha()?;
24 config::cache_store(&path_hash, &sha)?;
25 sha
26 };
27
28 if let Some(base_path) = path {
30 config::paths_store(&root_sha, base_path)?;
31
32 println!(
33 "{} Side repo will be stored at: {}",
34 "Initialized.".green().bold(),
35 base_path.join(&root_sha).display()
36 );
37 } else {
38 let default_path = config::default_base_path().join(&root_sha);
39 println!(
40 "{} Side repo will be stored at: {}",
41 "Initialized.".green().bold(),
42 default_path.display()
43 );
44 }
45
46 Ok(())
47}