diff --git a/resources/com/google/gerrit/server/commit-msg_test.sh b/resources/com/google/gerrit/server/commit-msg_test.sh index a9247711be..d797be30fd 100755 --- a/resources/com/google/gerrit/server/commit-msg_test.sh +++ b/resources/com/google/gerrit/server/commit-msg_test.sh @@ -11,6 +11,11 @@ function fail { exit 1 } +function prereq_modern_git { + # "git interpret-trailers --where" was introduced in Git 2.15.0. + git interpret-trailers -h 2>&1 | grep -e --where > /dev/null +} + function test_nonexistent_argument { rm -f input if ${hook} input ; then @@ -38,6 +43,38 @@ EOF fi } +function test_keep_cutoff_line { + if ! prereq_modern_git ; then + echo "old version of Git detected; skipping scissors test." + return 0 + fi + rm -f input + cat << EOF > input +Do something nice + +# Please enter the commit message for your changes. +# ------------------------ >8 ------------------------ +# Do not modify or remove the line above. +# Everything below it will be ignored. +diff --git a/file.txt b/file.txt +index 625fd613d9..03aeba3b21 100755 +--- a/file.txt ++++ b/file.txt +@@ -38,6 +38,7 @@ + context + line + ++hello, world + + context + line +EOF + ${hook} input || fail "failed hook execution" + grep '>8' input || fail "lost cut-off line" + sed -n -e '1,/>8/ p' input >top + grep '^Change-Id' top || fail "missing Change-Id above cut-off line" +} + # a Change-Id already set is preserved. function test_preserve_changeid { cat << EOF > input diff --git a/resources/com/google/gerrit/server/tools/root/hooks/commit-msg b/resources/com/google/gerrit/server/tools/root/hooks/commit-msg index e9ff5977e3..290123258b 100755 --- a/resources/com/google/gerrit/server/tools/root/hooks/commit-msg +++ b/resources/com/google/gerrit/server/tools/root/hooks/commit-msg @@ -48,11 +48,6 @@ if test ! -s "${dest}" ; then exit 1 fi -if ! mv "${dest}" "$1" ; then - echo "cannot mv ${dest} to $1" - exit 1 -fi - # Avoid the --in-place option which only appeared in Git 2.8 # Avoid the --if-exists option which only appeared in Git 2.15 if ! git -c trailer.ifexists=doNothing interpret-trailers \