diff --git a/post-commit.sh b/post-commit.sh index 1f13f0e..6929db4 100644 --- a/post-commit.sh +++ b/post-commit.sh @@ -237,13 +237,18 @@ replace_foreach () { temp=`tempfile -p "fugitive"` fe="foreach:$1" cat > "$temp" + cat "$temp" | \ + sed -n "//,//p" | \ + tail -n +2 | head -n -1 > "$foreach_body" + if [ ! -s "$foreach_body" ]; then + cat "$temp" + rm "$foreach_body" "$tmpfile" "$temp" + return + fi cat "$temp" | \ sed "s//\n\0/" | \ sed "//,//d" | \ cat > "$tmpfile" - cat "$temp" | \ - sed -n "//,//p" | \ - tail -n +2 | head -n -1 > "$foreach_body" for i in `cat "$2"`; do cat "$foreach_body" | replace_$1_info "$i" done > "$temp"