diff --git a/README.md b/README.md index e459d1c..562da3b 100644 --- a/README.md +++ b/README.md @@ -17,3 +17,4 @@ Dit werkt veel mooier en makkelijker. 73 Henk PG0H +PS All comments are in dutch! diff --git a/git/hooks/README.md b/git/hooks/README.md new file mode 100644 index 0000000..3c11ac5 --- /dev/null +++ b/git/hooks/README.md @@ -0,0 +1,11 @@ +Maak je git leven makkelijker + +sudo cp pre-commit prepare-commit-msg /usr/share/git-core/templates/hooks/ + +Doe dan het cmd git init , deze zet deze .git/hooks erin + +na een git add -A # dit is alles in je dir en subdirs + +Doe dan een git c2 om te committen + +Dan is er auto een datum als comment gemaakt zoals als je ziet in deze repo diff --git a/git/hooks/gitconfig b/git/hooks/gitconfig new file mode 100644 index 0000000..a1e7d97 --- /dev/null +++ b/git/hooks/gitconfig @@ -0,0 +1,8 @@ + +# zet dit onderaan in je .gitconfig +[alias] + ci = commit -an + c2 = commit -an --no-edit + co = checkout + st = status -a + diff --git a/git/hooks/pre-commit b/git/hooks/pre-commit new file mode 100755 index 0000000..aa7ccce --- /dev/null +++ b/git/hooks/pre-commit @@ -0,0 +1,60 @@ +#!/bin/bash +# + +# A git hook script to find and fix trailing whitespace +# in your commits. Bypass it with the --no-verify option +# to git-commit +# +# usage: make a soft link to this file, e.g., ln -s ~/config/pre-commit.git.sh ~/some_project/.git/hooks/pre-commit + +# detect platform +platform="win" +uname_result=`uname` +if [ "$uname_result" = "Linux" ]; then + platform="linux" +elif [ "$uname_result" = "Darwin" ]; then + platform="mac" +fi + +# change IFS to ignore filename's space in |for| +IFS=" +" +# autoremove trailing whitespace +for line in `git diff --check --cached | sed '/^[+-]/d'` ; do + # get file name + if [ "$platform" = "mac" ]; then + file="`echo $line | sed -E 's/:[0-9]+: .*//'`" + else + file="`echo $line | sed -r 's/:[0-9]+: .*//'`" + fi + # display tips + echo -e "auto remove trailing whitespace in \033[31m$file\033[0m!" + # since $file in working directory isn't always equal to $file in index, so we backup it + mv -f "$file" "${file}.save" + # discard changes in working directory + git checkout -- "$file" + # remove trailing whitespace + if [ "$platform" = "win" ]; then + # in windows, `sed -i` adds ready-only attribute to $file(I don't kown why), so we use temp file instead + sed 's/[[:space:]]*$//' "$file" > "${file}.bak" + mv -f "${file}.bak" "$file" + elif [ "$platform" == "mac" ]; then + sed -i "" 's/[[:space:]]*$//' "$file" + else + sed -i 's/[[:space:]]*$//' "$file" + fi + git add "$file" + # restore the $file + sed 's/[[:space:]]*$//' "${file}.save" > "$file" + rm "${file}.save" +done + +if [ "x`git status -s | grep '^[A|D|M]'`" = "x" ]; then + # empty commit + echo + echo -e "\033[31mNO CHANGES ADDED, ABORT COMMIT!\033[0m" + exit 1 +fi + +# Now we can commit +exit diff --git a/git/hooks/prepare-commit-msg b/git/hooks/prepare-commit-msg new file mode 100755 index 0000000..6588a19 --- /dev/null +++ b/git/hooks/prepare-commit-msg @@ -0,0 +1,5 @@ +#!/bin/bash +# +# Append current `date` to commit messages + +echo "`date +'%Y-%m-%d %H:%M:%S'`" >> $1