git-commit-vandalism/t/lib-httpd/apply-one-time-sed.sh
Denton Liu 77a946be98 apply-one-time-sed.sh: modernize style
Convert `[ ... ]` to use `test` and test for the existence of a regular
file (`-f`) instead of any file (`-e`).

Move the `then`s onto their own lines so that it conforms with the
general test style.

Instead of redirecting input into sed, allow it to open its own input.

Use `cmp -s` instead of `diff` since we only care about whether the two
files are equal and `diff` is overkill for this.

Signed-off-by: Denton Liu <liu.denton@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2019-11-29 13:20:14 -08:00

25 lines
647 B
Bash

#!/bin/sh
# If "one-time-sed" exists in $HTTPD_ROOT_PATH, run sed on the HTTP response,
# using the contents of "one-time-sed" as the sed command to be run. If the
# response was modified as a result, delete "one-time-sed" so that subsequent
# HTTP responses are no longer modified.
#
# This can be used to simulate the effects of the repository changing in
# between HTTP request-response pairs.
if test -f one-time-sed
then
"$GIT_EXEC_PATH/git-http-backend" >out
sed "$(cat one-time-sed)" out >out_modified
if cmp -s out out_modified
then
cat out
else
cat out_modified
rm one-time-sed
fi
else
"$GIT_EXEC_PATH/git-http-backend"
fi