diff options
| author | Maxim Cournoyer <maxim@guixotic.coop> | 2026-06-02 19:33:46 +0900 |
|---|---|---|
| committer | Maxim Cournoyer <maxim@guixotic.coop> | 2026-06-12 18:27:39 +0900 |
| commit | 59b2b4b3c2706d419c346865929e23fbf56b77ca (patch) | |
| tree | f33d4719adf7e990d2b0fdf3b70cf1cbeaef8b20 /Makefile.am | |
| parent | bd0b9284a9dd233b5e32131a9bb6aa74b74d796b (diff) | |
build: Emit warning/tips when git auto-configuration is not possible.
And otherwise do not abort the build.
* configure.ac (ENDIF): New output variable.
* Makefile.am (GIT_CORE_HOOKS_PATH, NL): New variables. Add conditional
warnings messages.
(git_hooks_checks): New variable.
($(GIT_HOOKS_DIR)/pre-push, $(GIT_HOOKS_DIR)/commit-msg): Use it.
Reported-by: Nicolas Graves <ngraves@ngraves.fr>
Merges: !9031
Fixes: #8064
Diffstat (limited to 'Makefile.am')
| -rw-r--r-- | Makefile.am | 36 |
1 files changed, 31 insertions, 5 deletions
diff --git a/Makefile.am b/Makefile.am index 416c958b202..0f7a93278c1 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, 2026 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> |
| @@ -1269,22 +1269,48 @@ cuirass-jobs: $(GOBJECTS) | |||
| 1269 | 1269 | ||
| 1270 | if in_git_p | 1270 | if in_git_p |
| 1271 | # Git auto-configuration. | 1271 | # Git auto-configuration. |
| 1272 | 1272 | GIT_CORE_HOOKS_PATH := $(shell git config --global core.hooksPath 2>/dev/null) | |
| 1273 | # Note: the following git commands may fail and produce empty variables, | ||
| 1274 | # e.g. when working on a work tree in a container. | ||
| 1275 | GIT_HOOKS_DIR := $(shell git rev-parse --git-path hooks 2>/dev/null) | 1273 | GIT_HOOKS_DIR := $(shell git rev-parse --git-path hooks 2>/dev/null) |
| 1276 | GIT_CONFIG_FILE := $(shell git rev-parse --git-path config 2>/dev/null) | 1274 | GIT_CONFIG_FILE := $(shell git rev-parse --git-path config 2>/dev/null) |
| 1275 | |||
| 1276 | # Produce a warning/hint in cases where the Guix-provided hooks won't be | ||
| 1277 | # installed. Need some empty variable trickery as Automake strips extra blank | ||
| 1278 | # lines for some reason. | ||
| 1279 | override EMPTY := | ||
| 1280 | define NL | ||
| 1281 | |||
| 1282 | $(EMPTY) | ||
| 1283 | endef | ||
| 1284 | |||
| 1285 | ifneq ($(GIT_CORE_HOOKS_PATH),) | ||
| 1286 | $(warning Not installing Guix-provided git hooks; global hooks path set$(NL)$\ | ||
| 1287 | Hint: unset global git hooks path) | ||
| 1288 | @ENDIF@ | ||
| 1289 | |||
| 1290 | ifeq ($(GIT_HOOKS_DIR),) | ||
| 1291 | $(warning Not installing Guix-provided git hooks; hooks dir not found$(NL)$\ | ||
| 1292 | Hint: avoid containerized environment when using a git worktree) | ||
| 1293 | @ENDIF@ | ||
| 1294 | |||
| 1295 | ifeq ($(GIT_CONFIG_FILE),) | ||
| 1296 | $(warning Not installing Guix-provided git configurations; \ | ||
| 1297 | git config file not found$(NL)$\ | ||
| 1298 | Hint: avoid containerized environment when using a git worktree) | ||
| 1299 | @ENDIF@ | ||
| 1300 | |||
| 1277 | $(GIT_HOOKS_DIR): | 1301 | $(GIT_HOOKS_DIR): |
| 1278 | if [ -n "$(GIT_HOOKS_DIR)" ]; then mkdir -p "$@"; fi | 1302 | if [ -n "$(GIT_HOOKS_DIR)" ]; then mkdir -p "$@"; fi |
| 1279 | 1303 | ||
| 1280 | $(GIT_HOOKS_DIR)/%: etc/git/% | $(GIT_HOOKS_DIR)/ | 1304 | $(GIT_HOOKS_DIR)/%: etc/git/% | $(GIT_HOOKS_DIR)/ |
| 1281 | if [ -n "$(GIT_HOOKS_DIR)" ]; then cp "$<" "$@"; fi | 1305 | if [ -n "$(GIT_HOOKS_DIR)" ]; then cp "$<" "$@"; fi |
| 1282 | 1306 | ||
| 1307 | git_hooks_checks = [ -n "$(GIT_HOOKS_DIR)" ] && [ -z "$(GIT_CORE_HOOKS_PATH)" ] | ||
| 1308 | |||
| 1283 | # Special-case the pre-push hook installation, to ensure it is always | 1309 | # Special-case the pre-push hook installation, to ensure it is always |
| 1284 | # up-to-date with its source. | 1310 | # up-to-date with its source. |
| 1285 | .PHONY: $(GIT_HOOKS_DIR)/pre-push | 1311 | .PHONY: $(GIT_HOOKS_DIR)/pre-push |
| 1286 | $(GIT_HOOKS_DIR)/pre-push: etc/git/pre-push | $(GIT_HOOKS_DIR) | 1312 | $(GIT_HOOKS_DIR)/pre-push: etc/git/pre-push | $(GIT_HOOKS_DIR) |
| 1287 | @if [ -n "$(GIT_HOOKS_DIR)" ]; then \ | 1313 | @if $(git_hooks_checks); then \ |
| 1288 | cmp "--silent" "$<" "$@" || cp "$<" "$@"; \ | 1314 | cmp "--silent" "$<" "$@" || cp "$<" "$@"; \ |
| 1289 | fi | 1315 | fi |
| 1290 | 1316 | ||
