Skip to content

Instantly share code, notes, and snippets.

@riggtravis
Last active May 13, 2020 14:50
Show Gist options
  • Save riggtravis/fa097b5ecc87a5ee3d2c0753f83a858a to your computer and use it in GitHub Desktop.
Save riggtravis/fa097b5ecc87a5ee3d2c0753f83a858a to your computer and use it in GitHub Desktop.
An example of some rust code using libgit2
use git2;
fn main() {
let repo = git2::Repository::open(".").unwrap();
let remotes: Vec<git2::Remote> = repo
.remotes()
.unwrap()
.iter()
.map(|remote| repo.find_remote(remote.unwrap()).unwrap())
.collect();
let refspec_pairings = remotes.iter().map(
|remote| (remote, remote.refspecs())
);
refspec_pairings.for_each(
|refspec_pairing| refspec_pairing.1.for_each(
|refspec| println!(
"{} {} {}",
refspec_pairing.0.name().unwrap(),
refspec_pairing.0.url().unwrap(),
match refspec.direction() {
git2::Direction::Fetch => "(fetch)",
git2::Direction::Push => "(push)"
}
)
)
)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment