Skip to content

Commit 429aa95

Browse files
authored
Merge pull request #2803 from yahonda/devcontainer-worktree-git-dir
Make git work in the dev container when opened from a worktree
2 parents 0e2d13b + 62b23b3 commit 429aa95

3 files changed

Lines changed: 16 additions & 0 deletions

File tree

.devcontainer/docker-compose.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ services:
66
volumes:
77
- ..:/workspaces/oracle-enhanced:cached
88
- ./tzdata:/opt/tzdata:ro
9+
- ${GIT_COMMON_DIR}:${GIT_COMMON_DIR}:cached
910
command: sleep infinity
1011
network_mode: service:oracle
1112

.devcontainer/initializeCommand.sh

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ set -euo pipefail
44

55
IMAGE=gvenzl/oracle-free:latest
66
SCRIPT_DIR=$(cd "$(dirname "$0")" && pwd)
7+
WORKSPACE_DIR=$(cd "$SCRIPT_DIR/.." && pwd)
78
OUT_DIR="$SCRIPT_DIR/tzdata"
89

910
docker pull "$IMAGE"
@@ -17,3 +18,16 @@ docker run --rm --entrypoint sh \
1718
-c 'cp "$ORACLE_HOME"/oracore/zoneinfo/timezlrg_*.dat /out/ && chmod a+r /out/*.dat'
1819

1920
ls -1 "$OUT_DIR"
21+
22+
# When opened from a git worktree, .git is a file whose `gitdir:` line points
23+
# at the main repo's .git/worktrees/<branch>. That host path is not visible
24+
# inside the dev container by default, so git commands inside the container
25+
# fail with "fatal: not a git repository". Resolve the common git dir on the
26+
# host and write it to .devcontainer/.env; docker-compose.yml bind-mounts it
27+
# at the same path inside the container so the gitdir reference resolves.
28+
GIT_COMMON_DIR=$(git -C "$WORKSPACE_DIR" rev-parse --git-common-dir)
29+
case "$GIT_COMMON_DIR" in
30+
/*) ;;
31+
*) GIT_COMMON_DIR=$(cd "$WORKSPACE_DIR/$GIT_COMMON_DIR" && pwd) ;;
32+
esac
33+
printf 'GIT_COMMON_DIR=%s\n' "$GIT_COMMON_DIR" > "$SCRIPT_DIR/.env"

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,4 @@ ojdbc*.jar
1515
.byebug_history
1616
debug.log
1717
.devcontainer/tzdata/
18+
.devcontainer/.env

0 commit comments

Comments
 (0)