...
 
Commits (59)
.git* export-ignore
* eol=lf whitespace=indent-with-non-tab
*.sample
This diff is collapsed.
Kitware Local Git Hooks
Copyright 2010-2011 Kitware, Inc.
This product includes software developed at Kitware, Inc.
(http://www.kitware.com/).
Portions of this software were developed as part of Gerrit Code Review
(http://code.google.com/p/gerrit/) by The Android Open Source Project.
#!/usr/bin/env bash
#=============================================================================
# Copyright 2010-2012 Kitware, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#=============================================================================
. "${BASH_SOURCE%/*}/hooks-config.bash"
# Start with project-specific hook.
hooks_start commit-msg "$@"
# Prepare a copy of the message:
# - strip comment lines
# - stop at "diff --git" (git commit -v)
commit_msg="$GIT_DIR/COMMIT_MSG"
sed -n -e '/^#/d' -e '/^diff --git/q' -e 'p;d' "$1" > "$commit_msg"
die_advice='
To continue editing, run the command
git commit -e -F '"$commit_msg"'
(assuming your working directory is at the top).'
die() {
echo 'commit-msg hook failure' 1>&2
echo '-----------------------' 1>&2
echo '' 1>&2
echo "$@" 1>&2
test -n "$die_advice" && echo "$die_advice" 1>&2
exit 1
}
#-----------------------------------------------------------------------------
# Check the commit message layout with a simple state machine.
msg_is_merge() {
echo "$line" | grep "^Merge " >/dev/null 2>&1
}
msg_is_revert() {
echo "$line" | grep "^Revert " >/dev/null 2>&1
}
msg_first() {
len=$(echo -n "$line" | wc -c)
if test $len -eq 0; then
# not yet first line
return
elif test $len -lt 8; then
die 'The first line must be at least 8 characters:
--------
'"$line"'
--------'
elif test $len -gt 78 && ! msg_is_merge && ! msg_is_revert; then
die 'The first line may be at most 78 characters:
------------------------------------------------------------------------------
'"$line"'
------------------------------------------------------------------------------'
elif echo "$line" | grep "^[ ]\|[ ]$" >/dev/null 2>&1; then
die 'The first line may not have leading or trailing space:
['"$line"']'
else
# first line okay
state=second
fi
}
msg_second() {
if test "x$line" != "x"; then
die 'The second line must be empty:
'"$line"
else
state=rest
fi
}
msg_rest() {
if echo "$line" | grep -q "^Change-Id:"; then
state=gerrit
fi
}
msg_gerrit() {
test "x$line" = "x" && return
echo "$line" | grep -q '^[A-Za-z0-9-][A-Za-z0-9-]*:' && return
die 'The Change-Id line must appear in a footer at the bottom.'
}
# Pipe commit message into the state machine.
state=first
cat "$commit_msg" |
while IFS='' read line; do
msg_$state || break
done &&
rm -f "$commit_msg" || exit 1
die_advice='' # No more temporary message file.
#-----------------------------------------------------------------------------
# Optionally run Gerrit's commit-msg hook to add a Change-Id line.
gerrit_advice() {
gerrits=$(git config -l |grep '^remote\.[^=]\+url=.*review.*$')
test "x$gerrits" != "x" || return 0
echo 'Some config values look like Gerrit Code Review URLs:'
echo ''
echo "$gerrits" | sed 's/^/ /'
echo '
This hook can automatically add a "Change-Id" footer to commit messages
to make interaction with Gerrit easier. To enable this feature, run
git config hooks.GerritId true
Then run "git commit --amend" to fix this commit. Otherwise, run
git config hooks.GerritId false
to disable the feature and this message.'
}
gerrit_error() {
die 'non-bool config value hooks.GerritId = '"$hooks_GerritId"
}
gerrit_hook() {
"$HOOKS_DIR/gerrit/commit-msg" "$@" ||
die 'gerrit/commit-msg failed'
}
hooks_GerritId=$(git config --get hooks.GerritId)
case "$hooks_GerritId" in
'true') gerrit_hook "$@" ;;
'false') ;;
'') gerrit_advice ;;
*) gerrit_error ;;
esac
#-----------------------------------------------------------------------------
# Chain to project-specific hook.
hooks_chain commit-msg "$@"
#!/usr/bin/env bash
# From Gerrit Code Review 2.1.5
#
# Part of Gerrit Code Review (http://code.google.com/p/gerrit/)
#
# Copyright (C) 2009 The Android Open Source Project
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
CHANGE_ID_AFTER="Bug|Issue"
MSG="$1"
# Check for, and add if missing, a unique Change-Id
#
add_ChangeId() {
clean_message=$(sed -e '
/^diff --git a\/.*/{
s///
q
}
/^Signed-off-by:/d
/^#/d
' "$MSG" | git stripspace)
if test -z "$clean_message"
then
return
fi
if grep -i '^Change-Id:' "$MSG" >/dev/null
then
return
fi
id=$(_gen_ChangeId)
perl -e '
$MSG = shift;
$id = shift;
$CHANGE_ID_AFTER = shift;
undef $/;
open(I, $MSG); $_ = <I>; close I;
s|^diff --git a/.*||ms;
s|^#.*$||mg;
exit unless $_;
@message = split /\n/;
$haveFooter = 0;
$startFooter = @message;
for($line = @message - 1; $line >= 0; $line--) {
$_ = $message[$line];
if (/^[a-zA-Z0-9-]+:/ && !m,^[a-z0-9-]+://,) {
$haveFooter++;
next;
}
next if /^[ []/;
$startFooter = $line if ($haveFooter && /^\r?$/);
last;
}
@footer = @message[$startFooter+1..@message];
@message = @message[0..$startFooter];
push(@footer, "") unless @footer;
for ($line = 0; $line < @footer; $line++) {
$_ = $footer[$line];
next if /^($CHANGE_ID_AFTER):/i;
last;
}
splice(@footer, $line, 0, "Change-Id: I$id");
$_ = join("\n", @message, @footer);
open(O, ">$MSG"); print O; close O;
' "$MSG" "$id" "$CHANGE_ID_AFTER"
echo "Added Change-Id: I$id"
}
_gen_ChangeIdInput() {
echo "tree $(git write-tree)"
if parent=$(git rev-parse HEAD^0 2>/dev/null)
then
echo "parent $parent"
fi
echo "author $(git var GIT_AUTHOR_IDENT)"
echo "committer $(git var GIT_COMMITTER_IDENT)"
echo
printf '%s' "$clean_message"
}
_gen_ChangeId() {
_gen_ChangeIdInput |
git hash-object -t commit --stdin
}
add_ChangeId
#=============================================================================
# Copyright 2010-2012 Kitware, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#=============================================================================
# Make sure GIT_DIR is set.
if test -z "$GIT_DIR"; then
export GIT_DIR=$(git rev-parse --git-dir)
fi
# Load hooks configuration from source tree.
hooks_config=".hooks-config"
if test -r "$hooks_config"; then
hooks_config() {
git config -f "$hooks_config" "$@"
}
else
hooks_config() {
false
}
fi
config=".hooks-config.bash" && test -r "$config" && . "$config"
# Set up the location for "this" set of hooks.
HOOKS_DIR="${BASH_SOURCE%/*}"
hooks_chain() {
hook="$1" ; shift
chain=$(git config --get hooks.chain-$hook) ||
chain="$(hooks_config --get hooks.chain.$hook)" ||
eval chain="\${hooks_chain_${hook//-/_}}"
hooks_child "$chain" "$@" || exit
}
hooks_start() {
hook="$1" ; shift
start="$(hooks_config --get hooks.start.$hook)"
hooks_child "$start" "$@" || exit
}
hooks_child() {
child="$1" ; shift
test -n "$child" || return 0
case "$child" in
'/'*) prefix="" ;;
'[A-Za-z]:/'*) prefix="" ;;
'.'*) prefix="" ;;
*) prefix="./" ;;
esac
if test -x "$prefix$child" ; then
echo "$stdin" | "$prefix$child" "$@"
fi
}
# vim: set filetype=sh tabstop=8 softtabstop=8 shiftwidth=8 noexpandtab :
#!/usr/bin/env bash
#=============================================================================
# Copyright 2010-2015 Kitware, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#=============================================================================
. "${BASH_SOURCE%/*}/hooks-config.bash"
# Chain to project-specific hook.
hooks_chain post-commit "$@"
This diff is collapsed.
#!/usr/bin/env bash
#=============================================================================
# Copyright 2010-2014 Kitware, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#=============================================================================
. "${BASH_SOURCE%/*}/hooks-config.bash"
# Read all input up front so we can use it and hand it to the chained hook.
stdin="$(cat)" &&
# Chain to project-specific hook.
hooks_chain pre-push "$@"
#!/usr/bin/env bash
#=============================================================================
# Copyright 2010-2012 Kitware, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#=============================================================================
. "${BASH_SOURCE%/*}/hooks-config.bash"
# Start with project-specific hook.
hooks_start prepare-commit-msg "$@"
# Invoke the Gerrit Change-Id hook here for "git merge" because
# it does not run the normal commit-msg hook.
hooks_GerritId=$(git config --get hooks.GerritId)
case "$hooks_GerritId,$2,$3" in
true,merge,) "$HOOKS_DIR/gerrit/commit-msg" "$1" ;;
*) ;;
esac
#-----------------------------------------------------------------------------
# Chain to project-specific hook.
hooks_chain prepare-commit-msg "$@"