Skip to content

Commit 282f8dd

Browse files
mwilcknewren
authored andcommitted
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 <[email protected]> Signed-off-by: Elijah Newren <[email protected]>
1 parent 7b3e714 commit 282f8dd

File tree

2 files changed

+35
-1
lines changed

2 files changed

+35
-1
lines changed

git-filter-repo

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1189,13 +1189,14 @@ class FastExportParser(object):
11891189
original_id = self._parse_original_id();
11901190

11911191
author_name = None
1192+
author_email = None
11921193
if self._currentline.startswith(b'author'):
11931194
(author_name, author_email, author_date) = self._parse_user(b'author')
11941195

11951196
(committer_name, committer_email, committer_date) = \
11961197
self._parse_user(b'committer')
11971198

1198-
if not author_name:
1199+
if not author_name and not author_email:
11991200
(author_name, author_email, author_date) = \
12001201
(committer_name, committer_email, committer_date)
12011202

t/t9390-filter-repo.sh

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1649,4 +1649,37 @@ test_expect_success '--version' '
16491649
test_cmp expect actual
16501650
'
16511651

1652+
test_expect_success 'empty author ident' '
1653+
test_create_repo empty_author_ident &&
1654+
(
1655+
cd empty_author_ident &&
1656+
1657+
git init &&
1658+
cat <<-EOF | git fast-import --quiet &&
1659+
feature done
1660+
blob
1661+
mark :1
1662+
data 8
1663+
initial
1664+
1665+
reset refs/heads/develop
1666+
commit refs/heads/develop
1667+
mark :2
1668+
author <[email protected]> 1535228562 -0700
1669+
committer Full Name <[email protected]> 1535228562 -0700
1670+
data 8
1671+
Initial
1672+
M 100644 :1 filename
1673+
1674+
done
1675+
EOF
1676+
1677+
git filter-repo --force --path-rename filename:stuff &&
1678+
1679+
git log --format=%an develop >actual &&
1680+
echo >expect &&
1681+
test_cmp expect actual
1682+
)
1683+
'
1684+
16521685
test_done

0 commit comments

Comments
 (0)