commit 12b555d9492a47bd3ffd2240ee810fc5fa95d53b
parent c1edd9466fba34610bb424ca681bdfdd4b96593b
Author: Vincent Forest <vincent.forest@meso-star.com>
Date: Sat, 10 Feb 2024 19:33:01 +0100
Fixed status subcommand on empty git repository
On an empty git repository, i.e. a repository without any commit, the
status subcommand failed by questioning HEAD as it was missing. So we
have to check that at least one commit exists and, otherwise, report
that there is no commit.
Diffstat:
1 file changed, 8 insertions(+), 0 deletions(-)
diff --git a/git-wad b/git-wad
@@ -318,6 +318,14 @@ prune() # [--all]
# Print WAD management status
status() # [--all]
{
+ # First, we need to check that a commit exists, otherwise there's no
+ # active HEAD and therefore no status to report. In fact, the function
+ # would return an error if it queried the HEAD object.
+ if ! git rev-parse HEAD > /dev/null 2>&1; then
+ >&2 printf "No commits yet\n"
+ return
+ fi
+
# Create 3 temp files to list resolved, unrestored and orphaned WADs
resolved="$(mktemp -p "${GIT_WAD_OBJDIR}")"
unrestored="$(mktemp -p "${GIT_WAD_OBJDIR}")"