Add new filter to smudge/clean usernames from info scripts

This commit is contained in:
2021-02-25 11:34:39 +01:00
parent a687c18af4
commit 8ddf6f755f
5 changed files with 47 additions and 0 deletions

1
.gitattributes vendored Normal file
View File

@ -0,0 +1 @@
cluster_info.json filter=username

View File

@ -0,0 +1,5 @@
#!/bin/sh
# Git filter to replace $USER with USERNAME.
# Assigned to cluster_info files in .gitattributes
sed -e "s/$USER/USERNAME/g"

View File

@ -0,0 +1,4 @@
#!/bin/sh
# Git filter to replace USERNAME with $USER.
# Assigned to cluster_info files in .gitattributes
sed -e "s/USERNAME/$USER/g"

19
dev/install_filters.sh Executable file
View File

@ -0,0 +1,19 @@
#!/bin/sh
# Installs filters for this repository
# Should be run from
ROOT="$(git rev-parse --show-toplevel)"
cd "$ROOT"
# username filter, for automaticly removing usernames from checkins
git config filter.username.smudge dev/git-filter-smudge-username.sh
git config filter.username.clean dev/git-filter-clean-username.sh
# pre-commit hook to varify usernames aren't committed
if [ -f .git/hooks/pre-commit ]; then
if ! cmp -s .git/hooks/pre-commit dev/pre-commit; then
echo "ERROR: $ROOT/.git/hooks/pre-commit exists; skipping hook" >&2
fi
else
ln -s ../../dev/pre-commit .git/hooks/pre-commit
fi

18
dev/pre-commit Executable file
View File

@ -0,0 +1,18 @@
#!/bin/sh
#
# A hook script to verify what is about to be committed.
# 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.
# Redirect output to stderr.
exec 1>&2
# Make sure I don't check in my username
bad_files="$( git grep --cached -l $USER */cluster_info.json)"
if [ -n "$bad_files" ]; then
echo "Error: Committing your username in"
echo "$bad_files"
exit 1
fi