Skip to content

Instantly share code, notes, and snippets.

@organisciak
Created December 16, 2015 00:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save organisciak/8df19f54240eb37b599a to your computer and use it in GitHub Desktop.
Save organisciak/8df19f54240eb37b599a to your computer and use it in GitHub Desktop.
githook to convert iPython README to Markdown
READPY=$(git log --name-only HEAD^.. | grep "^README.ipynb$")
READMD=$(git log --name-only HEAD^.. | grep "^README.md$")
if [ -n "$READPY" ] && [ -z "$READMD" ]; then
echo "It looks like a new README was committed, appending a Markdown version"
ipython nbconvert --to markdown README.ipynb
# Adding this file doesn't work in pre-commit hooks, which is
# why we're appending post-commit
git add README.md
# We don't want to run this hook again after appending
git commit --amend -C HEAD --no-verify
fi
@organisciak
Copy link
Author

Why not simply generate the file pre-commit and stage? Because git add does not actually stage in pre-commit scripts. This is why the script checks post-commit and steps back, amending the commit.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment