summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMica White <botahamec@outlook.com>2026-03-28 14:28:42 -0400
committerMica White <botahamec@outlook.com>2026-03-28 14:28:42 -0400
commitc9d8448fcbc3e79668fc5d33bd4f1e33a3f3d25c (patch)
treedf081ffed90b13cd49151eb5cc0c8bedf2522cab /src
Init autosave command
Diffstat (limited to 'src')
-rw-r--r--src/bin/init-autosave.rs10
-rw-r--r--src/lib.rs72
2 files changed, 82 insertions, 0 deletions
diff --git a/src/bin/init-autosave.rs b/src/bin/init-autosave.rs
new file mode 100644
index 0000000..df3b66d
--- /dev/null
+++ b/src/bin/init-autosave.rs
@@ -0,0 +1,10 @@
+use git2::Repository;
+use git_autosave::{init, load_config, save_config};
+
+fn main() -> Result<(), anyhow::Error> {
+ let repository = Repository::discover(".")?;
+ let mut config = load_config()?;
+ init(&repository, Some(&mut config))?;
+ save_config(&config)?;
+ Ok(())
+}
diff --git a/src/lib.rs b/src/lib.rs
new file mode 100644
index 0000000..252af98
--- /dev/null
+++ b/src/lib.rs
@@ -0,0 +1,72 @@
+/*
+ * git-init-autosave:
+ * - generate local repo UUID
+ * - add repo to autosave configuration (optionally)
+ *
+ * git-autosave:
+ * - convert workdir to tree
+ * - note hostname
+ * - commit workdir to `refs/autosave/{UUID}-{branch}`
+ * - push autosave ref to branch upstream
+ *
+ * git-autosave-daemon:
+ * - watch configuration directory
+ * - watch configured repositories
+ * - run autosave on change
+ *
+ * git-restore-autosave:
+ * - fetch upstream's autosaves
+ * - filter to autosaves from the local user and branch
+ * - display available autosaves if there is more than one
+ * - check for conflicts between workdir and autosave
+ * - save workdir to `refs/autosave/undo`
+ * - copy autosave to `refs/autosave/restored` with new commit
+ * - apply tree to workdir
+ * - allow `git restore-autosave --force`
+ * - allow a device to be specified by name or UUID
+ *
+ * git-merge-autosave:
+ * - error is workdir is dirty
+ * - check default merge strategy
+ * - merge autosave using default strategy
+ * - allow a different merge strategy to be specified
+ * - display available autosaves if there is more than one
+ *
+ * git undo-restore-autosave:
+ * - check for differences between workdir and restored save
+ * - error if there are unsaved changes
+ * - apply `refs/autosave/undo` to tree
+ * - allow force
+ */
+
+use std::path::PathBuf;
+
+use confy::ConfyError;
+use git2::{Error, Repository};
+use serde::{Deserialize, Serialize};
+use uuid::Uuid;
+
+#[derive(Default, Serialize, Deserialize)]
+pub struct Config {
+ repositories: Vec<PathBuf>,
+}
+
+pub fn load_config() -> Result<Config, ConfyError> {
+ confy::load("git-autosave", None)
+}
+
+pub fn save_config(config: &Config) -> Result<(), ConfyError> {
+ confy::store("git-autosave", None, config)
+}
+
+pub fn init(repository: &Repository, config: Option<&mut Config>) -> Result<(), Error> {
+ let id = Uuid::new_v4();
+ let workdir = repository.workdir();
+ repository.config()?.set_str("autosave.id", &id.to_string())?;
+
+ if let Some(config) = config && let Some(workdir) = workdir {
+ config.repositories.push(workdir.into());
+ }
+
+ Ok(())
+}