From 282f8ddb9bdb1b0ba860e36a83fa11e0d4597d66 Mon Sep 17 00:00:00 2001 From: Martin Wilck Date: Wed, 9 Sep 2020 15:09:26 +0200 Subject: [PATCH] filter-repo: only set author from committer if author email not set Some commits may have a valid author email, but no valid author name. Old versions of git didn't enforce a non-empty name. Setting the author data from the committer is wrong in this case. Also add a test case for this to t9390. Example: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=c6295cdf656de63d6d1123def71daba6cd91939c (en: replaced with a dedicated test instead of tweaking existing ones) Signed-off-by: Martin Wilck Signed-off-by: Elijah Newren --- git-filter-repo | 3 ++- t/t9390-filter-repo.sh | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 35 insertions(+), 1 deletion(-) diff --git a/git-filter-repo b/git-filter-repo index ac039ec..2dec352 100755 --- a/git-filter-repo +++ b/git-filter-repo @@ -1189,13 +1189,14 @@ class FastExportParser(object): original_id = self._parse_original_id(); author_name = None + author_email = None if self._currentline.startswith(b'author'): (author_name, author_email, author_date) = self._parse_user(b'author') (committer_name, committer_email, committer_date) = \ self._parse_user(b'committer') - if not author_name: + if not author_name and not author_email: (author_name, author_email, author_date) = \ (committer_name, committer_email, committer_date) diff --git a/t/t9390-filter-repo.sh b/t/t9390-filter-repo.sh index 14bdeaa..fd83484 100755 --- a/t/t9390-filter-repo.sh +++ b/t/t9390-filter-repo.sh @@ -1649,4 +1649,37 @@ test_expect_success '--version' ' test_cmp expect actual ' +test_expect_success 'empty author ident' ' + test_create_repo empty_author_ident && + ( + cd empty_author_ident && + + git init && + cat <<-EOF | git fast-import --quiet && + feature done + blob + mark :1 + data 8 + initial + + reset refs/heads/develop + commit refs/heads/develop + mark :2 + author 1535228562 -0700 + committer Full Name 1535228562 -0700 + data 8 + Initial + M 100644 :1 filename + + done + EOF + + git filter-repo --force --path-rename filename:stuff && + + git log --format=%an develop >actual && + echo >expect && + test_cmp expect actual + ) +' + test_done