tools/cl: Support worktree checkouts

CrOS checkouts are experimenting with using git worktree, where
the path to the hook directory is not .git/hooks. So ask git
where the hooks are stored instead.

BUG=b:236645893
TEST=./tools/cl upload in a worktree checkout

Change-Id: Ib353da0aea5d27ce29d1c082268a326adb429d23
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3739373
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Junichi Uekawa <uekawa@chromium.org>
Commit-Queue: Dennis Kempin <denniskempin@google.com>
This commit is contained in:
Dennis Kempin 2022-07-01 20:26:27 +00:00 committed by Chromeos LUCI
parent 2689c838af
commit 382acd20d3

View file

@ -3,6 +3,7 @@
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
from pathlib import Path
from impl.common import confirm, run_commands, cmd, CROSVM_ROOT
import sys
@ -90,7 +91,8 @@ def prerequisites():
sys.exit(1)
# Install gerrit commit hook
hook_path = CROSVM_ROOT / ".git/hooks/commit-msg"
hooks_dir = Path(git("rev-parse --git-path hooks").stdout())
hook_path = hooks_dir / "commit-msg"
if not hook_path.exists():
hook_path.parent.mkdir(exist_ok=True)
curl(f"{GERRIT_URL}/tools/hooks/commit-msg").write_to(hook_path)