summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMaxim Cournoyer <maxim@guixotic.coop>2026-02-14 17:28:07 +0900
committerMaxim Cournoyer <maxim@guixotic.coop>2026-02-14 18:32:02 +0900
commitbc4972662b4b38d902a55dffcff89aa8767aa02a (patch)
tree793c8155392830b748cd323b3d81e4c5ffc5dc78
parentd2c12da9415b0bdfd50416d9b73135b3b6d76075 (diff)
make: Improve handling of git configuration.
Commit 427b8f960ec introduced a regression that broke building Guix in an isolated container. * configure.ac ($(GIT_HOOKS_DIR), $(GIT_HOOKS_DIR)/%) ($(GIT_CONFIG_FILE), $(GIT_HOOKS_DIR)/commit-msg): Guard against the cases where GIT_HOOKS_DIR or GIT_CONFIG_FILE variables are empty. Fixes: <https://issues.guix.gnu.org/80388>. Reported-by: Tomas Volf <~@wolfsden.cz> Change-Id: I68645f93d9e1088902f6e0d2c8f97fe969d741c0
-rw-r--r--Makefile.am31
1 files changed, 19 insertions, 12 deletions
diff --git a/Makefile.am b/Makefile.am
index 732dd9a2c8c..c55ccb0e248 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -14,7 +14,7 @@
# Copyright © 2018 Oleg Pykhalov <go.wigust@gmail.com>
# Copyright © 2018 Alex Vong <alexvong1995@gmail.com>
# Copyright © 2019, 2023 Efraim Flashner <efraim@flashner.co.il>
-# Copyright © 2020, 2021, 2023, 2025 Maxim Cournoyer <maxim@guixotic.coop>
+# Copyright © 2020, 2021, 2023, 2025, 2026 Maxim Cournoyer <maxim@guixotic.coop>
# Copyright © 2021 Chris Marusich <cmmarusich@gmail.com>
# Copyright © 2021 Andrew Tropin <andrew@trop.in>
# Copyright © 2023 Clément Lassieur <clement@lassieur.org>
@@ -1271,25 +1271,32 @@ cuirass-jobs: $(GOBJECTS)
if in_git_p
# Git auto-configuration.
-GIT_HOOKS_DIR := $(shell git rev-parse --git-path hooks)
-GIT_CONFIG_FILE := $(shell git rev-parse --git-path config)
+
+# Note: the following git commands may fail and produce empty variables,
+# e.g. when working on a work tree in a container.
+GIT_HOOKS_DIR := $(shell git rev-parse --git-path hooks 2>/dev/null)
+GIT_CONFIG_FILE := $(shell git rev-parse --git-path config 2>/dev/null)
$(GIT_HOOKS_DIR):
- mkdir -p "$@"
+ if [ -n "$(GIT_HOOKS_DIR)" ]; then mkdir -p "$@"; fi
$(GIT_HOOKS_DIR)/%: etc/git/% | $(GIT_HOOKS_DIR)/
- cp "$<" "$@"
+ if [ -n "$(GIT_HOOKS_DIR)" ]; then cp "$<" "$@"; fi
$(GIT_CONFIG_FILE): etc/git/gitconfig
- git config --fixed-value --replace-all include.path \
- ../etc/git/gitconfig ../etc/git/gitconfig
+ if [ -n "$(GIT_CONFIG_FILE)" ]; then \
+ git config --fixed-value --replace-all include.path \
+ ../etc/git/gitconfig ../etc/git/gitconfig; \
+ fi
COMMIT_MSG_MAGIC = VGhpcyBpcyB0aGUgY29tbWl0LW1zZyBob29rIG9mIEd1aXg=
$(GIT_HOOKS_DIR)/commit-msg: etc/git/commit-msg | $(GIT_HOOKS_DIR)
- if test -f $@ && ! grep -qF $(COMMIT_MSG_MAGIC) $@; then \
- mkdir -p $@.d && mv $@ $@.d && \
- @ echo user commit-msg hook moved to $@.d/commit-msg; \
- fi; \
- cp etc/git/commit-msg $@
+ if [ -n "$(GIT_HOOKS_DIR)" ]; then \
+ if test -f $@ && ! grep -qF $(COMMIT_MSG_MAGIC) $@; then \
+ mkdir -p $@.d && mv $@ $@.d && \
+ echo user commit-msg hook moved to $@.d/commit-msg; \
+ fi && \
+ cp etc/git/commit-msg $@; \
+ fi
# Convenience targets.
GIT_HOOKS_SOURCE_FILES := $(shell find etc/git -type f -executable)