diff options
| author | Maxim Cournoyer <maxim@guixotic.coop> | 2026-02-14 17:28:07 +0900 |
|---|---|---|
| committer | Maxim Cournoyer <maxim@guixotic.coop> | 2026-02-14 18:32:02 +0900 |
| commit | bc4972662b4b38d902a55dffcff89aa8767aa02a (patch) | |
| tree | 793c8155392830b748cd323b3d81e4c5ffc5dc78 | |
| parent | d2c12da9415b0bdfd50416d9b73135b3b6d76075 (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.am | 31 |
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 @@ | |||
| 14 | # Copyright © 2018 Oleg Pykhalov <go.wigust@gmail.com> | 14 | # Copyright © 2018 Oleg Pykhalov <go.wigust@gmail.com> |
| 15 | # Copyright © 2018 Alex Vong <alexvong1995@gmail.com> | 15 | # Copyright © 2018 Alex Vong <alexvong1995@gmail.com> |
| 16 | # Copyright © 2019, 2023 Efraim Flashner <efraim@flashner.co.il> | 16 | # Copyright © 2019, 2023 Efraim Flashner <efraim@flashner.co.il> |
| 17 | # Copyright © 2020, 2021, 2023, 2025 Maxim Cournoyer <maxim@guixotic.coop> | 17 | # Copyright © 2020, 2021, 2023, 2025, 2026 Maxim Cournoyer <maxim@guixotic.coop> |
| 18 | # Copyright © 2021 Chris Marusich <cmmarusich@gmail.com> | 18 | # Copyright © 2021 Chris Marusich <cmmarusich@gmail.com> |
| 19 | # Copyright © 2021 Andrew Tropin <andrew@trop.in> | 19 | # Copyright © 2021 Andrew Tropin <andrew@trop.in> |
| 20 | # Copyright © 2023 Clément Lassieur <clement@lassieur.org> | 20 | # Copyright © 2023 Clément Lassieur <clement@lassieur.org> |
| @@ -1271,25 +1271,32 @@ cuirass-jobs: $(GOBJECTS) | |||
| 1271 | 1271 | ||
| 1272 | if in_git_p | 1272 | if in_git_p |
| 1273 | # Git auto-configuration. | 1273 | # Git auto-configuration. |
| 1274 | GIT_HOOKS_DIR := $(shell git rev-parse --git-path hooks) | 1274 | |
| 1275 | GIT_CONFIG_FILE := $(shell git rev-parse --git-path config) | 1275 | # Note: the following git commands may fail and produce empty variables, |
| 1276 | # e.g. when working on a work tree in a container. | ||
| 1277 | GIT_HOOKS_DIR := $(shell git rev-parse --git-path hooks 2>/dev/null) | ||
| 1278 | GIT_CONFIG_FILE := $(shell git rev-parse --git-path config 2>/dev/null) | ||
| 1276 | $(GIT_HOOKS_DIR): | 1279 | $(GIT_HOOKS_DIR): |
| 1277 | mkdir -p "$@" | 1280 | if [ -n "$(GIT_HOOKS_DIR)" ]; then mkdir -p "$@"; fi |
| 1278 | 1281 | ||
| 1279 | $(GIT_HOOKS_DIR)/%: etc/git/% | $(GIT_HOOKS_DIR)/ | 1282 | $(GIT_HOOKS_DIR)/%: etc/git/% | $(GIT_HOOKS_DIR)/ |
| 1280 | cp "$<" "$@" | 1283 | if [ -n "$(GIT_HOOKS_DIR)" ]; then cp "$<" "$@"; fi |
| 1281 | 1284 | ||
| 1282 | $(GIT_CONFIG_FILE): etc/git/gitconfig | 1285 | $(GIT_CONFIG_FILE): etc/git/gitconfig |
| 1283 | git config --fixed-value --replace-all include.path \ | 1286 | if [ -n "$(GIT_CONFIG_FILE)" ]; then \ |
| 1284 | ../etc/git/gitconfig ../etc/git/gitconfig | 1287 | git config --fixed-value --replace-all include.path \ |
| 1288 | ../etc/git/gitconfig ../etc/git/gitconfig; \ | ||
| 1289 | fi | ||
| 1285 | 1290 | ||
| 1286 | COMMIT_MSG_MAGIC = VGhpcyBpcyB0aGUgY29tbWl0LW1zZyBob29rIG9mIEd1aXg= | 1291 | COMMIT_MSG_MAGIC = VGhpcyBpcyB0aGUgY29tbWl0LW1zZyBob29rIG9mIEd1aXg= |
| 1287 | $(GIT_HOOKS_DIR)/commit-msg: etc/git/commit-msg | $(GIT_HOOKS_DIR) | 1292 | $(GIT_HOOKS_DIR)/commit-msg: etc/git/commit-msg | $(GIT_HOOKS_DIR) |
| 1288 | if test -f $@ && ! grep -qF $(COMMIT_MSG_MAGIC) $@; then \ | 1293 | if [ -n "$(GIT_HOOKS_DIR)" ]; then \ |
| 1289 | mkdir -p $@.d && mv $@ $@.d && \ | 1294 | if test -f $@ && ! grep -qF $(COMMIT_MSG_MAGIC) $@; then \ |
| 1290 | @ echo user commit-msg hook moved to $@.d/commit-msg; \ | 1295 | mkdir -p $@.d && mv $@ $@.d && \ |
| 1291 | fi; \ | 1296 | echo user commit-msg hook moved to $@.d/commit-msg; \ |
| 1292 | cp etc/git/commit-msg $@ | 1297 | fi && \ |
| 1298 | cp etc/git/commit-msg $@; \ | ||
| 1299 | fi | ||
| 1293 | 1300 | ||
| 1294 | # Convenience targets. | 1301 | # Convenience targets. |
| 1295 | GIT_HOOKS_SOURCE_FILES := $(shell find etc/git -type f -executable) | 1302 | GIT_HOOKS_SOURCE_FILES := $(shell find etc/git -type f -executable) |
