Feature: Allow git to work even when in a repo subdir#87
Conversation
|
Thanks @jeff-phil for adding this capability. Here are a few revisions that I think will make this improvement better aligned with the pi-less-yolo approach:
# PI_PARENT_GIT_MOUNT=1: mount the repo's common .git dir when pi is launched
# from a subdirectory or a separate worktree. Sets GIT_DIR and GIT_WORK_TREE
# inside the container so git commands work correctly. The .git dir is always
# mounted read-only. If you need the agent to commit, it should do so through
# the working-tree path.
if [[ -n "${PI_PARENT_GIT_MOUNT:-}" ]]; then
_pi_git_common_dir="$(git rev-parse --path-format=absolute --git-common-dir 2>/dev/null || true)"
_pi_git_work_tree="$(git rev-parse --show-toplevel 2>/dev/null || true)"
if [[ -n "${_pi_git_common_dir}" ]]; then
DOCKER_FLAGS+=(
"--volume" "${_pi_git_common_dir}:/git-data:ro"
"--env" "GIT_DIR=/git-data"
"--env" "GIT_WORK_TREE=${_pi_git_work_tree}"
)
# Mount the worktree root read-only only when it isn't already covered by
# the primary $(pwd):$(pwd) mount — i.e. launching from a subdirectory or
# a linked worktree whose root differs from the working directory.
if [[ "$(pwd -P)" != "${_pi_git_work_tree}" ]]; then
DOCKER_FLAGS+=(
"--volume" "${_pi_git_work_tree}:${_pi_git_work_tree}:ro"
)
fi
fi
fiWhat do you think? |
|
This part:
won't work like maybe you are thinking. When For example: If you start pi-less-yolo in What i was looking to adjust was when pi-less-yolo is started in a worktree or subdirectory of a git branch or worktree, then you still have access to a working repo... unless you used the pi:readonly task. Everything else i agree with, just this line always making GIT_DIR=/git-data read-only isn't a good change IMHO: "--volume" "${_pi_git_common_dir}:/git-data:ro"Please let me know if i am explaining it okay. I had to go through a dozens of test iterations to get this right in my head of what worked and what didn't work, and then implement it for this PR. Appreciate your looking at this! |
|
I made some changes but kept /git-data mounted r/w unless Hope you agree and are good. |
When in a sub-directory of a repo when start
pi, then nogitcommands work for that repo. This means that pi agents cannot see the history, status, etc. to help make set better context.The reason this happens is because the .git folder will be in a sub-directory, or for some worktrees completely different directory structure. And when pi-less-yolo starts in subdirectory the .git folder and other files not in current working directory will not be mounted.
As an example from below tree, if pi-less-yolo is kicked off from
/my-project/src/somedir, then git will not work. If started from /my-project then git will work.And if started from a worktree of my-project in a separate directory, the /my-project/.git is also needed because that is where the git data is stored.
This PR discovers if pi-less-yolo was started in a git repo, and discovers the common git data dir, maps that into
/git-data, and sets environment variable to tell git to look there for the git data. It follows the same PI_WORKDIR_RO rules that the user selects.Then if the user does not start in the worktree dir, then the full worktree dir is volume mapped into the container - but always READONLY. Without the rest of the repo directories, things like
git statuswill make it look like all the files were deleted, and this solves for that by having the files visible now.