From 1a3a1da16f40039cf5cd973dcd493e8857af8f48 Mon Sep 17 00:00:00 2001 From: Brad Fitzpatrick Date: Tue, 24 Nov 2026 18:44:51 +0000 Subject: [PATCH] misc/git_hook/githook: don't rebuild hooks after every OSS bump The launcher found the shared HOOK_VERSION via `go list -m -f '{{.Dir}}' tailscale.com`. But go list -m doesn't download modules, so after a repo bumps its tailscale.com dependency to a version not yet in the module cache, Dir is empty, SHARED_VER falls back to 0, and the launcher rebuilds ts-git-hook-bin even though the shared HOOK_VERSION didn't change. In corp, which can sometimes bump OSS a few times a day, that meant a spurious "git-hook: rebuilding ts-git-hook-bin..." (plus a module download) on the first git operation after most bumps. If Dir is empty, run `go mod download tailscale.com` and look again. The rebuild was going to download the module anyway. Bump HOOK_VERSION so existing installs pick up the new launcher. Updates tailscale/corp#40381 Change-Id: I6e4720702d7052df3b15dce0c60a8b313c6b48e3 Signed-off-by: Brad Fitzpatrick --- misc/git_hook/githook/HOOK_VERSION | 2 +- misc/git_hook/githook/launcher.sh | 10 +++++++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/misc/git_hook/githook/HOOK_VERSION b/misc/git_hook/githook/HOOK_VERSION index 7ed6ff82d..1e8b31496 100644 --- a/misc/git_hook/githook/HOOK_VERSION +++ b/misc/git_hook/githook/HOOK_VERSION @@ -1 +1 @@ -5 +6 diff --git a/misc/git_hook/githook/launcher.sh b/misc/git_hook/githook/launcher.sh index ba9f67dd9..2e5845b46 100755 --- a/misc/git_hook/githook/launcher.sh +++ b/misc/git_hook/githook/launcher.sh @@ -32,7 +32,15 @@ BINARY="$HOOK_DIR/ts-git-hook-bin$EXE" GO="$REPO_ROOT/tool/go$EXE" if [ ! -x "$GO" ]; then GO=go; fi -OSS_DIR="$(cd "$REPO_ROOT" && GOWORK=off "$GO" list -m -f '{{.Dir}}' tailscale.com 2>/dev/null || true)" +oss_dir() { + (cd "$REPO_ROOT" && GOWORK=off "$GO" list -m -f '{{.Dir}}' tailscale.com 2>/dev/null) || true +} +OSS_DIR="$(oss_dir)" +if [ -z "$OSS_DIR" ]; then + # go list -m doesn't download; a fresh go.mod bump may not be cached yet. + (cd "$REPO_ROOT" && GOWORK=off "$GO" mod download tailscale.com >/dev/null 2>&1) || true + OSS_DIR="$(oss_dir)" +fi SHARED_VER="$(cat "$OSS_DIR/misc/git_hook/githook/HOOK_VERSION" 2>/dev/null || echo 0)" LOCAL_VER="$(cat "$REPO_ROOT/misc/git_hook/HOOK_VERSION" 2>/dev/null || echo 0)" WANT="$SHARED_VER:$LOCAL_VER"