blob: 4a85206a550cd1f74e906c100d32f01075efc079 (
plain)
use auth_git2::GitAuthenticator;
use git_autosave::{Config, authenticate::Inquirer, commit_autosave, push_autosaves};
use git2::{RemoteCallbacks, Repository};
fn main() -> Result<(), anyhow::Error> {
let repository = Repository::discover(".")?;
let gitconfig = repository.config()?;
let config: &'static mut Config = Box::leak(Box::new(git_autosave::load_config()?));
if std::env::args().any(|arg| arg == "--init") {
let id = git_autosave::init(&repository, Some(config))?;
git_autosave::save_config(config)?;
println!("Initialized autosave for repository: {id}");
}
let auth = GitAuthenticator::new().set_prompter(Inquirer(config));
let mut callbacks = RemoteCallbacks::new();
callbacks.credentials(auth.credentials(&gitconfig));
let commit = commit_autosave(&repository)?;
println!("Commited autosave: {commit}");
push_autosaves(&repository, callbacks)?;
println!("Successfully pushed autosave to remote");
Ok(())
}
|