Skip to content

Commit 43c2325

Browse files
jaysoffiangitster
authored andcommitted
am: use get_author_ident_from_commit instead of mailinfo when rebasing
In certain situations, commit authorship can consist of an invalid e-mail address. For example, this is the case when working with git svn repos where the author email has had the svn repo UUID appended such as: [email protected] <[email protected]@deadbee-dead-beef-dead-beefdeadbeef> Given such an address, mailinfo extracts the authorship incorrectly as it assumes a valid domain. However, when rebasing the original authorship should be preserved irrespective of its validity as an email address. Using get_author_ident_from_commit instead of mailinfo when rebasing preserves the original authorship. Signed-off-by: Jay Soffian <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent e0a9110 commit 43c2325

File tree

2 files changed

+17
-6
lines changed

2 files changed

+17
-6
lines changed

git-am.sh

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -593,7 +593,7 @@ do
593593
echo "Patch is empty. Was it split wrong?"
594594
stop_here $this
595595
}
596-
rm -f "$dotest/original-commit"
596+
rm -f "$dotest/original-commit" "$dotest/author-script"
597597
if test -f "$dotest/rebasing" &&
598598
commit=$(sed -e 's/^From \([0-9a-f]*\) .*/\1/' \
599599
-e q "$dotest/$msgnum") &&
@@ -602,6 +602,7 @@ do
602602
git cat-file commit "$commit" |
603603
sed -e '1,/^$/d' >"$dotest/msg-clean"
604604
echo "$commit" > "$dotest/original-commit"
605+
get_author_ident_from_commit "$commit" > "$dotest/author-script"
605606
else
606607
{
607608
sed -n '/^Subject/ s/Subject: //p' "$dotest/info"
@@ -613,9 +614,14 @@ do
613614
;;
614615
esac
615616

616-
GIT_AUTHOR_NAME="$(sed -n '/^Author/ s/Author: //p' "$dotest/info")"
617-
GIT_AUTHOR_EMAIL="$(sed -n '/^Email/ s/Email: //p' "$dotest/info")"
618-
GIT_AUTHOR_DATE="$(sed -n '/^Date/ s/Date: //p' "$dotest/info")"
617+
if test -f "$dotest/author-script"
618+
then
619+
eval $(cat "$dotest/author-script")
620+
else
621+
GIT_AUTHOR_NAME="$(sed -n '/^Author/ s/Author: //p' "$dotest/info")"
622+
GIT_AUTHOR_EMAIL="$(sed -n '/^Email/ s/Email: //p' "$dotest/info")"
623+
GIT_AUTHOR_DATE="$(sed -n '/^Date/ s/Date: //p' "$dotest/info")"
624+
fi
619625

620626
if test -z "$GIT_AUTHOR_EMAIL"
621627
then

t/t3400-rebase.sh

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,9 @@ among other things.
1010
'
1111
. ./test-lib.sh
1212

13-
GIT_AUTHOR_EMAIL=bogus_email_address
14-
export GIT_AUTHOR_EMAIL
13+
GIT_AUTHOR_NAME=author@name
14+
GIT_AUTHOR_EMAIL=bogus@email@address
15+
export GIT_AUTHOR_NAME GIT_AUTHOR_EMAIL
1516

1617
test_expect_success \
1718
'prepare repository with topic branches' \
@@ -80,6 +81,10 @@ test_expect_success \
8081
'the rebase operation should not have destroyed author information' \
8182
'! (git log | grep "Author:" | grep "<>")'
8283

84+
test_expect_success \
85+
'the rebase operation should not have destroyed author information (2)' \
86+
"git log -1 | grep 'Author: $GIT_AUTHOR_NAME <$GIT_AUTHOR_EMAIL>'"
87+
8388
test_expect_success 'HEAD was detached during rebase' '
8489
test $(git rev-parse HEAD@{1}) != $(git rev-parse my-topic-branch@{1})
8590
'

0 commit comments

Comments
 (0)