Use generalized developer GitSetup hooks

Add hooks branch for VTK-m so that developers can get some pre-commit checks
easily.

Commands used to setup GitSetup:
  git remote add -f setup https://robertmaynard@gitlab.kitware.com/utils/gitsetup.git
  git merge --no-commit --allow-unrelated-histories setup/hooks
  git read-tree -u --prefix=. setup/hooks
This commit is contained in:
Robert Maynard 2017-05-26 14:47:25 -04:00
commit a36399ccfa
10 changed files with 804 additions and 0 deletions

2
.gitattributes vendored Normal file

@ -0,0 +1,2 @@
.git* export-ignore
* eol=lf whitespace=indent-with-non-tab

1
.gitignore vendored Normal file

@ -0,0 +1 @@
*.sample

202
LICENSE Normal file

@ -0,0 +1,202 @@
Apache License
Version 2.0, January 2004
http://www.apache.org/licenses/
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
1. Definitions.
"License" shall mean the terms and conditions for use, reproduction,
and distribution as defined by Sections 1 through 9 of this document.
"Licensor" shall mean the copyright owner or entity authorized by
the copyright owner that is granting the License.
"Legal Entity" shall mean the union of the acting entity and all
other entities that control, are controlled by, or are under common
control with that entity. For the purposes of this definition,
"control" means (i) the power, direct or indirect, to cause the
direction or management of such entity, whether by contract or
otherwise, or (ii) ownership of fifty percent (50%) or more of the
outstanding shares, or (iii) beneficial ownership of such entity.
"You" (or "Your") shall mean an individual or Legal Entity
exercising permissions granted by this License.
"Source" form shall mean the preferred form for making modifications,
including but not limited to software source code, documentation
source, and configuration files.
"Object" form shall mean any form resulting from mechanical
transformation or translation of a Source form, including but
not limited to compiled object code, generated documentation,
and conversions to other media types.
"Work" shall mean the work of authorship, whether in Source or
Object form, made available under the License, as indicated by a
copyright notice that is included in or attached to the work
(an example is provided in the Appendix below).
"Derivative Works" shall mean any work, whether in Source or Object
form, that is based on (or derived from) the Work and for which the
editorial revisions, annotations, elaborations, or other modifications
represent, as a whole, an original work of authorship. For the purposes
of this License, Derivative Works shall not include works that remain
separable from, or merely link (or bind by name) to the interfaces of,
the Work and Derivative Works thereof.
"Contribution" shall mean any work of authorship, including
the original version of the Work and any modifications or additions
to that Work or Derivative Works thereof, that is intentionally
submitted to Licensor for inclusion in the Work by the copyright owner
or by an individual or Legal Entity authorized to submit on behalf of
the copyright owner. For the purposes of this definition, "submitted"
means any form of electronic, verbal, or written communication sent
to the Licensor or its representatives, including but not limited to
communication on electronic mailing lists, source code control systems,
and issue tracking systems that are managed by, or on behalf of, the
Licensor for the purpose of discussing and improving the Work, but
excluding communication that is conspicuously marked or otherwise
designated in writing by the copyright owner as "Not a Contribution."
"Contributor" shall mean Licensor and any individual or Legal Entity
on behalf of whom a Contribution has been received by Licensor and
subsequently incorporated within the Work.
2. Grant of Copyright License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
copyright license to reproduce, prepare Derivative Works of,
publicly display, publicly perform, sublicense, and distribute the
Work and such Derivative Works in Source or Object form.
3. Grant of Patent License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
(except as stated in this section) patent license to make, have made,
use, offer to sell, sell, import, and otherwise transfer the Work,
where such license applies only to those patent claims licensable
by such Contributor that are necessarily infringed by their
Contribution(s) alone or by combination of their Contribution(s)
with the Work to which such Contribution(s) was submitted. If You
institute patent litigation against any entity (including a
cross-claim or counterclaim in a lawsuit) alleging that the Work
or a Contribution incorporated within the Work constitutes direct
or contributory patent infringement, then any patent licenses
granted to You under this License for that Work shall terminate
as of the date such litigation is filed.
4. Redistribution. You may reproduce and distribute copies of the
Work or Derivative Works thereof in any medium, with or without
modifications, and in Source or Object form, provided that You
meet the following conditions:
(a) You must give any other recipients of the Work or
Derivative Works a copy of this License; and
(b) You must cause any modified files to carry prominent notices
stating that You changed the files; and
(c) You must retain, in the Source form of any Derivative Works
that You distribute, all copyright, patent, trademark, and
attribution notices from the Source form of the Work,
excluding those notices that do not pertain to any part of
the Derivative Works; and
(d) If the Work includes a "NOTICE" text file as part of its
distribution, then any Derivative Works that You distribute must
include a readable copy of the attribution notices contained
within such NOTICE file, excluding those notices that do not
pertain to any part of the Derivative Works, in at least one
of the following places: within a NOTICE text file distributed
as part of the Derivative Works; within the Source form or
documentation, if provided along with the Derivative Works; or,
within a display generated by the Derivative Works, if and
wherever such third-party notices normally appear. The contents
of the NOTICE file are for informational purposes only and
do not modify the License. You may add Your own attribution
notices within Derivative Works that You distribute, alongside
or as an addendum to the NOTICE text from the Work, provided
that such additional attribution notices cannot be construed
as modifying the License.
You may add Your own copyright statement to Your modifications and
may provide additional or different license terms and conditions
for use, reproduction, or distribution of Your modifications, or
for any such Derivative Works as a whole, provided Your use,
reproduction, and distribution of the Work otherwise complies with
the conditions stated in this License.
5. Submission of Contributions. Unless You explicitly state otherwise,
any Contribution intentionally submitted for inclusion in the Work
by You to the Licensor shall be under the terms and conditions of
this License, without any additional terms or conditions.
Notwithstanding the above, nothing herein shall supersede or modify
the terms of any separate license agreement you may have executed
with Licensor regarding such Contributions.
6. Trademarks. This License does not grant permission to use the trade
names, trademarks, service marks, or product names of the Licensor,
except as required for reasonable and customary use in describing the
origin of the Work and reproducing the content of the NOTICE file.
7. Disclaimer of Warranty. Unless required by applicable law or
agreed to in writing, Licensor provides the Work (and each
Contributor provides its Contributions) on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
implied, including, without limitation, any warranties or conditions
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
PARTICULAR PURPOSE. You are solely responsible for determining the
appropriateness of using or redistributing the Work and assume any
risks associated with Your exercise of permissions under this License.
8. Limitation of Liability. In no event and under no legal theory,
whether in tort (including negligence), contract, or otherwise,
unless required by applicable law (such as deliberate and grossly
negligent acts) or agreed to in writing, shall any Contributor be
liable to You for damages, including any direct, indirect, special,
incidental, or consequential damages of any character arising as a
result of this License or out of the use or inability to use the
Work (including but not limited to damages for loss of goodwill,
work stoppage, computer failure or malfunction, or any and all
other commercial damages or losses), even if such Contributor
has been advised of the possibility of such damages.
9. Accepting Warranty or Additional Liability. While redistributing
the Work or Derivative Works thereof, You may choose to offer,
and charge a fee for, acceptance of support, warranty, indemnity,
or other liability obligations and/or rights consistent with this
License. However, in accepting such obligations, You may act only
on Your own behalf and on Your sole responsibility, not on behalf
of any other Contributor, and only if You agree to indemnify,
defend, and hold each Contributor harmless for any liability
incurred by, or claims asserted against, such Contributor by reason
of your accepting any such warranty or additional liability.
END OF TERMS AND CONDITIONS
APPENDIX: How to apply the Apache License to your work.
To apply the Apache License to your work, attach the following
boilerplate notice, with the fields enclosed by brackets "[]"
replaced with your own identifying information. (Don't include
the brackets!) The text should be enclosed in the appropriate
comment syntax for the file format. We also recommend that a
file or class name and description of purpose be included on the
same "printed page" as the copyright notice for easier
identification within third-party archives.
Copyright [yyyy] [name of copyright owner]
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.

8
NOTICE Normal file

@ -0,0 +1,8 @@
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.

105
commit-msg Executable file

@ -0,0 +1,105 @@
#!/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)
max_len=$(hooks_config --get hooks.commit-msg.maxLength || echo 78) &&
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 "$max_len" && ! msg_is_merge && ! msg_is_revert; then
die 'The first line may be at most '"$max_len"' 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
die 'Gerrit Change-Id are not allowed in VTK-m.'
fi
}
# 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.
#-----------------------------------------------------------------------------
# Chain to project-specific hook.
hooks_chain commit-msg "$@"

66
hooks-config.bash Normal file

@ -0,0 +1,66 @@
#=============================================================================
# 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 :

21
post-commit Executable file

@ -0,0 +1,21 @@
#!/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 "$@"

350
pre-commit Executable file

@ -0,0 +1,350 @@
#!/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 pre-commit "$@"
die() {
echo 'pre-commit hook failure' 1>&2
echo '-----------------------' 1>&2
echo '' 1>&2
echo "$@" 1>&2
exit 1
}
zero='0000000000000000000000000000000000000000'
#-----------------------------------------------------------------------------
# Check for committer identity.
advice='
Use the commands
git config --global user.name '\''Your Name'\''
git config --global user.email '\''you@yourdomain.com'\''
to introduce yourself to Git before committing.'
# Ensure name and email are available.
git config --get user.name > /dev/null &&
git config --get user.email > /dev/null ||
die 'Identity not configured!' "$advice"
# Validate the name and email.
git config --get user.name | grep ' ' > /dev/null ||
die 'Set user.name to your Real Name (with a space), not a userid.' "$advice"
git config --get user.email | grep '^[^@]*@[^@]*$' > /dev/null ||
die 'Set user.email to an email address (userid@validdomain.com).' "$advice"
#-----------------------------------------------------------------------------
# Check content that will be added by this commit.
if git rev-parse --verify -q HEAD > /dev/null; then
against=HEAD
else
# Initial commit: diff against an empty tree object
against=4b825dc642cb6eb9a060e54bf8d69288fbee4904
fi
# Merge ("git commit" after "git merge" with conflicts or --no-commit)
merge_head=$(git rev-parse -q --verify MERGE_HEAD) || merge_head=''
# Disallow non-ascii file names. The printable range starts at the
# space character and ends with tilde.
if test "$(git diff --cached --name-only --diff-filter=A -z $against |
LC_ALL=C tr -d '[ -~]\0')"; then
die 'Non-ascii file names may not be added:
'"$(git diff --cached --name-only --diff-filter=A $against)"
fi
#-----------------------------------------------------------------------------
# Builtin whitespace checks.
bad=$(git diff-index --check --cached $against --) || die "$bad"
# Approximate whitespace=tab-in-indent check with Git < 1.7.2.
git --version | grep -q " \(1\.[0-6]\|1\.7\.[01]\)" &&
approx_tab_in_indent=true || approx_tab_in_indent=false
check_tab() {
lines=$(git diff-index -p --cached $against -- "$1" |
grep '^+ ') &&
echo "$lines" |
while read line; do
echo "$1: tab in indent." &&
echo "$line"
done
}
# We are going to use server side reformat controls for this
# # Reject addition of a line without a newline at end-of-file.
# check_no_lf_at_eof() {
# lines=$(git diff-index -p --cached $against -- "$1" | tail -2)
# if echo "$lines" | head -1 | grep -q '^+' &&
# echo "$lines" | tail -1 | grep -q '^\\ No newline'; then
# echo "$1: No newline at end of file"
# fi
# }
# We are going to use server side reformat controls for this
# # Custom whitespace checks.
# check_whitespace() {
# ws=$(git check-attr whitespace -- "$file" |
# sed 's/^[^:]*: whitespace: //')
# if $approx_tab_in_indent; then
# case ",$ws," in
# *,tab-in-indent,*) check_tab "$1" ;;
# esac
# fi
# case ",$ws," in
# *,no-lf-at-eof,*) check_no_lf_at_eof "$1" ;;
# esac
# }
# bad=$(git diff-index --name-only --cached $against -- |
# while read file; do
# check_whitespace "$file"
# done)
# test -z "$bad" || die "$bad"
#-----------------------------------------------------------------------------
# Check file modes and sizes.
mode_looks_exe() {
case "$1" in
*.bat) return 0 ;;
*.cmd) return 0 ;;
*.exe) return 0 ;;
*.com) return 0 ;;
esac
git cat-file blob "$2" | head -1 | grep "^#!/" > /dev/null
}
mode_not_exe () {
echo "The file '$file' has looks executable but does not have an executable mode.
On UNIX, run:
$ chmod u+x '$file' && git add -u '$file'
On Windows, run:
$ git update-index --chmod=+x '$file'
"
}
mode_bad_exe () {
echo "The file '$file' has executable mode but does not look executable.
On UNIX, run:
$ chmod u-x '$file' && git add -u '$file'
On Windows, run:
$ git update-index --chmod=-x '$file'
"
}
mode_non_file () {
echo "The path '$file' has a non-file mode."
}
check_mode() {
case "$dst_mode" in
100755) mode_looks_exe "$file" "$dst_obj" || mode_bad_exe ;;
100644) mode_looks_exe "$file" "$dst_obj" && mode_not_exe ;;
160000) ;;
*) mode_non_file ;;
esac
}
size_max_KiB=$(git config hooks.MaxObjectKiB)
test -n "$size_max_KiB" || size_max_KiB=1024
size_too_large_once=""
size_too_large_once() {
test -z "$size_too_large_once" || return ; size_too_large_once=done
echo 'At least one file is staged for commit with size larger than its limit.
We prefer to keep large files out of the main source tree, especially
binary files that do not compress well. This hook disallows large files
by default but can be configured. A limit for specific files or patterns
may be set in ".gitattributes" with the "hooks.MaxObjectKiB" attribute.
For example, the line
*.c hooks.MaxObjectKiB=2048
sets a limit of 2048 KiB for C source files. See "git help attributes"
for details on the .gitattributes format. If no attribute has been set
for a given file then its size is limited by the local default. Run
git config hooks.MaxObjectKiB $KiB
to set the local default limit (0 to disable).
'
}
size_too_large() {
size_too_large_once
echo "The path '$file' has size $file_KiB KiB, greater than allowed $max_KiB KiB."
}
size_validate_max_KiB() {
test "$max_KiB" -ge "0" 2>/dev/null && return 0
echo "The path '$file' has invalid attribute \"hooks-MaxObjectKiB=$max_KiB\"."
return 1
}
check_size() {
test "$dst_obj" != "$zero" || return
max_KiB=$(git check-attr hooks.MaxObjectKiB -- "$file" |
sed 's/^[^:]*: hooks.MaxObjectKiB: //')
case "$max_KiB" in
'unset') return ;; # No maximum for this object.
'set') max_KiB="$size_max_KiB" ;; # Use local default.
'unspecified') max_KiB="$size_max_KiB" ;; # Use local default.
*) size_validate_max_KiB || return ;;
esac
if test "$max_KiB" -gt "0"; then
file_KiB=$(expr '(' $(git cat-file -s "$dst_obj") + 1023 ')' / 1024)
test "$file_KiB" -le "$max_KiB" || size_too_large
fi
}
short_commit() {
git rev-parse --short "$1" 2>/dev/null || echo "$1"
}
lookup_config_module_update() {
update=$(git config "hooks.$1.update")
# Special-case "true" to accept any update.
test "{$update}" = "{true}" && echo '.' && return
# Format is "aaaaaa..bbbbbb" for update aaaaaa => bbbbbb.
# Convert to regex "^aaaaaa[a-z0-9]* bbbbbb[a-z0-9]*$".
sha1ex='[a-z0-9][a-z0-9][a-z0-9][a-z0-9][a-z0-9][a-z0-9][a-z0-9]*'
regex='^\('"$sha1ex"'\)\.\.\('"$sha1ex"'\)$'
echo "$update" |
sed -n "/$regex/ {s/$regex/"'^\1[a-z0-9]* \2[a-z0-9]*$/;p;}' |
grep '.' # Return false if result is empty.
}
check_module() {
enabled=$(git config --get --bool hooks.submodule) || enabled=true
test "$enabled" = "false" && return
# Allow merged submodule updates.
test -n "$merge_head" &&
merge_obj=$(git rev-parse -q --verify "$merge_head:$file") &&
test "$merge_obj" = "$dst_obj" && return
# Allow module-only commits without extra work.
test -z "$diffs_normal" && return
# Check if module update is allowed with other changes.
allow=$(lookup_config_module_update "$file") || allow='none'
if echo "$src_obj $dst_obj" | grep "$allow" > /dev/null; then
return
fi
src_short=$(short_commit "$src_obj")
dst_short=$(short_commit "$dst_obj")
echo 'A submodule link is staged for commit (among other changes):
"'"$file"'" '"$src_short => $dst_short"'
This may occur by accident so we require an extra step to commit.
If you intend to include this change in your commit, run
git config "hooks.'"$file"'.update" '"$src_short..$dst_short"'
to explicitly allow the change and try the commit again. Otherwise run
git reset HEAD -- "'"$file"'"
to unstage the change. Furthermore, if you did not intend to modify
the submodule at all, also run
git submodule update -- "'"$file"'"
to checkout the current version of the submodule in your work tree.
Test your changes again to see if they still work with the module.
Finally, try the commit again.
'
return 1
}
check_module_rewind() {
parent_name="$1"
parent_commit="$2"
base=$(GIT_DIR="$file/.git" \
git merge-base $src_obj $dst_obj 2>/dev/null) || base=''
test "$base" != "$dst_obj" && return
parent_short=$(short_commit "$parent_commit")
src_short=$(GIT_DIR="$file/.git" short_commit "$src_obj")
dst_short=$(GIT_DIR="$file/.git" short_commit "$dst_obj")
echo 'This commit would rewind a submodule link:
"'"$file"'" '"$src_short => $dst_short"'
from the newer version in '"$parent_name"' ('"$parent_short"'). Run
git reset '"$parent_name"' -- "'"$file"'"
git submodule update -- "'"$file"'"
to checkout the newer version of the submodule in your work tree.
Then try the commit again.
'
return 1
}
diffs=$(git diff-index --cached $against -- |
sed -n '/^:[^:]/ {s/^://;p;}')
diffs_normal=$(echo "$diffs" | grep -v '^...... 160000')
diffs_module=$(echo "$diffs" | grep '^...... 160000')
bad=$(
test -n "$diffs_normal" && echo "$diffs_normal" |
while read src_mode dst_mode src_obj dst_obj status file; do
if test "$src_mode" != "$dst_mode" -a "$dst_mode" != "000000"; then
check_mode
fi
# We don't want to enable the size check currently, need to verify
# git-lfs interaction first
# if test "$dst_mode" != "160000" -a "$dst_mode" != '000000'; then
# check_size
# fi
done
test -n "$diffs_module" && echo "$diffs_module" |
while read src_mode dst_mode src_obj dst_obj status file; do
check_module_rewind HEAD "$against" &&
check_module ||
break
done
)
test -z "$bad" || die "$bad"
#-----------------------------------------------------------------------------
# Merge checks.
if test -n "$merge_head"; then
merge_diffs=$(git diff-index --cached $merge_head -- |
sed -n '/^:[^:]/ {s/^://;p;}')
else
merge_diffs=''
fi
merge_diffs_normal=$(echo "$merge_diffs" | grep -v '^...... 160000')
merge_diffs_module=$(echo "$merge_diffs" | grep '^...... 160000')
bad=$(
test -n "$merge_diffs_module" && echo "$merge_diffs_module" |
while read src_mode dst_mode src_obj dst_obj status file; do
check_module_rewind MERGE_HEAD "$merge_head" ||
break
done
)
test -z "$bad" || die "$bad"
#-----------------------------------------------------------------------------
# Chain to project-specific hook.
hooks_chain pre-commit "$@"
# vim: set filetype=sh tabstop=8 softtabstop=8 shiftwidth=8 noexpandtab :

24
pre-push Executable file

@ -0,0 +1,24 @@
#!/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 "$@"

25
prepare-commit-msg Executable file

@ -0,0 +1,25 @@
#!/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 "$@"
#-----------------------------------------------------------------------------
# Chain to project-specific hook.
hooks_chain prepare-commit-msg "$@"