@matheusbsbs / matheus-bagliano / commits / 2e6e3e829f
Fork 0

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>

Linus Torvalds committed Apr 15, 2008 at 12:56 UTC 2e6e3e829f3759823d70e7af511bc04cd05ad0af
1 file changed +10 -14
git-am.sh
+10 -14
@@ -107,7 +107,7 @@ It does not apply to blobs recorded in its index."
107 # patch did not touch, so recursive ends up canceling them,
108 # saying that we reverted all those changes.
109
110 - eval GITHEAD_$his_tree='"$SUBJECT"'
110 + eval GITHEAD_$his_tree='"$FIRSTLINE"'
111 export GITHEAD_$his_tree
112 git-merge-recursive $orig_tree -- HEAD $his_tree || {
113 git rerere
@@ -117,10 +117,6 @@ It does not apply to blobs recorded in its index."
117 unset GITHEAD_$his_tree
118 }
119
120 -reread_subject () {
121 - git stripspace <"$1" | sed -e 1q
122 -}
123 -
120 prec=4
121 dotest=.dotest sign= utf8=t keep= skip= interactive= resolved= binary=
122 resolvemsg= resume=
@@ -303,7 +299,11 @@ do
299 echo "Patch is empty. Was it split wrong?"
300 stop_here $this
301 }
306 - git stripspace < "$dotest/msg" > "$dotest/msg-clean"
302 + SUBJECT="$(sed -n '/^Subject/ s/Subject: //p' "$dotest/info")"
303 + case "$keep_subject" in -k) SUBJECT="[PATCH] $SUBJECT" ;; esac
304 +
305 + (echo "$SUBJECT" ; echo ; cat "$dotest/msg") |
306 + git stripspace > "$dotest/msg-clean"
307 ;;
308 esac
309
@@ -319,9 +319,6 @@ do
319
320 export GIT_AUTHOR_NAME GIT_AUTHOR_EMAIL GIT_AUTHOR_DATE
321
322 - SUBJECT="$(sed -n '/^Subject/ s/Subject: //p' "$dotest/info")"
323 - case "$keep_subject" in -k) SUBJECT="[PATCH] $SUBJECT" ;; esac
324 -
322 case "$resume" in
323 '')
324 if test '' != "$SIGNOFF"
@@ -340,10 +337,8 @@ do
337 ADD_SIGNOFF=
338 fi
339 {
343 - printf '%s\n' "$SUBJECT"
340 if test -s "$dotest/msg-clean"
341 then
346 - echo
342 cat "$dotest/msg-clean"
343 fi
344 if test '' != "$ADD_SIGNOFF"
@@ -360,6 +355,7 @@ do
355 ;;
356 esac
357 esac
358 + FIRSTLINE=$(head -1 "$dotest/final-commit")
359
360 resume=
361 if test "$interactive" = t
@@ -380,7 +376,7 @@ do
376 [aA]*) action=yes interactive= ;;
377 [nN]*) action=skip ;;
378 [eE]*) git_editor "$dotest/final-commit"
383 - SUBJECT=$(reread_subject "$dotest/final-commit")
379 + FIRSTLINE=$(head -1 "$dotest/final-commit")
380 action=again ;;
381 [vV]*) action=again
382 LESS=-S ${PAGER:-less} "$dotest/patch" ;;
@@ -403,7 +399,7 @@ do
399 stop_here $this
400 fi
401
406 - printf 'Applying %s\n' "$SUBJECT"
402 + printf 'Applying %s\n' "$FIRSTLINE"
403
404 case "$resolved" in
405 '')
@@ -461,7 +457,7 @@ do
457 tree=$(git write-tree) &&
458 parent=$(git rev-parse --verify HEAD) &&
459 commit=$(git commit-tree $tree -p $parent <"$dotest/final-commit") &&
464 - git update-ref -m "$GIT_REFLOG_ACTION: $SUBJECT" HEAD $commit $parent ||
460 + git update-ref -m "$GIT_REFLOG_ACTION: $FIRSTLINE" HEAD $commit $parent ||
461 stop_here $this
462
463 if test -x "$GIT_DIR"/hooks/post-applypatch