From 8411ecb5e3541c24e6e5db07b02f948ab6a730f3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Gronowski?= Date: Wed, 7 Aug 2024 15:22:39 +0200 Subject: [PATCH] Makefile: Add BIND_GIT variable MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Defining BIND_GIT will bind mount the common .git directory into the dev container. This makes it possible to run some hack/* scripts which rely on `git` when running the container in a git worktree. Signed-off-by: Paweł Gronowski --- Makefile | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 1b8dd04d1f..e89172be71 100644 --- a/Makefile +++ b/Makefile @@ -103,7 +103,14 @@ DOCKER_MOUNT := $(if $(DOCKER_MOUNT),$(DOCKER_MOUNT),-v /go/src/github.com/docke DOCKER_MOUNT_CACHE := -v docker-dev-cache:/root/.cache -v docker-mod-cache:/go/pkg/mod/ DOCKER_MOUNT_CLI := $(if $(DOCKER_CLI_PATH),-v $(shell dirname $(DOCKER_CLI_PATH)):/usr/local/cli,) DOCKER_MOUNT_BASH_COMPLETION := $(if $(DOCKER_BASH_COMPLETION_PATH),-v $(shell dirname $(DOCKER_BASH_COMPLETION_PATH)):/usr/local/completion/bash,) -DOCKER_MOUNT := $(DOCKER_MOUNT) $(DOCKER_MOUNT_CACHE) $(DOCKER_MOUNT_CLI) $(DOCKER_MOUNT_BASH_COMPLETION) + +ifdef BIND_GIT + # Gets the common .git directory (even from inside a git worktree) + GITDIR := $(shell realpath $(shell git rev-parse --git-common-dir)) + MOUNT_GITDIR := $(if $(GITDIR),-v "$(GITDIR):$(GITDIR)") +endif + +DOCKER_MOUNT := $(DOCKER_MOUNT) $(DOCKER_MOUNT_CACHE) $(DOCKER_MOUNT_CLI) $(DOCKER_MOUNT_BASH_COMPLETION) $(MOUNT_GITDIR) endif # ifndef DOCKER_MOUNT # This allows to set the docker-dev container name