Last active
April 19, 2016 17:09
-
-
Save wallyuva/15e625c7959459c82604ecde098539aa to your computer and use it in GitHub Desktop.
Studplan pre-commit hook for adding uuids
This file contains hidden or 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
| #!/bin/sh | |
| # This script will install a Git pre-commit hook that adds UUIDs | |
| # to assignments in studyplans | |
| # curl -fL https://gist.githubusercontent.com/wallyuva/15e625c7959459c82604ecde098539aa/raw/install-studyplan-pre-commit.sh | sh | |
| # Uninstall: | |
| # rm .git/hooks/pre-commit | |
| # in each repository that you've added this to. | |
| GITROOT=`git rev-parse --show-toplevel 2> /dev/null` | |
| echo | |
| echo | |
| if [ "$GITROOT" == "" ]; then | |
| echo This does not appear to be a git repo. | |
| exit 1 | |
| fi | |
| if [ -f "$GITROOT/.git/hooks/pre-commit" ]; then | |
| BACKUPTIMESTAMP=$(date +%d-%m-%Y" "%H:%M:%S) | |
| echo "Backing up the old pre-commit hook" | |
| mv "$GITROOT/.git/hooks/pre-commit" "$GITROOT/.git/hooks/pre-commit-$BACKUPTIMESTAMP" | |
| fi | |
| FILE=${1:-pre-commit} | |
| GISTURL="" | |
| echo Downloading $FILE hook from my gist address | |
| echo | |
| curl -fL -o "$GITROOT/.git/hooks/pre-commit" "https://gist.githubusercontent.com/wallyuva/15e625c7959459c82604ecde098539aa/raw/$FILE" | |
| if [ ! -f "$GITROOT/.git/hooks/pre-commit" ]; then | |
| echo Error downloading pre-commit script! | |
| exit 3 | |
| fi | |
| chmod +x "$GITROOT/.git/hooks/pre-commit" | |
| exit 0 |
This file contains hidden or 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
| #!/bin/sh | |
| # Adds uuids to studyplan assignments. https://gist.github.com/wallyuva/15e625c7959459c82604ecde098539aa | |
| 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 | |
| exec 1>&2 | |
| diffFileName=output.txt | |
| git diff --cached --name-status --diff-filter=AM *.ditamap > $diffFileName | |
| atom-studyplan-uuid-tool $diffFileName | |
| if [ $? != 0 ]; then | |
| exit 1 | |
| fi | |
| IFS=$'\t' | |
| while read -r status name | |
| do | |
| git add $name | |
| done < $diffFileName | |
| rm $diffFileName |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment