| 1 |
/* |
| 2 |
* libgit2 "ls-remote" example |
| 3 |
* |
| 4 |
* Written by the libgit2 contributors |
| 5 |
* |
| 6 |
* To the extent possible under law, the author(s) have dedicated all copyright |
| 7 |
* and related and neighboring rights to this software to the public domain |
| 8 |
* worldwide. This software is distributed without any warranty. |
| 9 |
* |
| 10 |
* You should have received a copy of the CC0 Public Domain Dedication along |
| 11 |
* with this software. If not, see |
| 12 |
* <http://creativecommons.org/publicdomain/zero/1.0/>. |
| 13 |
*/ |
| 14 |
|
| 15 |
#![deny(warnings)] |
| 16 |
|
| 17 |
use clap::Parser; |
| 18 |
use git2::{Direction, Repository}; |
| 19 |
|
| 20 |
#[derive(Parser)] |
| 21 |
struct Args { |
| 22 |
#[structopt(name = "remote")] |
| 23 |
arg_remote: String, |
| 24 |
} |
| 25 |
|
| 26 |
fn run(args: &Args) -> Result<(), git2::Error> { |
| 27 |
let repo = Repository::open(".")?; |
| 28 |
let remote = &args.arg_remote; |
| 29 |
let mut remote = repo |
| 30 |
.find_remote(remote) |
| 31 |
.or_else(|_| repo.remote_anonymous(remote))?; |
| 32 |
|
| 33 |
// Connect to the remote and call the printing function for each of the |
| 34 |
// remote references. |
| 35 |
let connection = remote.connect_auth(Direction::Fetch, None, None)?; |
| 36 |
|
| 37 |
// Get the list of references on the remote and print out their name next to |
| 38 |
// what they point to. |
| 39 |
for head in connection.list()?.iter() { |
| 40 |
println!("{}\t{}", head.oid(), head.name()); |
| 41 |
} |
| 42 |
Ok(()) |
| 43 |
} |
| 44 |
|
| 45 |
fn main() { |
| 46 |
let args = Args::parse(); |
| 47 |
match run(&args) { |
| 48 |
Ok(()) => {} |
| 49 |
Err(e) => println!("error: {}", e), |
| 50 |
} |
| 51 |
} |