summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/core.rs52
-rw-r--r--src/main.rs23
2 files changed, 75 insertions, 0 deletions
diff --git a/src/core.rs b/src/core.rs
new file mode 100644
index 0000000..1223bb7
--- /dev/null
+++ b/src/core.rs
@@ -0,0 +1,52 @@
+use std::collections::HashMap;
+use std::path::PathBuf;
+use std::process;
+use ini::ini;
+
+pub struct GitRepository {
+ pub worktree: PathBuf,
+ gitdir: PathBuf,
+ conf: HashMap<String, HashMap<String, Option<String>>>
+}
+
+fn die(msg: &str) {
+ println!("{}", msg);
+ process::exit(1);
+}
+
+impl GitRepository {
+ pub fn new(worktree: PathBuf) -> Self {
+ let gitdir = worktree.join(".git");
+ let conf: HashMap<String, HashMap<String, Option<String>>> = HashMap::new();
+ Self { worktree, gitdir, conf }
+ }
+
+ pub fn from_dir(worktree: PathBuf) -> Self {
+ if !worktree.exists() {
+ die("Worktree does not exist");
+ }
+ let gitdir = worktree.join(".git");
+ if !gitdir.exists() {
+ die("Not a valid git repository");
+ }
+ let conf_file = gitdir.join("config");
+ if !conf_file.exists() {
+ die("Config file does not exist");
+ }
+ let conf = ini!(conf_file.to_str().unwrap());
+ let repo_format_version = conf["core"]["repositoryformatversion"].clone();
+ if let Some(version) = repo_format_version {
+ if version != "0" {
+ die("Unsupported format version");
+ }
+ } else {
+ die("Could not determine repository format version");
+ }
+
+ Self {
+ worktree,
+ gitdir,
+ conf
+ }
+ }
+} \ No newline at end of file
diff --git a/src/main.rs b/src/main.rs
new file mode 100644
index 0000000..a533003
--- /dev/null
+++ b/src/main.rs
@@ -0,0 +1,23 @@
+mod core;
+
+use clap::{Parser, Subcommand};
+
+#[derive(Parser)]
+#[command(version, about, long_about = None)]
+struct Cli {
+ #[command(subcommand)]
+ command: Command
+}
+
+#[derive(Subcommand)]
+enum Command {
+ Init,
+}
+
+
+fn main() {
+ let cli = Cli::parse();
+ match &cli.command {
+ Command::Init => { todo!() }
+ }
+} \ No newline at end of file