diff --git a/HISTORY.asc b/HISTORY.asc index a3e912b..98ea2a3 100644 --- a/HISTORY.asc +++ b/HISTORY.asc @@ -1,3 +1,12 @@ +STABLE +------ +== Fix setup.sh / pgxntool-sync.sh / update-setup-files.sh inside a git worktree +These scripts guarded the project root with `[ -d .git ]`. In a linked worktree +`.git` is a file, not a directory, so the check failed: setup.sh would wrongly +re-run `git init`, and the sync scripts aborted with "Not in a git repository." +They now detect the repo with `git rev-parse --git-dir`, which works in both a +normal clone and a worktree. + 2.0.3 ----- == Fix pgxntool-sync remote, and make it runnable without make diff --git a/pgxntool-sync.sh b/pgxntool-sync.sh index c61e60a..56896ac 100755 --- a/pgxntool-sync.sh +++ b/pgxntool-sync.sh @@ -38,7 +38,8 @@ ref=${2:-$DEFAULT_REF} # We must run from the project root: git subtree pull operates on the pgxntool/ # prefix and update-setup-files.sh resolves paths relative to the current dir. [[ -d "pgxntool" ]] || die 1 "pgxntool directory not found. Run from your project root." -[[ -d ".git" ]] || die 1 "Not in a git repository. Run from your project root." +# Use rev-parse, not [ -d .git ]: in a worktree .git is a file, not a directory. +git rev-parse --git-dir >/dev/null 2>&1 || die 1 "Not in a git repository. Run from your project root." # The old commit is the pgxntool subtree HEAD before the pull; update-setup-files.sh # needs it as the merge base for files that were copied out of pgxntool. diff --git a/setup.sh b/setup.sh index 0a67f0e..54b3633 100755 --- a/setup.sh +++ b/setup.sh @@ -7,7 +7,9 @@ trap 'echo "Error on line ${LINENO}"' ERR PGXNTOOL_DIR="$(dirname "${BASH_SOURCE[0]}")" source "$PGXNTOOL_DIR/lib.sh" -[ -d .git ] || git init +# Use rev-parse, not [ -d .git ]: in a worktree .git is a file, not a directory, +# so the old check would wrongly re-run `git init` inside a valid working tree. +git rev-parse --git-dir >/dev/null 2>&1 || git init if ! git diff --cached --exit-code; then echo "Git repository is not clean; please commit and try again." >&2 diff --git a/update-setup-files.sh b/update-setup-files.sh index 94ae75d..94e88aa 100755 --- a/update-setup-files.sh +++ b/update-setup-files.sh @@ -146,9 +146,10 @@ process_symlink() { old_commit=$1 -# Verify we're in a git repo with pgxntool subtree +# Verify we're in a git repo with pgxntool subtree. +# Use rev-parse, not [ -d .git ]: in a worktree .git is a file, not a directory. [[ -d "pgxntool" ]] || die 1 "pgxntool directory not found. Run from project root." -[[ -d ".git" ]] || die 1 "Not in a git repository." +git rev-parse --git-dir >/dev/null 2>&1 || die 1 "Not in a git repository." # Verify the old commit is valid if ! git cat-file -e "${old_commit}^{commit}" 2>/dev/null; then