nix-bitcoin/test/lib/create-git-repo.sh
Erik Arvstedt 67a573dae8
create-git-repo.sh: fix amend error if there's no branch checked out
In this case, `git commit --amend` fails.

The state of a .git repo existing without a branch being checked out
can be reached through the following sequence of events (which I just
seem to have triggered):
1. The script calls `git init`
2. The user interrupts the script before `git commit` is finished
2022-08-29 00:12:19 +02:00

16 lines
341 B
Bash

# Create and maintain a minimal git repo at the root of the copied src
(
# shellcheck disable=SC2154,SC2164
cd "$scriptDir/.."
amend=--amend
if [[ ! -e .git ]] || ! git rev-parse HEAD 2>/dev/null; then
git init
amend=
fi
git add .
if ! git diff --quiet --cached; then
git commit -a "$amend" -m -
fi
) >/dev/null