diff --git a/README.md b/README.md index 32375ce..7aa7f28 100644 --- a/README.md +++ b/README.md @@ -100,11 +100,14 @@ Show help and usage instructions: ### Using as a Git filter -Set up the git filter and attributes as described in the manual installation -instructions below: +Set up the [git filter](https://git-scm.com/docs/gitattributes#_filter) and +attributes as described in the manual installation instructions below: nbstripout --install +Note: The filter is declared as `required`, meaning the filter *must* succeed. +Failures and misconfigurations will not simply cause the filter to be ignored. + Set up the git filter using `.gitattributes`: nbstripout --install --attributes .gitattributes diff --git a/nbstripout/_nbstripout.py b/nbstripout/_nbstripout.py index d4409cc..f588550 100644 --- a/nbstripout/_nbstripout.py +++ b/nbstripout/_nbstripout.py @@ -201,6 +201,7 @@ def install(git_config, install_location=INSTALL_LOCATION_LOCAL, python=None, at filepath = f'"{PureWindowsPath(python or sys.executable).as_posix()}" -m nbstripout' check_call(git_config + ['filter.nbstripout.clean', filepath]) check_call(git_config + ['filter.nbstripout.smudge', 'cat']) + check_call(git_config + ['filter.nbstripout.required', 'true']) check_call(git_config + ['diff.ipynb.textconv', filepath + ' -t']) attrfile = _get_attrfile(git_config, install_location, attrfile) except FileNotFoundError: @@ -251,6 +252,7 @@ def uninstall(git_config, install_location=INSTALL_LOCATION_LOCAL, attrfile=None try: call(git_config + ['--unset', 'filter.nbstripout.clean'], stdout=open(devnull, 'w'), stderr=STDOUT) call(git_config + ['--unset', 'filter.nbstripout.smudge'], stdout=open(devnull, 'w'), stderr=STDOUT) + call(git_config + ['--unset', 'filter.nbstripout.required'], stdout=open(devnull, 'w'), stderr=STDOUT) call(git_config + ['--remove-section', 'diff.ipynb'], stdout=open(devnull, 'w'), stderr=STDOUT) attrfile = _get_attrfile(git_config, install_location, attrfile) except FileNotFoundError: diff --git a/tests/test_git_integration.py b/tests/test_git_integration.py index 7d58cdc..1a85512 100644 --- a/tests/test_git_integration.py +++ b/tests/test_git_integration.py @@ -24,6 +24,7 @@ def test_install(pytester: pytest.Pytester): config = ConfigParser() config.read(".git/config") assert re.match(r".*python.* -m nbstripout", config['filter "nbstripout"']["clean"]) + assert config['filter "nbstripout"']["required"] == "true" assert config['filter "nbstripout"']["smudge"] == "cat" assert re.match(r".*python.* -m nbstripout -t", config['diff "ipynb"']["textconv"]) @@ -40,6 +41,7 @@ def test_install_different_python(pytester: pytest.Pytester): r".*DIFFERENTPYTHON.* -m nbstripout", config['filter "nbstripout"']["clean"] ) assert sys.executable not in config['filter "nbstripout"']["clean"] + assert config['filter "nbstripout"']["required"] == "true" assert config['filter "nbstripout"']["smudge"] == "cat" assert re.match( r".*DIFFERENTPYTHON.* -m nbstripout -t", config['diff "ipynb"']["textconv"]