Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions src/remote.rs
Original file line number Diff line number Diff line change
Expand Up @@ -384,6 +384,18 @@ impl<'repo> Remote<'repo> {
mem::size_of::<RemoteHead<'_>>(),
mem::size_of::<*const raw::git_remote_head>()
);
if base.is_null() {
// We cannot use slice::from_raw_parts() since that requires
// that the pointer be non-null, but that is fine since the size
// should be zero
if size != 0 {
return Err(Error::from_str(&format!(
"git_remote_ls() set a null pointer for a list of size {}",
size
)));
}
return Ok(&[]);
}
let slice = slice::from_raw_parts(base as *const _, size as usize);
Ok(mem::transmute::<
&[*const raw::git_remote_head],
Expand Down Expand Up @@ -921,6 +933,27 @@ mod tests {
drop(origin.clone());
}

#[test]

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it possible to follow the style here?

https://epage.github.io/dev/pr-style/#c-test

  • First commits documenting the buggy behavior (test passes and commit is bisectable)
  • second commit showing the behavior change in test diff

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

in the initial commit, in debug builds the test panics and in release builds it passes. Thus, in release builds there is no behavior change in the diff. I could add #[cfg_attr(debug_assertions, should_panic)] but I'm not sure that that would be really helpful (and also, not fully sure that debug_assertions is the right condition)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah that does not matter much. Merging

fn empty_remote_list() {
// Regression tests for issue #1217
let td = TempDir::new().unwrap();
let repo = Repository::init(td.path()).unwrap();

let remote_dir = TempDir::new().unwrap();
let _remote_repo = Repository::init_bare(remote_dir.path()).unwrap();
let remote_url = if cfg!(unix) {
format!("file://{}", remote_dir.path().display())
} else {
format!(
"file:///{}",
remote_dir.path().display().to_string().replace("\\", "/")
)
};
let mut remote = repo.remote("origin", &remote_url).unwrap();
remote.connect(Direction::Fetch).unwrap();
assert_eq!(0, remote.list().unwrap().len());
}

#[test]
fn is_valid_name() {
assert!(Remote::is_valid_name("foobar"));
Expand Down
Loading