File: pre-commit

package info (click to toggle)
python-nbstripout 0.8.1-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 436 kB
  • sloc: python: 870; sh: 18; makefile: 13
file content (30 lines) | stat: -rw-r--r-- 647 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
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 -z --cached $against --name-only | 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 --