Felix Moessbauer schrieb am Di 17. Dez, 13:32 (+0100):
> diff --git a/kas-container b/kas-container
> index 0437381ab..2b239a916 100755
> --- a/kas-container
> +++ b/kas-container
> @@ -454,6 +454,17 @@ if [ "$(id -u)" -eq 0 ] && [ "${KAS_ALLOW_ROOT}" != "yes" ] ; then
> "KAS_ALLOW_ROOT=yes to override."
> fi
>
> +if git_com_dir=$(git -C "${KAS_REPO_DIR}" rev-parse --git-common-dir 2>/dev/null) \
> + && [ "$git_com_dir" != "$(git -C "${KAS_REPO_DIR}" rev-parse --git-dir 2>/dev/null)" ]; then
I found that you can remove the second 2>/…, because at this point it's a
git dir and rev-parse should give real errors.
> + # If (it's a git repo) and the common dir isn't the git-dir, it is shared worktree and
> + # we have to mount the common dir in the container to make git work
> + # The mount path inside the container is different from the host path. Hence, we over-mount
> + # the .git file to point to the correct path.
> + git_overlay_file=$(mktemp)
How about using trap? Now, in case of SIGINT (or SIGTERM) the clean-up code
is never reached.
> + sed "s|gitdir: ${git_com_dir}/|gitdir: /repo-common/|" "${KAS_REPO_DIR}/.git" > "${git_overlay_file}"
I really would not edit git's internal files. I found no public interface
like git-config to change this value, and I think they intentionally provide
only GIT_COMMON_DIR.
Inside the worktrees are also files they contain paths. I don't know when
they are used, but with uncommon values they might need to be updated, too.
% gcat .git/worktrees/tmp/*dir
.git/worktrees/tmp/commondir:1:../..
.git/worktrees/tmp/gitdir:1:/home/joerg_sommer/kein_backup/tmp/.git
But as I said, I would not edit git's internal state, because this interface
can become different with the next version.
> + set -- "$@" -v "${git_com_dir}:/repo-common:${KAS_REPO_MOUNT_OPT}" -v "${git_overlay_file}:/repo/.git:ro"
I think you need to add `-v "${git_overlay_file}:/work/.git:ro"`
> +fi
> +
At me, I did
% git worktree add -b wt-tmp ~/kein_backup/tmp origin/main
% sha256sum kas-container
0099fb0c93e3ca849def15c6512e6e4a28df870c3a76681af1f730ee463e9fde kas-container
% git am /tmp/pat
Applying: Git support sharing the .git directory across multiple worktrees each having
% ./kas-container --log-level warning shell -c 'echo works'
fatal: not a git repository: /home/joerg_sommer/Projekte/prj/.git/worktrees/tmp
abort: no repository found in '/work' (.hg not found)
fatal: not a git repository: /home/joerg_sommer/Projekte/prj/.git/worktrees/tmp
abort: no repository found in '/work' (.hg not found)
fatal: not a git repository: /home/joerg_sommer/Projekte/prj/.git/worktrees/tmp
abort: no repository found in '/work' (.hg not found)
fatal: not a git repository: /home/joerg_sommer/Projekte/prj/.git/worktrees/tmp
fatal: not a git repository: /home/joerg_sommer/Projekte/prj/.git/worktrees/tmp
works
% ./kas-container --log-level debug shell -c 'echo works'
+ mkdir -p /home/joerg_sommer/.cache/yocto-dl-cache
+ mkdir -p /home/joerg_sommer/.cache/yocto-sstate
+ docker run -v /home/joerg_sommer/Projekte/prj/.git:/repo-common:rw -v /tmp/tmp.6jSUsXT9bf:/repo/.git:ro -v /home/joerg_sommer/kein_backup/tmp:/repo:rw -v /home/joerg_sommer/kein_backup/tmp:/work:rw -e KAS_WORK_DIR=/work -v /home/joerg_sommer/kein_backup/tmp/build:/build:rw --workdir=/repo -e KAS_BUILD_DIR=/build -e USER_ID=1001 -e GROUP_ID=1001 --rm --init -t -i -v /home/joerg_sommer/.cache/yocto-dl-cache:/downloads:rw -e DL_DIR=/downloads -v /home/joerg_sommer/.cache/yocto-sstate:/sstate:rw -e SSTATE_DIR=/sstate -e TERM=screen -e SHELL=/bin/bash --log-driver=none --user=root
ghcr.io/siemens/kas/kas:4.6 -l debug shell -c echo works
2024-12-20 06:58:29 - INFO - kas 4.6 started
2024-12-20 06:58:29 - DEBUG - Using selector: EpollSelector
2024-12-20 06:58:29 - DEBUG - /work$ git rev-parse --show-toplevel --show-superproject-working-tree
fatal: not a git repository: /home/joerg_sommer/Projekte/prj/.git/worktrees/tmp
2024-12-20 06:58:29 - DEBUG - /work$ hg root
abort: no repository found in '/work' (.hg not found)
2024-12-20 06:58:29 - DEBUG - /work$ git rev-parse --show-toplevel --show-superproject-working-tree
fatal: not a git repository: /home/joerg_sommer/Projekte/prj/.git/worktrees/tmp
2024-12-20 06:58:29 - DEBUG - /work$ hg root
abort: no repository found in '/work' (.hg not found)
2024-12-20 06:58:29 - DEBUG - execute setup_dir
2024-12-20 06:58:29 - DEBUG - execute setup_home
2024-12-20 06:58:29 - DEBUG - execute init_setup_repos
2024-12-20 06:58:29 - DEBUG - append lockfile /work/.kas/upstream.lock.yml
2024-12-20 06:58:29 - DEBUG - append lockfile /work/.kas/upstream.lock.yml
2024-12-20 06:58:29 - DEBUG - execute repo_setup_loop
2024-12-20 06:58:29 - DEBUG - Loop repo_setup_loop: execute setup_repos_step
2024-12-20 06:58:29 - DEBUG - execute finish_setup_repos
2024-12-20 06:58:29 - DEBUG - /work$ git rev-parse --show-toplevel --show-superproject-working-tree
fatal: not a git repository: /home/joerg_sommer/Projekte/prj/.git/worktrees/tmp
2024-12-20 06:58:29 - DEBUG - /work$ hg root
abort: no repository found in '/work' (.hg not found)
2024-12-20 06:58:29 - INFO - Using /work as root for repository meta-prj
2024-12-20 06:58:29 - DEBUG - /work$ git remote get-url origin
fatal: not a git repository: /home/joerg_sommer/Projekte/prj/.git/worktrees/tmp
2024-12-20 06:58:29 - DEBUG - /work$ git rev-parse --verify HEAD
fatal: not a git repository: /home/joerg_sommer/Projekte/prj/.git/worktrees/tmp
Regards, Jörg
--
http://www.gnu.org/fun/jokes/ed.msg.html
»Note the consistent user interface and error reportage. Ed is generous
enough to flag errors, yet prudent enough not to overwhelm the novice with
verbosity.«