diff --git a/libgit2-sys/lib.rs b/libgit2-sys/lib.rs index dd1106b7b6..726e852532 100644 --- a/libgit2-sys/lib.rs +++ b/libgit2-sys/lib.rs @@ -1872,6 +1872,9 @@ extern { pub fn git_reference_lookup(out: *mut *mut git_reference, repo: *mut git_repository, name: *const c_char) -> c_int; + pub fn git_reference_dwim(out: *mut *mut git_reference, + repo: *mut git_repository, + refname: *const c_char) -> c_int; pub fn git_reference_name(r: *const git_reference) -> *const c_char; pub fn git_reference_name_to_id(out: *mut git_oid, repo: *mut git_repository, diff --git a/src/index.rs b/src/index.rs index 9c618c7ef0..87851b2141 100644 --- a/src/index.rs +++ b/src/index.rs @@ -33,13 +33,13 @@ pub struct IndexConflicts<'index> { /// A structure to represent the information returned when a conflict is detected in an index entry pub struct IndexConflict { /// The ancestor index entry of the two conflicting index entries - pub ancestor: IndexEntry, + pub ancestor: Option, /// The index entry originating from the user's copy of the repository. /// Its contents conflict with 'their' index entry - pub our: IndexEntry, + pub our: Option, /// The index entry originating from the external repository. /// Its contents conflict with 'our' index entry - pub their: IndexEntry, + pub their: Option, } /// A callback function to filter index matches. @@ -588,9 +588,18 @@ impl<'index> Iterator for IndexConflicts<'index> { self.conflict_iter )); Some(Ok(IndexConflict { - ancestor: IndexEntry::from_raw(*ancestor), - our: IndexEntry::from_raw(*our), - their: IndexEntry::from_raw(*their), + ancestor: match ancestor.is_null() { + false => Some(IndexEntry::from_raw(*ancestor)), + true => None, + }, + our: match our.is_null() { + false => Some(IndexEntry::from_raw(*our)), + true => None, + }, + their: match their.is_null() { + false => Some(IndexEntry::from_raw(*their)), + true => None, + }, })) } } diff --git a/src/repo.rs b/src/repo.rs index 263beb7006..4cb1b9c77b 100644 --- a/src/repo.rs +++ b/src/repo.rs @@ -1218,6 +1218,19 @@ impl Repository { } } + /// Lookup a reference to one of the objects in a repository. + /// `Repository::find_reference` with teeth; give the method your reference in + /// human-readable format e.g. 'master' instead of 'refs/heads/master', and it + /// will do-what-you-mean, returning the `Reference`. + pub fn resolve_reference_from_short_name(&self, refname: &str) -> Result { + let refname = try!(CString::new(refname)); + let mut raw = ptr::null_mut(); + unsafe { + try_call!(raw::git_reference_dwim(&mut raw, self.raw(), refname)); + Ok(Binding::from_raw(raw)) + } + } + /// Lookup a reference by name and resolve immediately to OID. /// /// This function provides a quick way to resolve a reference name straight