Repository navigation
Add git worktree support, make git repo data read-only by default - #10
Conversation
`rev-parse --path-format=absolute --git-common-dir` needs git 2.31+. Older git does not reject the unknown flag: it echoes it back and exits 0, so GIT_COMMON_DIR became "--path-format=absolute\n.git" and bwrap refused to start in any git repo. This is the default path -- no flag involved -- so ai-bwrap was unusable on e.g. Ubuntu 20.04 (git 2.25.1). Use plain --git-common-dir, which works on every version and is what resolves worktrees and subdirectories anyway, then absolutize by hand. Verified on git 2.25.1: read-only .git by default, --git-rw restores writes, tracked files stay editable, and subdirectories, linked worktrees and non-git dirs all behave as intended.
|
Thanks — merging this. One thing I fixed on the branch before merge rather than sending back, since it only shows up on older git than you'd have: Swapped it for plain |
|
Git older than 2.31? But that's over five years ago. :-) I wouldn't have added that extra complexity since the Ubuntu 20.04 mentioned in the commit message has been EOL since 31 May 2025. For some quick context, Debian Bullseye (oldold-stable, no more security updates) 2.30, Bookworm (old-stable) 2.39, Ubuntu Jammy (22.04) 2.34. |
What & why
git worktree depends on being able to read the original
.gitdir, not just pwd.git.I don't want it to be able to mess up all my git stuff. For context, I wrote my own cobbled together script that looks like like this but I figured some kind of shared effort would be a better use of time. ;-)
Details
BWRAP_ARGS=( --setenv OPENROUTER_API_KEY "$OPENROUTER_API_KEY" --ro-bind /usr /usr --ro-bind /lib /lib --ro-bind /lib64 /lib64 --ro-bind /bin /bin --ro-bind /etc/alternatives /etc/alternatives --ro-bind /etc/resolv.conf /etc/resolv.conf --ro-bind /etc/hosts /etc/hosts --ro-bind /etc/ssl /etc/ssl --dev-bind /dev/null /dev/null --ro-bind "$HOME/bin/bwrap-ante" "$HOME/bin/brwap-ante" --bind "$HOME/.ante/bin/ante" "$HOME/.ante/bin/ante" --ro-bind "$HOME/.gitconfig" "$HOME/.gitconfig" --ro-bind "$HOME/.nvm" "$HOME/.nvm" --bind "$PROJECT_DIR" "$PROJECT_DIR" --bind "$HOME/.ante" "$HOME/.ante" --bind "$HOME/.cargo" "$HOME/.cargo" --bind "$HOME/.rustup" "$HOME/.rustup" --tmpfs /tmp --proc /proc --dev /dev --share-net --unshare-pid --die-with-parent --chdir "$PROJECT_DIR" --ro-bind /dev/null "$PROJECT_DIR/.env" --ro-bind /dev/null "$PROJECT_DIR/.env.local" --ro-bind /dev/null "$PROJECT_DIR/.env.production" ) # Check if the current directory is inside a Git repository # Enforce worktree if so if git rev-parse --is-inside-work-tree >/dev/null 2>&1; then GIT_COMMON_DIR=$(git rev-parse --path-format=absolute --git-common-dir) BWRAP_ARGS+=(--ro-bind "$GIT_COMMON_DIR" "$GIT_COMMON_DIR") else echo Not in a git repo. exit 1 fi # Execute bwrap with the constructed arguments bwrap "${BWRAP_ARGS[@]}" ante "$@"Checklist
shellcheck ai-bwrapis clean--helptext and README updated together (if the CLI surface changed)--dry-run(paste relevant output below if helpful)Details
Notes
It means it can't commit but I consider that a feature. The default could be flipped if desired.