Skip to content
This repository has been archived by the owner on Sep 26, 2023. It is now read-only.

Commit

Permalink
Don't rely on local user and email for Git tests.
Browse files Browse the repository at this point in the history
On Travis, depending on what OS you are building on, this may or may not
be set — and I suppose it's infinitely possible this could be the case
on a user's machine too! So, instead, we now set the signature (that is,
email, user's name and time) of the commit to a statically defined thing
we control in the tests.

This fixes the test failures we see on at least MacOS on Travis CI.
  • Loading branch information
nathankleyn committed Apr 18, 2019
1 parent 8dfcce4 commit 3a3dc54
Showing 1 changed file with 13 additions and 11 deletions.
24 changes: 13 additions & 11 deletions git/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ mod tests {

use super::{GitOps, LibGitOps};

use git2::Repository;
use git2::{Repository, Signature, Time};
use std::fs;
use std::io::Write;
use std::path::Path;
Expand Down Expand Up @@ -138,16 +138,18 @@ mod tests {
index
.add_path(Path::new(file))
.expect("can't add file to index");
repo.signature().and_then(|sig| {
index
.write_tree()
.and_then(|tid| repo.find_tree(tid))
.and_then(|tree| {
repo.commit(Some("HEAD"), &sig, &sig, "Initial commit", &tree, &[])
})
})
})
.expect("can't do first commit");

let time = Time::new(123456789, 0);
let sig = Signature::new("Foo McBarson", "foo.mcbarson@iamarealboy.net", &time)
.expect("couldn't create signature for commit");

index
.write_tree()
.and_then(|tid| repo.find_tree(tid))
.and_then(|tree| {
repo.commit(Some("HEAD"), &sig, &sig, "Initial commit", &tree, &[])
})
}).expect("can't do first commit");;

callback(&repo);
dir.close().expect("couldn't close the dir");
Expand Down

0 comments on commit 3a3dc54

Please sign in to comment.