-
Notifications
You must be signed in to change notification settings - Fork 109
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
354 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
param([switch]$all, [switch]$clear) | ||
|
||
$gitDir = git rev-parse --git-commom-dir | ||
|
||
if (!(test-path $gitDir)) | ||
{ | ||
$gitDir = git rev-parse --git-dir | ||
} | ||
|
||
$gitDir = (resolve-path ($gitDir)).Path | ||
|
||
if (!$gitDir) { | ||
throw ".git - Directory not found" | ||
} | ||
|
||
$gitHooksDir = join-path $gitDir "hooks" | ||
|
||
if (!(test-path $gitHooksDir)) { | ||
throw "$gitHooksDir not present" | ||
} | ||
|
||
if($clear) { | ||
write-host "cleaning old hooks dir: $githooksdir" | ||
Remove-Item (join-path $githooksdir "*") -force -recurse | ||
} | ||
|
||
write-host "providing files:" | ||
|
||
if ($all) { | ||
Copy-Item $PSScriptRoot/optional/* $githooksdir -force -recurse -PassThru | format-table Fullname | out-host | ||
} | ||
|
||
Copy-Item $PSScriptRoot/necessary/* $githooksdir -force -recurse -PassThru | format-table Fullname | out-host | ||
|
||
if($IsLinux) { | ||
chmod 755 (join-path $githooksdir "post-merge") | ||
chmod 755 (join-path $githooksdir "pre-commit") | ||
chmod 755 (join-path $githooksdir "precommit/check/*") | ||
chmod 755 (join-path $githooksdir "precommit/modify/*") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
concatenate() | ||
{ | ||
list="$1" | ||
element="$2" | ||
delimiter="\n" | ||
|
||
if [ -z "$list" ] | ||
then | ||
echo "$element" | ||
else | ||
echo -e "$list$delimiter$element" | ||
fi | ||
} | ||
|
||
removeEmptyLines() | ||
{ | ||
echo "$@" | sed '/^$/d' | ||
} | ||
|
||
isLinux() | ||
{ | ||
if [ "$OSTYPE" = "linux" ] | ||
then | ||
return 0 | ||
fi | ||
|
||
return 1 | ||
} | ||
|
||
isWindows() | ||
{ | ||
if [ "$OSTYPE" = "linux" ] | ||
then | ||
return 1 | ||
fi | ||
|
||
return 0 | ||
} | ||
|
||
onLinux() | ||
{ | ||
isLinux && $@ | ||
} | ||
|
||
onWindows() | ||
{ | ||
isWindows && $@ | ||
} | ||
|
||
runPSScript() | ||
{ | ||
enter "runPSScript" | ||
|
||
if isLinux | ||
then | ||
"pwsh" $@ | ||
else | ||
"powershell" "-noprofile" $@ | ||
fi | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
#!/bin/sh | ||
|
||
# Usage: add this file to your project's .git/hooks directory. | ||
# Now, when you change some files in repository and try to commit these | ||
# changes, git will run this script right after merge. | ||
|
||
base_dir="misc/git-hook" | ||
|
||
if [ ! -d "$base_dir" ] | ||
then | ||
echo "Warning: cannot determine hooks base folder" | ||
exit 0 | ||
fi | ||
|
||
cp -rf "$base_dir/necessary/"* .git/hooks/; | ||
|
||
for file in .git/hooks/*; do | ||
if [ -d "${file}" ] | ||
then | ||
for subfile in .git/hooks/"${file##*/}"/*; do | ||
if [ -e "$base_dir/optional/${file##*/}/${subfile##*/}" ] | ||
then | ||
cp -f "$base_dir/optional/${file##*/}/${subfile##*/}" "$subfile"; | ||
fi | ||
done | ||
else | ||
if [ -e "$base_dir/optional/${file##*/}" ] | ||
then | ||
cp -f "$base_dir/optional/${file##*/}" "$file"; | ||
fi | ||
fi | ||
done | ||
|
||
exit 0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
#!/bin/bash | ||
|
||
# Usage: add this file to your project's .git/hooks directory. | ||
# Now, when you change some files in repository and try to commit these | ||
# changes, git will run this script right before commit. | ||
|
||
GITDIR=`git rev-parse --git-common-dir` | ||
if [ "$(expr substr $(uname -s) 1 10)" == "MINGW64_NT" ]; then | ||
GITDIR=`cygpath --unix $GITDIR` | ||
fi | ||
|
||
export GITDIR | ||
|
||
if [ -f "./functions.bash" ] | ||
then | ||
. ./functions.bash | ||
else | ||
. $GITDIR/hooks/functions.bash | ||
fi | ||
|
||
echo ">>>>>>>> modifying begin <<<<<<<<" | ||
|
||
files=`find $GITDIR/hooks/precommit/modify/* -type f -maxdepth 0 -mindepth 0` | ||
|
||
for file in $files | ||
do | ||
echo "######## begin $file ########" | ||
|
||
if [ -z `echo "$file" | sed 's/.*\.ps1$//g'` ] | ||
then | ||
runPSScript -File $file | ||
else | ||
$file | ||
fi | ||
result="$?" | ||
|
||
if [ "$result" -ne 0 ] | ||
then | ||
echo "######## end $file: abort ########" | ||
exit 1 | ||
fi | ||
|
||
echo "######## end $file: continue ########" | ||
done | ||
|
||
echo ">>>>>>>> modifying complete <<<<<<<<" | ||
|
||
echo ">>>>>>>> checks begin <<<<<<<<" | ||
|
||
files=`find $GITDIR/hooks/precommit/check/* -type f -maxdepth 0 -mindepth 0` | ||
|
||
for file in $files | ||
do | ||
echo "######## begin $file ########" | ||
|
||
if [ -z `echo "$file" | sed 's/.*\.ps1$//g'` ] | ||
then | ||
runPSScript -File $file | ||
else | ||
$file | ||
fi | ||
result="$?" | ||
|
||
if [ "$result" -ne 0 ] | ||
then | ||
echo "######## end $file: abort ########" | ||
exit 1 | ||
fi | ||
|
||
echo "######## end $file: continue ########" | ||
done | ||
|
||
echo ">>>>>>>> checks complete <<<<<<<<" | ||
|
||
exit 0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
#!/bin/bash | ||
|
||
. $GITDIR/hooks/functions.bash | ||
|
||
if git rev-parse --verify HEAD >/dev/null 2>&1 | ||
then | ||
against=HEAD | ||
else | ||
# Initial commit: diff against an empty tree object | ||
against=4b825dc642cb6eb9a060e54bf8d69288fbee4904 | ||
fi | ||
|
||
# We should check only added or modified C/C++ source files for tabs. | ||
changed_files=$(git diff-index --cached $against | grep -E '[MA] .*\.(c|cpp|cc|cxx|h|hh)$' | cut -d' ' -f 2) | ||
|
||
issue_found=0 | ||
|
||
IFS=$'\n' # bash specific | ||
for file in $changed_files | ||
do | ||
result=`cat "$file" | grep -E -n '^[\t]*( | {1,3}\t)'` | ||
|
||
if [ -n "$result" ] | ||
then | ||
echo "file with indent issue: $file" | ||
echo "$result" | ||
issue_found=1 | ||
else | ||
echo "file without issue: $file" | ||
fi | ||
done | ||
|
||
if [ $issue_found = 1 ] | ||
then | ||
exit 1 | ||
fi | ||
|
||
exit 0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
#!/bin/bash | ||
|
||
. $GITDIR/hooks/functions.bash | ||
|
||
if git rev-parse --verify HEAD >/dev/null 2>&1 | ||
then | ||
against=HEAD | ||
else | ||
# Initial commit: diff against an empty tree object | ||
against=4b825dc642cb6eb9a060e54bf8d69288fbee4904 | ||
fi | ||
|
||
# We should check only added or modified files of these given types for line endings. | ||
changed_files=$(git diff-index --cached $against | grep -E '([MA] .*\.(c|cpp|cc|cxx|h|hh)$)' | cut -f 2) | ||
issue_found=0 | ||
|
||
IFS=$'\n' # bash specific | ||
for file in $changed_files | ||
do | ||
result=`cat "$file" | grep -E -n '[[:space:]]$'` | ||
|
||
if [ -n "$result" ] | ||
then | ||
echo "file with line ending issue: $file" | ||
echo "$result" | ||
issue_found=1 | ||
else | ||
echo "file without issue: $file" | ||
fi | ||
done | ||
|
||
if [ $issue_found = 1 ] | ||
then | ||
exit 1 | ||
fi | ||
|
||
exit 0 |
34 changes: 34 additions & 0 deletions
34
misc/git-hook/optional/precommit/modify/remove_trailing_spaces
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
#!/bin/sh | ||
|
||
. $GITDIR/hooks/functions.bash | ||
|
||
process() | ||
{ | ||
file="$1" | ||
|
||
mv "$file" "$file.orig" | ||
cat "$file.orig" | sed 's/[ \t]\+$//g' > "$file" | ||
rm "$file.orig" | ||
git add "$file" | ||
} | ||
|
||
if git rev-parse --verify HEAD >/dev/null 2>&1 | ||
then | ||
against=HEAD | ||
else | ||
# Initial commit: diff against an empty tree object | ||
against=4b825dc642cb6eb9a060e54bf8d69288fbee4904 | ||
fi | ||
|
||
changed_files=$(git diff-index --cached $against | grep -i -E '[MA] .*\.(c|cc|cpp|h|hh)$' | cut -d' ' -f 2) | ||
|
||
if [ -n "$changed_files" ] | ||
then | ||
echo "$changed_files" | while read file | ||
do | ||
echo "process \"$file\"" | ||
process "$file" | ||
done | ||
fi | ||
|
||
exit 0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
#!/bin/sh | ||
|
||
. $GITDIR/hooks/functions.bash | ||
|
||
process() | ||
{ | ||
file="$1" | ||
|
||
mv "$file" "$file.orig" | ||
cat "$file.orig" | sed 's/^\([\t]*\) /\1\t/g' | sed 's/^\([\t]*\) \{1,3\}\t/\1\t/g' > "$file" | ||
rm "$file.orig" | ||
git add "$file" | ||
} | ||
|
||
if git rev-parse --verify HEAD >/dev/null 2>&1 | ||
then | ||
against=HEAD | ||
else | ||
# Initial commit: diff against an empty tree object | ||
against=4b825dc642cb6eb9a060e54bf8d69288fbee4904 | ||
fi | ||
|
||
changed_files=$(git diff-index --cached $against | grep -i -E '[MA] .*\.(c|cc|cpp|h|hh)$' | cut -d' ' -f 2) | ||
|
||
if [ -n "$changed_files" ] | ||
then | ||
echo "$changed_files" | while read file | ||
do | ||
echo "process \"$file\"" | ||
process "$file" | ||
done | ||
fi | ||
|
||
exit 0 |