commit 443324e078a2319afbaef6151e7d3463a5ca2dd2
parent 2d1674b88488f45d1cf6ea52e9d721de739047b4
Author: Vincent Forest <vincent.forest@meso-star.com>
Date: Wed, 5 Feb 2025 14:43:16 +0100
Update on how git wad terminates
As tests already do, the die function is automatically called on exit.
This means that the temporary directory is always deleted. It is no
longer necessary to explicitly call die to handle errors, as the -e set
and output trapping will do the job. Just like the explicit call to exit
when an error is explicitly detected.
Diffstat:
| M | git-wad | | | 31 | ++++++++++++++++--------------- |
1 file changed, 16 insertions(+), 15 deletions(-)
diff --git a/git-wad b/git-wad
@@ -23,11 +23,14 @@ die()
exit "${1:-1}" # return status code (default is 1)
}
+# Configure signal processing
+trap 'die $?' EXIT
+
# Check that git-wad does not run from a .git directory
is_inside_git_dir="$(git rev-parse --is-inside-git-dir)"
if [ "${is_inside_git_dir}" = "true" ]; then
>&2 printf 'git-wad must be run in a work tree\n'
- die
+ exit 1
fi
# Force default locale when using sed, i.e. treat all characters as
@@ -40,7 +43,7 @@ if ! command -v sha256sum 1> /dev/null 2>&1 \
&& ! command -v shasum 1> /dev/null 2>&1 \
&& ! command -v sha256 1> /dev/null 2>&1; then
>&2 printf 'No tool to process SHA256 checksum\n'
- die
+ exit 1
fi
# Check C compiler support
@@ -50,12 +53,12 @@ elif command -v cc 1> /dev/null 2>&1; then
CC="cc"
else
>&2 printf 'No C compiler\n'
- die
+ exit 1
fi
# shellcheck disable=SC2310
-working_tree="$(git rev-parse --show-toplevel)" || die "$?"
-git_wad_tmpdir="$(mktemp -d "${TMPDIR:-/tmp}/git_wad_XXXXXX")" || die "$?"
+working_tree="$(git rev-parse --show-toplevel)"
+git_wad_tmpdir="$(mktemp -d "${TMPDIR:-/tmp}/git_wad_XXXXXX")"
# Path toward the next_timestamp command
next_timestamp="${git_wad_tmpdir}/next_timestamp"
@@ -215,7 +218,7 @@ unreferenced_objects() # [-1a]
# List WAD objects in the current working tree or to commit
wads="${git_wad_tmpdir}/wads"
# shellcheck disable=SC2310
- { wad_objects "$@" && wad_objects_staged; } > "${wads}" || die "$?"
+ { wad_objects "$@" && wad_objects_staged; } > "${wads}"
# The following command line is translated as follows:
# Sort WAD objects in ascending order
@@ -227,7 +230,7 @@ objects_to_push() # [-1a]
{
wads="${git_wad_tmpdir}/wad_objects"
# shellcheck disable=SC2310
- wad_objects "$@" > "${wads}" || die "$?"
+ wad_objects "$@" > "${wads}"
xargs -I {} sh -c \
"if [ -f \"${GIT_WAD_OBJDIR}/{}\" ]; then echo \"{}\"; fi" \
@@ -238,7 +241,7 @@ objects_to_fetch() # [-1a]
{
wads="${git_wad_tmpdir}/wad_objects"
# shellcheck disable=SC2310
- wad_objects "$@" > "${wads}" || die "$?"
+ wad_objects "$@" > "${wads}"
xargs -I {} sh -c \
"if [ ! -f \"${GIT_WAD_OBJDIR}/{}\" ]; then echo \"{}\"; fi" < "${wads}"
@@ -451,7 +454,7 @@ push() # [-1a]
{
if [ -z "${GIT_WAD_REMOTE_PUSH}" ]; then
>&2 printf "Remote undefined, i.e. variable GIT_WAD_REMOTE_PUSH is empty\n"
- die 1
+ exit 1
fi
>&2 printf "Pushing to %s\n" "${GIT_WAD_REMOTE_PUSH}"
@@ -460,7 +463,7 @@ push() # [-1a]
objects_to_push="${git_wad_tmpdir}/objects_to_push"
# shellcheck disable=SC2310
- objects_to_push "$@" > "${objects_to_push}" || die "$?"
+ objects_to_push "$@" > "${objects_to_push}"
rsync -av --progress --ignore-existing \
--files-from=- "${GIT_WAD_OBJDIR}" "${remote}" < "${objects_to_push}"
@@ -471,7 +474,7 @@ fetch() # [-1a]
{
if [ -z "${GIT_WAD_REMOTE_FETCH}" ]; then
>&2 printf "Remote undefined, i.e. variable GIT_WAD_REMOTE_FETCH is empty\n"
- die 1
+ exit 1
fi
objects_to_fetch="${git_wad_tmpdir}/objects_to_fetch"
@@ -550,7 +553,7 @@ checkout()
if ! is_init; then
>&2 printf "\e[0;31mgit-wad is not initialized\e[0m\n"
>&2 printf " (use \"git wad init\" to enable WAD management)\n"
- die 1
+ exit 1
fi
restore_init
@@ -683,7 +686,5 @@ case "${sub_cmd}" in
"push") shift 1; push "$@" ;;
"pull") shift 1; pull "$@" ;;
"status") shift 1; status "$@" ;;
- *) synopsis; die 1 ;;
+ *) synopsis; exit 1 ;;
esac
-
-die 0