diff --git a/src/main.rs b/src/main.rs index 04d421c..d5f89e3 100644 --- a/src/main.rs +++ b/src/main.rs @@ -6,6 +6,7 @@ use std::process::{Command, Stdio}; mod base; mod data; mod diff; +mod remote; fn main() { let matches = App::new("rgit vcs") @@ -92,6 +93,11 @@ fn main() { .arg(Arg::with_name("commit1").index(1).required(true)) .arg(Arg::with_name("commit2").index(2).required(true)), ) + .subcommand( + SubCommand::with_name("fetch") + .about("Fetch refs and objects from another repository") + .arg(Arg::with_name("remote").index(1).required(true)), + ) .get_matches(); data::set_rgit_dir("."); @@ -113,6 +119,7 @@ fn main() { Some("diff") => difference(matches), Some("merge") => merge(matches), Some("merge-base") => merge_base(matches), + Some("fetch") => fetch(matches), _ => println!("unknown sub command"), } data::reset_rgit_dir(); @@ -343,6 +350,13 @@ fn merge_base(matches: ArgMatches) { } } +fn fetch(matches: ArgMatches) { + if let Some(cmd_matches) = matches.subcommand_matches("fetch") { + let remote_path = cmd_matches.value_of("remote").unwrap().to_owned(); + remote::fetch(remote_path); + } +} + fn print_commit(oid: String, commit: &base::Commit, mut refs: HashMap>) { let ref_str = if refs.contains_key(&oid) { refs.get_mut(&oid).unwrap().join(", ") diff --git a/src/remote.rs b/src/remote.rs new file mode 100644 index 0000000..8365a94 --- /dev/null +++ b/src/remote.rs @@ -0,0 +1,11 @@ +#[path = "data.rs"] +mod data; + +pub fn fetch(path: String) { + println!("Will fetch the following refs:"); + data::set_rgit_dir(path.as_str()); + for (refname, _) in data::iter_refs("refs/heads", true) { + println!(" - {}", refname); + } + data::reset_rgit_dir(); +}