step fifty six: print remote refs

This commit is contained in:
Gonçalo Valério 2020-12-01 23:15:21 +00:00
parent 027bad5d5f
commit 65773a5317
2 changed files with 25 additions and 0 deletions

View File

@ -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<String, Vec<String>>) {
let ref_str = if refs.contains_key(&oid) {
refs.get_mut(&oid).unwrap().join(", ")

11
src/remote.rs Normal file
View File

@ -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();
}