summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authortummychow <tummychow@users.noreply.github.com>2018-02-15 22:40:19 -0800
committertummychow <tummychow@users.noreply.github.com>2018-02-15 22:40:19 -0800
commitdc09725b60c1a7c3a2a6a78bb88c7fa38872cb61 (patch)
tree53ecd97a02dd486ed65cb705e26bbf72ae6899c5
parent182d10027d3fff2c65197723c4d41c69474f1afc (diff)
add foreign author detection
-rw-r--r--src/lib.rs30
1 files changed, 29 insertions, 1 deletions
diff --git a/src/lib.rs b/src/lib.rs
index 78c9f9d..d94f19b 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -93,12 +93,19 @@ fn working_stack<'repo>(
}
let mut ret = Vec::new();
+ let sig = repo.signature()?;
for rev in revwalk {
let commit = repo.find_commit(rev?)?;
if commit.parents().count() > 1 {
debug!(logger, "merge commit found"; "commit" => commit.id().to_string());
break;
}
+ if commit.author().name_bytes() != sig.name_bytes()
+ || commit.author().email_bytes() != sig.email_bytes()
+ {
+ debug!(logger, "foreign author found"; "commit" => commit.id().to_string());
+ break;
+ }
if ret.len() == max_stack(repo) {
warn!(logger, "stack limit reached"; "limit" => ret.len());
break;
@@ -124,6 +131,11 @@ mod tests {
let dir = tempdir::TempDir::new("git-absorb").unwrap();
// TODO: use in-memory ODB instead (blocked on git2 support)
let repo = git2::Repository::init(&dir).unwrap();
+
+ let mut config = repo.config().unwrap();
+ config.set_str("user.name", "nobody").unwrap();
+ config.set_str("user.email", "nobody@example.com").unwrap();
+
(dir, repo)
}
@@ -133,7 +145,7 @@ mod tests {
message: &str,
parents: &[&git2::Commit],
) -> git2::Commit<'repo> {
- let sig = git2::Signature::now("nobody", "nobody@example.com").unwrap();
+ let sig = repo.signature().unwrap();
let tree = repo.find_tree(repo.treebuilder(None).unwrap().write().unwrap())
.unwrap();
@@ -218,6 +230,22 @@ mod tests {
}
#[test]
+ fn test_stack_stops_at_foreign_author() {
+ let (_dir, repo) = init_repo();
+ let old_commits = empty_commit_chain(&repo, "HEAD", &[], 3);
+ repo.config()
+ .unwrap()
+ .set_str("user.name", "nobody2")
+ .unwrap();
+ let new_commits = empty_commit_chain(&repo, "HEAD", &[old_commits.last().unwrap()], 2);
+
+ let stack = working_stack(&repo, None, &empty_slog()).unwrap();
+ assert_eq!(stack.len(), 2);
+ assert_eq!(stack[0].id(), new_commits[1].id());
+ assert_eq!(stack[1].id(), new_commits[0].id());
+ }
+
+ #[test]
fn test_stack_stops_at_merges() {
let (_dir, repo) = init_repo();
let first = empty_commit(&repo, "HEAD", "first", &[]);