git-am: cope better with an empty Subject: line
When the Subject: line is empty for whatever reason, git-am was fooled by it and left an empty line at the beginning of the resulting commit log message. This moves the logic around so that we do not keep $SUBJECT in a separate variable. Instead, $dotest/msg-clean, which used to be the log message body extracted from the message and then trailing whitespaces cleansed out, now contains the subject line followed by a blank line at the beginning for normal messages, and we use the first line from the file as the summary line throughout the program. Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org> Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
parent
6a28518ae0
commit
2e6e3e829f
24
git-am.sh
24
git-am.sh
@ -107,7 +107,7 @@ It does not apply to blobs recorded in its index."
|
|||||||
# patch did not touch, so recursive ends up canceling them,
|
# patch did not touch, so recursive ends up canceling them,
|
||||||
# saying that we reverted all those changes.
|
# saying that we reverted all those changes.
|
||||||
|
|
||||||
eval GITHEAD_$his_tree='"$SUBJECT"'
|
eval GITHEAD_$his_tree='"$FIRSTLINE"'
|
||||||
export GITHEAD_$his_tree
|
export GITHEAD_$his_tree
|
||||||
git-merge-recursive $orig_tree -- HEAD $his_tree || {
|
git-merge-recursive $orig_tree -- HEAD $his_tree || {
|
||||||
git rerere
|
git rerere
|
||||||
@ -117,10 +117,6 @@ It does not apply to blobs recorded in its index."
|
|||||||
unset GITHEAD_$his_tree
|
unset GITHEAD_$his_tree
|
||||||
}
|
}
|
||||||
|
|
||||||
reread_subject () {
|
|
||||||
git stripspace <"$1" | sed -e 1q
|
|
||||||
}
|
|
||||||
|
|
||||||
prec=4
|
prec=4
|
||||||
dotest=.dotest sign= utf8=t keep= skip= interactive= resolved= binary=
|
dotest=.dotest sign= utf8=t keep= skip= interactive= resolved= binary=
|
||||||
resolvemsg= resume=
|
resolvemsg= resume=
|
||||||
@ -303,7 +299,11 @@ do
|
|||||||
echo "Patch is empty. Was it split wrong?"
|
echo "Patch is empty. Was it split wrong?"
|
||||||
stop_here $this
|
stop_here $this
|
||||||
}
|
}
|
||||||
git stripspace < "$dotest/msg" > "$dotest/msg-clean"
|
SUBJECT="$(sed -n '/^Subject/ s/Subject: //p' "$dotest/info")"
|
||||||
|
case "$keep_subject" in -k) SUBJECT="[PATCH] $SUBJECT" ;; esac
|
||||||
|
|
||||||
|
(echo "$SUBJECT" ; echo ; cat "$dotest/msg") |
|
||||||
|
git stripspace > "$dotest/msg-clean"
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
|
|
||||||
@ -319,9 +319,6 @@ do
|
|||||||
|
|
||||||
export GIT_AUTHOR_NAME GIT_AUTHOR_EMAIL GIT_AUTHOR_DATE
|
export GIT_AUTHOR_NAME GIT_AUTHOR_EMAIL GIT_AUTHOR_DATE
|
||||||
|
|
||||||
SUBJECT="$(sed -n '/^Subject/ s/Subject: //p' "$dotest/info")"
|
|
||||||
case "$keep_subject" in -k) SUBJECT="[PATCH] $SUBJECT" ;; esac
|
|
||||||
|
|
||||||
case "$resume" in
|
case "$resume" in
|
||||||
'')
|
'')
|
||||||
if test '' != "$SIGNOFF"
|
if test '' != "$SIGNOFF"
|
||||||
@ -340,10 +337,8 @@ do
|
|||||||
ADD_SIGNOFF=
|
ADD_SIGNOFF=
|
||||||
fi
|
fi
|
||||||
{
|
{
|
||||||
printf '%s\n' "$SUBJECT"
|
|
||||||
if test -s "$dotest/msg-clean"
|
if test -s "$dotest/msg-clean"
|
||||||
then
|
then
|
||||||
echo
|
|
||||||
cat "$dotest/msg-clean"
|
cat "$dotest/msg-clean"
|
||||||
fi
|
fi
|
||||||
if test '' != "$ADD_SIGNOFF"
|
if test '' != "$ADD_SIGNOFF"
|
||||||
@ -360,6 +355,7 @@ do
|
|||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
esac
|
esac
|
||||||
|
FIRSTLINE=$(head -1 "$dotest/final-commit")
|
||||||
|
|
||||||
resume=
|
resume=
|
||||||
if test "$interactive" = t
|
if test "$interactive" = t
|
||||||
@ -380,7 +376,7 @@ do
|
|||||||
[aA]*) action=yes interactive= ;;
|
[aA]*) action=yes interactive= ;;
|
||||||
[nN]*) action=skip ;;
|
[nN]*) action=skip ;;
|
||||||
[eE]*) git_editor "$dotest/final-commit"
|
[eE]*) git_editor "$dotest/final-commit"
|
||||||
SUBJECT=$(reread_subject "$dotest/final-commit")
|
FIRSTLINE=$(head -1 "$dotest/final-commit")
|
||||||
action=again ;;
|
action=again ;;
|
||||||
[vV]*) action=again
|
[vV]*) action=again
|
||||||
LESS=-S ${PAGER:-less} "$dotest/patch" ;;
|
LESS=-S ${PAGER:-less} "$dotest/patch" ;;
|
||||||
@ -403,7 +399,7 @@ do
|
|||||||
stop_here $this
|
stop_here $this
|
||||||
fi
|
fi
|
||||||
|
|
||||||
printf 'Applying %s\n' "$SUBJECT"
|
printf 'Applying %s\n' "$FIRSTLINE"
|
||||||
|
|
||||||
case "$resolved" in
|
case "$resolved" in
|
||||||
'')
|
'')
|
||||||
@ -461,7 +457,7 @@ do
|
|||||||
tree=$(git write-tree) &&
|
tree=$(git write-tree) &&
|
||||||
parent=$(git rev-parse --verify HEAD) &&
|
parent=$(git rev-parse --verify HEAD) &&
|
||||||
commit=$(git commit-tree $tree -p $parent <"$dotest/final-commit") &&
|
commit=$(git commit-tree $tree -p $parent <"$dotest/final-commit") &&
|
||||||
git update-ref -m "$GIT_REFLOG_ACTION: $SUBJECT" HEAD $commit $parent ||
|
git update-ref -m "$GIT_REFLOG_ACTION: $FIRSTLINE" HEAD $commit $parent ||
|
||||||
stop_here $this
|
stop_here $this
|
||||||
|
|
||||||
if test -x "$GIT_DIR"/hooks/post-applypatch
|
if test -x "$GIT_DIR"/hooks/post-applypatch
|
||||||
|
Loading…
Reference in New Issue
Block a user