-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Create pre-commit hook for nbstripout
- Loading branch information
Showing
3 changed files
with
50 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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
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/ |
This file contains 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
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$ |
This file contains 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
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 -- |