Skip to content

Commit

Permalink
Create pre-commit hook for nbstripout
Browse files Browse the repository at this point in the history
  • Loading branch information
devstein committed Jun 20, 2019
1 parent ec7f7a5 commit bd2f6a0
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 0 deletions.
14 changes: 14 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
*.egg
*.egg-info/
*.eggs/
*.pyc
.*.swp
.travis-solo/
MANIFEST
README.html
__pycache__/
build/
dist/
htmlcov/
.coverage
.idea/
6 changes: 6 additions & 0 deletions .pre-commit-hooks.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
- id: nbstripout
name: Strip Outputs from Notebooks
description: Strip outputs from all new notebooks
entry: nbstripout
language: script
files: (^|/).+\.ipynb$
30 changes: 30 additions & 0 deletions nbstripout.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#!/bin/sh
#
# strip output of IPython Notebooks
# add this as `.git/hooks/pre-commit`
# to run every time you commit a notebook
#
# requires `nbstripout` to be available on your PATH
#

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

# Find notebooks to be committed
(
IFS='
'
NBS=`git diff-index --cached $against --name-only --diff-filter=A | grep '.ipynb' | uniq`

for NB in $NBS ; do
echo "Removing outputs from $NB"
nbstripout "$NB"
git add "$NB"
done
)

exec git diff-index --check --cached $against --

0 comments on commit bd2f6a0

Please sign in to comment.