Scoubi
Scoubi

Reputation: 35

Rust Git2 - How to specify the branch type to pull all (new) branches

After I cloned a git repo, I'm trying to keep it up to date by fetching and merging all new branches.

I have successfully cloned the repo but I can't seem to get all the branches to sync.

I found the .branches() that seems to go and fetch all branches names and .next or .collect that allows you to go through the returned results. I also saw that the value for the branches() method are either Local or Remote, if I read this correctly: https://docs.rs/git2/latest/src/git2/lib.rs.html#365-370

Now, I can't seem to figure out how to use .branches. Here's the code and output.

When I try:

let remote_name = "origin";
let repo = Repository::open(".").unwrap();
let mut remote = repo.find_remote(remote_name).expect("Can't find remote");
let br = repo.branches("Remote");

I get:

expected `Option<BranchType>`, found `&str`

So I try this:

let br = repo.branches(Some("Remote"));

and I get:

expected `BranchType`, found `&str`

I also tried:

let br = repo.branches(remote);

Which gives:

expected `Option<BranchType>`, found `Option<&str>`

So I'm kind of confused as to how to format it to pass the value correctly. I've tried with [] without luck.

Upvotes: 0

Views: 202

Answers (2)

Rick Gerssen
Rick Gerssen

Reputation: 7

thi wil work

let br = repo.branches(Some(BranchType::Remote));

here you can find more information: https://doc.rust-lang.org/book

Upvotes: -3

mkrieger1
mkrieger1

Reputation: 23192

"Remote" is a string, you need to use the value Remote of the BranchType enum instead:

let br = repo.branches(Some(BranchType::Remote));

See: https://doc.rust-lang.org/book/ch06-01-defining-an-enum.html#enum-values

Upvotes: 3

Related Questions