Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

nbstripout --install --global cannot file ~/.config/git/attributes #139

Closed
dennisobrien opened this issue Oct 7, 2020 · 3 comments
Closed

Comments

@dennisobrien
Copy link

I am trying to install nbstripout git integrations globally but I get an error finding the file ~/.config/git/attributes.

$ nbstripout --install --global
Traceback (most recent call last):
  File "/Users/denniso/opt/anaconda3/bin/nbstripout", line 10, in <module>
    sys.exit(main())
  File "/Users/denniso/opt/anaconda3/lib/python3.7/site-packages/nbstripout/_nbstripout.py", line 299, in main
    sys.exit(install(git_config, user=args._global, attrfile=args.attributes))
  File "/Users/denniso/opt/anaconda3/lib/python3.7/site-packages/nbstripout/_nbstripout.py", line 175, in install
    with open(attrfile, 'a', newline='') as f:
FileNotFoundError: [Errno 2] No such file or directory: '/Users/denniso/.config/git/attributes'

Is this attribute file expected to exist already? I would expect it to be using the file ~/.gitconfig based on the docs.

This is on MacOS 10.15.7

$ git --version
git version 2.24.3 (Apple Git-128)
$ nbstripout --version
0.3.9
@dennisobrien
Copy link
Author

If I manually create this empty file before installing, I don't see an error.

$ mkdir -p ~/.config/git
$ touch ~/.config/git/attributes
$ nbstripout --install --global

I'm not sure if the file ~/.config/git/attributes not existing is a bug with my git setup, or if nbstripout should be modified to create the file if it doesn't exist. I'm happy to make a PR if you have an opinion about how best to handle this.

@0x326
Copy link

0x326 commented Feb 18, 2021

The ${HOME}/.config/git directory isn't created by default in a Git installation. The error is essentially the same error one would get doing the following:

echo '...' > "${HOME}/.config/git/attributes

nbstripout should create the ${HOME}/.config/git directory (and any missing parent directories) if they don't exist (e.g. mkdir -p "${HOME}/.config/git")

@kynan kynan self-assigned this Apr 5, 2021
@kynan kynan added this to the 0.4.0 milestone Apr 5, 2021
@kynan
Copy link
Owner

kynan commented Apr 5, 2021

Thanks for reporting this. That is indeed a regression and nbstripout should be creating this directory if needed.

I'm implementing the convention document in man gitattributes btw.:

If you wish to affect only a single repository (i.e., to assign attributes to files that are particular to one user’s workflow for that repository), then attributes should be placed in the $GIT_DIR/info/attributes file. Attributes which should be version-controlled and distributed to other repositories (i.e., attributes of interest to all users) should go into .gitattributes files. Attributes that should affect all repositories for a single user should be placed in a file specified by the core.attributesFile configuration option (see git-config(1)). Its default value is $XDG_CONFIG_HOME/git/attributes. If $XDG_CONFIG_HOME is either not set or empty, $HOME/.config/git/attributes is used instead. Attributes for all users on a system should be placed in the $(prefix)/etc/gitattributes file.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants