kynan / nbstripout

strip output from Jupyter and IPython notebooks
Other
1.21k stars 95 forks source link

added support for git diff #53

Closed utsekaj42 closed 7 years ago

utsekaj42 commented 7 years ago

This patch ensures that git diff makes a diff of the files after applying nbstripout.

I have also created a test, but I'm not sure about a couple things as I have never used travis, so I have included it here in hopes that someone can help me make it work.

I modified test-git.t as follows.

$ git init foobar
  Initialized empty Git repository in .* (re)
  $ cd foobar
  $ echo -n "*.txt text" >> .git/info/attributes
  $ nbstripout --is-installed
  [1]
  $ nbstripout --install
  $ nbstripout --is-installed
  $ git diff --no-ext-diff --unified=0 --exit-code -a --no-prefix ${TESTDIR}/test_diff.ipynb ${TESTDIR}/test_diff_output.ipynb 
  $ git diff ${TESTDIR}/test_diff.ipynb ${TESTDIR}/test_diff_different.ipynb 
  diff --git a/home/utsekaj42/sandbox/nbstripout/tests/test_diff.ipynb b/home/utsekaj42/sandbox/nbstripout/tests/test_diff_different.ipynb
  index e397b74..786bca5 100644
  --- a/home/utsekaj42/sandbox/nbstripout/tests/test_diff.ipynb
  +++ b/home/utsekaj42/sandbox/nbstripout/tests/test_diff_different.ipynb
  @@ -6,7 +6,7 @@
      "metadata": {},
      "outputs": [],
      "source": [
  -    "print u\"äöü\""
  +    "print u\"äöü now it is different \""
      ]
     }
    ],

  $ nbstripout --uninstall
  $ nbstripout --is-installed
  [1]
  $ cat .git/info/attributes
  *.txt text`
kynan commented 7 years ago

Great, looks like you figured out how to add a test. Thanks for your contribution!