Last active
May 13, 2020 14:50
-
-
Save riggtravis/fa097b5ecc87a5ee3d2c0753f83a858a to your computer and use it in GitHub Desktop.
An example of some rust code using libgit2
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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