Skip to content

Commit 6b8063e

Browse files
swsnralexcrichton
authored andcommitted
Add support for remotes of branches
Wrap git_branch_upstream_name and git_branch_upstream_remote which retrieve the configured upstream remote and branch, but do not attempt to resolve them, i.e. these functions don't fail if the configured upstream doesn't exist. Closes rust-langGH-469
1 parent e7973c4 commit 6b8063e

File tree

2 files changed

+35
-0
lines changed

2 files changed

+35
-0
lines changed

libgit2-sys/lib.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2424,6 +2424,16 @@ extern "C" {
24242424
) -> c_int;
24252425
pub fn git_branch_upstream(out: *mut *mut git_reference, branch: *const git_reference)
24262426
-> c_int;
2427+
pub fn git_branch_upstream_name(
2428+
out: *mut git_buf,
2429+
repo: *mut git_repository,
2430+
refname: *const c_char,
2431+
) -> c_int;
2432+
pub fn git_branch_upstream_remote(
2433+
out: *mut git_buf,
2434+
repo: *mut git_repository,
2435+
refname: *const c_char,
2436+
) -> c_int;
24272437

24282438
// index
24292439
pub fn git_index_add(index: *mut git_index, entry: *const git_index_entry) -> c_int;

src/repo.rs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2433,6 +2433,31 @@ impl Repository {
24332433
Ok(())
24342434
}
24352435
}
2436+
2437+
/// Retrieves the name of the reference supporting the remote tracking branch,
2438+
/// given the name of a local branch reference.
2439+
pub fn branch_upstream_name(&self, refname: &str) -> Result<Buf, Error> {
2440+
let refname = CString::new(refname)?;
2441+
unsafe {
2442+
let buf = Buf::new();
2443+
try_call!(raw::git_branch_upstream_name(buf.raw(), self.raw, refname));
2444+
Ok(buf)
2445+
}
2446+
}
2447+
2448+
/// Retrieve the name of the upstream remote of a local branch.
2449+
pub fn branch_upstream_remote(&self, refname: &str) -> Result<Buf, Error> {
2450+
let refname = CString::new(refname)?;
2451+
unsafe {
2452+
let buf = Buf::new();
2453+
try_call!(raw::git_branch_upstream_remote(
2454+
buf.raw(),
2455+
self.raw,
2456+
refname
2457+
));
2458+
Ok(buf)
2459+
}
2460+
}
24362461
}
24372462

24382463
impl Binding for Repository {

0 commit comments

Comments
 (0)