Description
The `patch-git.lua` script fails to identify the git repository when it is executed from within a `git worktree`. This prevents developers from using the script in more complex git workflows that involve worktrees.
Steps to Reproduce
- Create a new git worktree from the main repository directory.
- {code:bash}
git worktree add ../<worktree-name># Change directory into the newly created worktree. # \{code:bash} cd ../<worktree-name>
- Execute the `patch-git.lua` script. (The exact command might vary based on usage)
- {code:bash}
lua patch-git.lua changelog
Expected Behavior
The `patch-git.lua` script should run without errors, correctly detecting the git repository's context from within the worktree.
Actual Behavior
The script terminates with the following error:
centos/glibc-c9s/patch-git.lua:500: no Git repository and no captured Git history
Analysis
The error suggests that the script's method for finding the git repository root (e.g., searching for a `.git` directory) is not compatible with how git worktrees are structured. In a worktree, `.git` is a file pointing to the main repository's git directory, rather than being a directory itself. The script needs to be updated to handle this case.