diff --git a/libgit2-sys/lib.rs b/libgit2-sys/lib.rs index 234ec3003a..0f1b942497 100644 --- a/libgit2-sys/lib.rs +++ b/libgit2-sys/lib.rs @@ -2424,6 +2424,16 @@ extern "C" { ) -> c_int; pub fn git_branch_upstream(out: *mut *mut git_reference, branch: *const git_reference) -> c_int; + pub fn git_branch_upstream_name( + out: *mut git_buf, + repo: *mut git_repository, + refname: *const c_char, + ) -> c_int; + pub fn git_branch_upstream_remote( + out: *mut git_buf, + repo: *mut git_repository, + refname: *const c_char, + ) -> c_int; // index pub fn git_index_add(index: *mut git_index, entry: *const git_index_entry) -> c_int; diff --git a/src/repo.rs b/src/repo.rs index 02e660d9d2..451f912ad1 100644 --- a/src/repo.rs +++ b/src/repo.rs @@ -2433,6 +2433,31 @@ impl Repository { Ok(()) } } + + /// Retrieves the name of the reference supporting the remote tracking branch, + /// given the name of a local branch reference. + pub fn branch_upstream_name(&self, refname: &str) -> Result { + let refname = CString::new(refname)?; + unsafe { + let buf = Buf::new(); + try_call!(raw::git_branch_upstream_name(buf.raw(), self.raw, refname)); + Ok(buf) + } + } + + /// Retrieve the name of the upstream remote of a local branch. + pub fn branch_upstream_remote(&self, refname: &str) -> Result { + let refname = CString::new(refname)?; + unsafe { + let buf = Buf::new(); + try_call!(raw::git_branch_upstream_remote( + buf.raw(), + self.raw, + refname + )); + Ok(buf) + } + } } impl Binding for Repository {