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

~/.gitignore is ignored #1461

ijlyttle opened this issue Jul 17, 2021 · 3 comments · Fixed by #1477

~/.gitignore is ignored #1461

ijlyttle opened this issue Jul 17, 2021 · 3 comments · Fixed by #1477


Copy link

ijlyttle commented Jul 17, 2021

I realize that I can't provide a reproducible example; I need to tell a story (sorry).

I recently upgraded my Mac to Big Sur. Of course, one of the first things I did was install.packages("usethis"), then usethis::git_vaccinate().

I kept on seeing .DS_Store wanting to be committed, which was odd, so I kept adding it to local .gitignore. Finally, this morning, I said "enough" and started digging into it.

Of course, my ~/.gitignore file looked OK, so a little investigation brought me to this SO answer, and sure enough, I did not have git's core.excludesfile set.

So I set core.excludesfile, and .DS_Store "went away".

I see that in edit_git_ignore(), if there is no global gitignore file: you set core.excludesfile, then call git_vaccinate().

However, if you just call git_vaccinate(), I don't see that core.excludesfile gets set. I think this is how I got here.

As well git_vaccinated() does not check that core.excludesfile is set.

I have a few ideas on some solutions, and will be happy to contribute, but I figure I'd let you react first.


Copy link

Ah, by a lucky coincidence, I just got a new computer and ran git_vaccinated() a couple of days ago, and it resulted in the same problem for me. Consider it reproduced!

Copy link
Contributor Author

ijlyttle commented Jul 18, 2021

I'm glad (?) it is reproducible!

My thought is that git_ignore_path() is used by edit_git_ignore(), git_vaccinate() and git_vaccinated().

Perhaps git_ignore_path() could contain the logic for core.excludesfile, moving some of the logic out of edit_git_ignore():

If scope == "user", it could:

  • consult core.excludesfile

  • if core.excludesfile not set:

    • check if files "~/.gitignore" or "~/.gitignore_global" exist (in that order):
      • if either files exists, use that value.
      • if neither file exists, use (and create) "~/.gitignore", tell user via ui_done().
    • set core.excludesfile, tell user via ui_done()
  • return value of core.excludesfile

Happy to start a PR along these lines!

(edit to add that git_vaccinated() should be able to call git_ignore_path() in read-only mode.)

Copy link

jennybc commented Jul 18, 2021

This all seems reasonable to me 👍

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