Skip to content

Commit 3f01ad6

Browse files
committed
am: Add --committer-date-is-author-date option
This new option tells 'git-am' to use the timestamp recorded in the Email message as both author and committer date. Signed-off-by: しらいしななこ <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 5dc1308 commit 3f01ad6

File tree

2 files changed

+32
-1
lines changed

2 files changed

+32
-1
lines changed

git-am.sh

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ resolvemsg= override error message when patch failure occurs
2424
r,resolved to be used after a patch failure
2525
skip skip the current patch
2626
abort restore the original branch and abort the patching operation.
27+
committer-date-is-author-date lie about committer date
2728
rebasing (internal use for git-rebase)"
2829

2930
. git-sh-setup
@@ -134,6 +135,7 @@ dotest="$GIT_DIR/rebase-apply"
134135
sign= utf8=t keep= skip= interactive= resolved= rebasing= abort=
135136
resolvemsg= resume=
136137
git_apply_opt=
138+
committer_date_is_author_date=
137139

138140
while test $# != 0
139141
do
@@ -171,6 +173,8 @@ do
171173
git_apply_opt="$git_apply_opt $(sq "$1$2")"; shift ;;
172174
--reject)
173175
git_apply_opt="$git_apply_opt $1" ;;
176+
--committer-date-is-author-date)
177+
committer_date_is_author_date=t ;;
174178
--)
175179
shift; break ;;
176180
*)
@@ -524,7 +528,14 @@ do
524528

525529
tree=$(git write-tree) &&
526530
parent=$(git rev-parse --verify HEAD) &&
527-
commit=$(git commit-tree $tree -p $parent <"$dotest/final-commit") &&
531+
commit=$(
532+
if test -n "$committer_date_is_author_date"
533+
then
534+
GIT_COMMITTER_DATE="$GIT_AUTHOR_DATE"
535+
export GIT_COMMITTER_DATE
536+
fi &&
537+
git commit-tree $tree -p $parent <"$dotest/final-commit"
538+
) &&
528539
git update-ref -m "$GIT_REFLOG_ACTION: $FIRSTLINE" HEAD $commit $parent ||
529540
stop_here $this
530541

t/t4150-am.sh

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -257,4 +257,24 @@ test_expect_success 'am works from file (absolute path given) in subdirectory' '
257257
test -z "$(git diff second)"
258258
'
259259

260+
test_expect_success 'am --committer-date-is-author-date' '
261+
git checkout first &&
262+
test_tick &&
263+
git am --committer-date-is-author-date patch1 &&
264+
git cat-file commit HEAD | sed -e "/^$/q" >head1 &&
265+
at=$(sed -ne "/^author /s/.*> //p" head1) &&
266+
ct=$(sed -ne "/^committer /s/.*> //p" head1) &&
267+
test "$at" = "$ct"
268+
'
269+
270+
test_expect_success 'am without --committer-date-is-author-date' '
271+
git checkout first &&
272+
test_tick &&
273+
git am patch1 &&
274+
git cat-file commit HEAD | sed -e "/^$/q" >head1 &&
275+
at=$(sed -ne "/^author /s/.*> //p" head1) &&
276+
ct=$(sed -ne "/^committer /s/.*> //p" head1) &&
277+
test "$at" != "$ct"
278+
'
279+
260280
test_done

0 commit comments

Comments
 (0)