blob: 7de0d3fbd919d5950f1e801f527ae1f76290e4d9 [file] [log] [blame]
# Copyright 2022 The Fuchsia Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
# Installs git hooks for this repo into .git/hooks.
# Usage:
set -e # Fail on any error.
source "$(cd "$(dirname "${BASH_SOURCE[0]}")" >/dev/null 2>&1 && pwd)"/lib/ || exit $?
# Ensure the hooks were marked executable before copying them over,
# or git will fail to execute them.
chmod +x $FUCHSIA_EMBEDDER_DIR/hooks/*
# Install dependency for the hooks.
# Install the post-checkout hook for checkout, merge and rebase.
cp $FUCHSIA_EMBEDDER_DIR/hooks/post-checkout $FUCHSIA_EMBEDDER_DIR/.git/hooks/post-checkout
cp $FUCHSIA_EMBEDDER_DIR/hooks/post-checkout $FUCHSIA_EMBEDDER_DIR/.git/hooks/post-merge
cp $FUCHSIA_EMBEDDER_DIR/hooks/post-checkout $FUCHSIA_EMBEDDER_DIR/.git/hooks/post-rewrite
# post-rewrite gets fired for `amend` as well, so add a line that
# exits the post-rewrite hook immediately for anything but 'rebase'.
sed -i -e '6iif [[ "$1" != "rebase" ]]; then exit 0; fi;\' $FUCHSIA_EMBEDDER_DIR/.git/hooks/post-rewrite
# Install the pre-commit hook.
cp $FUCHSIA_EMBEDDER_DIR/hooks/pre-commit $FUCHSIA_EMBEDDER_DIR/.git/hooks/pre-commit
# Install Gerrit's commit-msg hook for code reviews.
if [[ ! -f `git -C $FUCHSIA_EMBEDDER_DIR rev-parse --git-dir`/hooks/commit-msg ]]
f=`git -C $FUCHSIA_EMBEDDER_DIR rev-parse --git-dir`/hooks/commit-msg ; mkdir -p $(dirname $f) ; curl -Lo $f ; chmod +x $f