blob: 252af98031988eb647729e3d466a05ba1265db4e (
plain)
/*
* 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(())
}
|