Hallo zusammen,
ich bin dabei einen Git pre-commit Hook zu basteln und brauche etwas Hilfe. Der Hook an sich wird gerufen und "funktioniert".
Das Ding überprüft die Namen der Objekte, die commitet werden sollen, ob sie nur zulässige Zeichen beinhalten.
Die zulässigen Zeichen sind:
- A-Z
- a-z
- 0-9
- - und _
- diese Zeichen könnten drin sein, sind aber "optional" so zu sagen [, ], (, und )
Mein Hook sieht bis jetzt so aus, ich überprüfe im Moment nur auf Leerzeichen (regex1 im Code):
Code
#!C:/Program\ Files/Git/usr/bin/sh.exe
# Called by "git commit" with no arguments. The hook should
# exit with non-zero status after issuing an appropriate message if
# it wants to stop the commit.
# def comparison target
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
# Redirect output to stderr.
exec 1>&2
IFS=$'\n'
## [[:blank:]] means space and tab. This makes it similar to: [ \t].
## [[:space:]], in addition to space and tab, includes newline, linefeed, formfeed, and vertical tab. This makes it similar to: [ \t\n\r\f\v]
teststring1="SLDWH-2086_Umsetzung_FiBu_Nebenbuch_Kontokorrent_(Kontokorrentkonto)"
teststring2="SLDWH-2082_Korrektur_ODI_Loadplans"
regex1="[[:space:]]+"
# Abort a commit if you have non ASCII characters in
# the commit, and output the non ASCII characters.
echo "Checking for unicode characters and trailing whitespace"
listchange=$(git diff --staged --name-only $against)
echo "Check filenames, check 1:"
for filename in $listchange
do
fname=$(basename $filename)
if [[ $fname =~ $regex1 ]]; then
echo "$fname match";
else
echo "$fname didn't match!";
fi
done
exit 1
Alles anzeigen
Die Variablen teststring1 und teststring2 sind Beispiele dafür, wie ein Objekten heißen kann.
Wäre jemand so nett die RegEx zu schreiben, ich scheitere gnadenlos dran...
Vielen Dank im Voraus!