I have configured git to remove jupyter notebook output with nbstripout before commits and diffs. It works perfectly fine from the git bash shell (in Windows). Now I would like to have the same functionality from within TortoiseGit. The output gets properly stripped upon committing, but running the TortoiseGit internal diff tool from the explorer context menu does not trigger the git diff.textconv filter configured in the .git/config by nbstripout:
[diff "ipynb"]
textconv = \"D:/Applications/Anaconda3/python.exe\" \"D:/Applications/Anaconda3/lib/site-packages/nbstripout.py\" -t
Is there any way to automatically run nbstripout before diff?
My current workaround is to manually remove notebook output before running diff.
TortoiseGit does not honor diff.textconv filters as of 2.7.0. Use advanced diff settings in TortoiseGit: https://tortoisegit.org/docs/tortoisegit/tgit-dug-settings.html#tgit-dug-settings-Progs-Adv
The following batch script does the job when configured under Advanced Diff Viewer Settings for .ipynb files as C:\path\to\script.bat %base %mine. It first runs nbstripout and opens the stripped file alongside the %base version in the TortoiseGit diff viewer.
:: Run nbstripout on a jupyter notebook before opening it with TortoiseGit
:: Call Signature: nbstripout_TortoiseGit.bat %base %mine
:: Parameters and options
@echo off
set "python_exe=C:\path\to\python.exe"
set "nbstripout=C:\path\to\nbstripout.py"
set "tmpfilename=%temp%\nbstripout_tempfile_%USERNAME%_%RANDOM%.ipynb"
set "diffViwer=TortoiseGitMerge.exe"
:: Get cmdline arguments
set base=%1
set mine=%2
:: Strip output from notebook
%python_exe% %nbstripout% -t %mine% > %tmpfilename%
:: Open file in diff viewer
%diffViwer% %base% %tmpfilename%
:: Remove tmpfilename
del %tmpfilename%
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With