Skip to content
Open
Show file tree
Hide file tree
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
2 changes: 0 additions & 2 deletions gix/src/repository/mailmap.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use crate::{Id, config::tree::Mailmap};

impl crate::Repository {
// TODO: tests
/// Similar to [`open_mailmap_into()`][crate::Repository::open_mailmap_into()], but ignores all errors and returns at worst
/// an empty mailmap, e.g. if there is no mailmap or if there were errors loading them.
///
Expand All @@ -13,7 +12,6 @@ impl crate::Repository {
out
}

// TODO: tests
/// Try to merge mailmaps from the following locations into `target`:
///
/// - read the `.mailmap` file without following symlinks from the working tree, if present
Expand Down
Binary file not shown.
Binary file not shown.
19 changes: 19 additions & 0 deletions gix/tests/fixtures/make_mailmap_repo.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#!/usr/bin/env bash
set -eu -o pipefail

git init -q
git checkout -b main

git config user.name "Committer"
git config user.email "committer@example.com"
git config commit.gpgsign false

# A .mailmap that remaps an author's display name by email.
# Format: <Proper Name> <commit@email>
cat >.mailmap <<'EOF'
Proper Name <proper@example.com>
EOF

touch a
git add a .mailmap
git commit -q -m "initial with mailmap"
55 changes: 55 additions & 0 deletions gix/tests/gix/repository/mailmap.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
use gix_date::parse::TimeBuf;

use crate::{Result, named_repo};

fn signature(name: &str, email: &str) -> gix_actor::Signature {
gix_actor::Signature {
name: name.into(),
email: email.into(),
time: gix_date::parse_header("42 +0800").expect("static input parses"),
}
}

#[test]
fn empty_when_no_mailmap_present() -> Result {
let repo = named_repo("make_basic_repo.sh")?;
let snapshot = repo.open_mailmap();
assert!(
snapshot.entries().is_empty(),
"a repo without any .mailmap or mailmap.* config yields an empty snapshot"
);

let mut into = gix_mailmap::Snapshot::default();
repo.open_mailmap_into(&mut into)
.expect("with no mailmap sources, no IO error is collected");
assert!(
into.entries().is_empty(),
"open_mailmap_into mirrors open_mailmap when there are no sources"
);
Ok(())
}

#[test]
fn reads_mailmap_from_worktree_root() -> Result {
let repo = named_repo("make_mailmap_repo.sh")?;
let snapshot = repo.open_mailmap();
assert_eq!(
snapshot.entries().len(),
1,
"the single entry from the worktree .mailmap is loaded"
);

let mut buf = TimeBuf::default();
let resolved = snapshot
.try_resolve(signature("Old Name", "proper@example.com").to_ref(&mut buf))
.expect("the entry rewrites the display name when the email matches");
assert_eq!(
resolved.name, "Proper Name",
"the mapped name from .mailmap replaces the original"
);
assert_eq!(
resolved.email, "proper@example.com",
"the email is preserved (this entry only changes the name)"
);
Ok(())
}
2 changes: 2 additions & 0 deletions gix/tests/gix/repository/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ mod config;
mod excludes;
#[cfg(feature = "attributes")]
mod filter;
#[cfg(feature = "mailmap")]
mod mailmap;
#[cfg(feature = "merge")]
mod merge;
mod object;
Expand Down