mirror of
https://github.com/qwjyh/xdbm
synced 2024-11-22 14:50:12 +09:00
(WIP) implement sync
This commit is contained in:
parent
498dd2db9b
commit
d1f7a4787e
3 changed files with 28 additions and 4 deletions
|
@ -45,7 +45,10 @@ pub(crate) enum Commands {
|
||||||
Path {},
|
Path {},
|
||||||
|
|
||||||
/// Sync with git repo.
|
/// Sync with git repo.
|
||||||
Sync {},
|
Sync {
|
||||||
|
/// Remote name to sync.
|
||||||
|
remote_name: Option<String>,
|
||||||
|
},
|
||||||
|
|
||||||
/// Check config files.
|
/// Check config files.
|
||||||
Check {},
|
Check {},
|
||||||
|
|
22
src/cmd_sync.rs
Normal file
22
src/cmd_sync.rs
Normal file
|
@ -0,0 +1,22 @@
|
||||||
|
use std::path::PathBuf;
|
||||||
|
|
||||||
|
use anyhow::{anyhow, Result};
|
||||||
|
use git2::Repository;
|
||||||
|
|
||||||
|
pub(crate) fn cmd_sync(config_dir: &PathBuf, remote_name: Option<String>) -> Result<()> {
|
||||||
|
warn!("Experimental");
|
||||||
|
let repo = Repository::open(config_dir)?;
|
||||||
|
let remote_name = match remote_name {
|
||||||
|
Some(remote_name) => remote_name,
|
||||||
|
None => {
|
||||||
|
let remotes = repo.remotes()?;
|
||||||
|
if remotes.len() != 1 {
|
||||||
|
return Err(anyhow!("Please specify remote name"));
|
||||||
|
}
|
||||||
|
remotes.get(0).unwrap().to_string()
|
||||||
|
}
|
||||||
|
};
|
||||||
|
let mut remote = repo.find_remote(&remote_name)?;
|
||||||
|
remote.push(&[] as &[&str], None)?;
|
||||||
|
Ok(())
|
||||||
|
}
|
|
@ -33,6 +33,7 @@ use devices::{Device, DEVICESFILE, *};
|
||||||
mod cmd_args;
|
mod cmd_args;
|
||||||
mod cmd_init;
|
mod cmd_init;
|
||||||
mod cmd_storage;
|
mod cmd_storage;
|
||||||
|
mod cmd_sync;
|
||||||
mod devices;
|
mod devices;
|
||||||
mod inquire_filepath_completer;
|
mod inquire_filepath_completer;
|
||||||
mod storages;
|
mod storages;
|
||||||
|
@ -91,9 +92,7 @@ fn main() -> Result<()> {
|
||||||
Commands::Path {} => {
|
Commands::Path {} => {
|
||||||
println!("{}", &config_dir.display());
|
println!("{}", &config_dir.display());
|
||||||
}
|
}
|
||||||
Commands::Sync {} => {
|
Commands::Sync { remote_name } => cmd_sync::cmd_sync(&config_dir, remote_name)?,
|
||||||
unimplemented!("Sync is not implemented")
|
|
||||||
}
|
|
||||||
Commands::Check {} => {
|
Commands::Check {} => {
|
||||||
println!("Config dir: {}", &config_dir.display());
|
println!("Config dir: {}", &config_dir.display());
|
||||||
let _storages = Storages::read(&config_dir)?;
|
let _storages = Storages::read(&config_dir)?;
|
||||||
|
|
Loading…
Reference in a new issue