Skip to content

Instantly share code, notes, and snippets.

@HeMe2
Last active February 20, 2018 16:31
Show Gist options
  • Save HeMe2/55dd1f1f79b376ac3870f4eae03dcffa to your computer and use it in GitHub Desktop.
Save HeMe2/55dd1f1f79b376ac3870f4eae03dcffa to your computer and use it in GitHub Desktop.
python script for git on public machines, to force users to provide their author name to commits
#!/bin/usr/python3
# This script analyzes the given arguments and if no "--author" is included in the argument list it forces the user to
# enter his credentials. To force all git calls to pass this script, set this as an alias in the .bashrc or the
# .bash_aliases by adding the following line:
# alias git='python3 <path_to_this_script>'
if __name__== "__main__":
import sys
from subprocess import call
arguments_okay = True
if "commit" in sys.argv:
arguments_okay = False
for arg in sys.argv:
if "--author" in arg:
arguments_okay = True
if arguments_okay:
call(["git"] + sys.argv[1:])
else:
try:
address = input("Please enter your mail address: ")
author_string = '--author="' + address + '"'
call(["git"] + sys.argv[1:] + [author_string])
except KeyboardInterrupt:
print()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment