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

write-gitignore confusion when using git-add #346

Open
madduck opened this issue Jul 2, 2024 · 1 comment
Open

write-gitignore confusion when using git-add #346

madduck opened this issue Jul 2, 2024 · 1 comment

Comments

@madduck
Copy link
Contributor

madduck commented Jul 2, 2024

The gitignore handling by vcsh is confusing. It does seem to work as intended,
but there are confusing error messages:

lotus:~% vcsh init bugdemo
Initialized empty Git repository in /home/madduck/.config/vcsh/repo.d/bugdemo.git/
vcsh: info: '/home/madduck/.gitignore.d/bugdemo' differs from new data, moving it to '/home/madduck/.gitignore.d/bugdemo.bak'
The following paths are ignored by one of your .gitignore files:
.gitignore.d
hint: Use -f if you really want to add them.
hint: Disable this message with "git config advice.addIgnoredFile false"
[main (root-commit) ca6eacc] seed gitignore file
 1 file changed, 2 insertions(+)
 create mode 100644 .gitignore.d/bugdemo

That message about having to use -f is confusing, especially since I haven't
called git-add. Update: except I did… there's a hook that does it. So my fault. But the issue still stands.

Let's move on:

lotus:~% vcsh enter bugdemo

+lotus:vcsh:bugdemo|main|~% mkdir -p sub/dir

+lotus:vcsh:bugdemo|main|~% date > sub/dir/date

+lotus:vcsh:bugdemo|main|~% git add sub/dir/date
The following paths are ignored by one of your .gitignore files:
sub
hint: Use -f if you really want to add them.
hint: Disable this message with "git config advice.addIgnoredFile false"

Okay, that makes perfect sense. It's a new file. Moving right along…

+lotus:vcsh:bugdemo|main|~% git add -f sub/dir/date

+lotus:vcsh:bugdemo|main|~% vcsh write-gitignore bugdemo
vcsh: info: '/home/madduck/.gitignore.d/bugdemo' differs from new data, moving it to '/home/madduck/.gitignore.d/bugdemo.bak'

+lotus:vcsh:bugdemo|main|~% git add .gitignore.d/bugdemo
The following paths are ignored by one of your .gitignore files:
.gitignore.d
hint: Use -f if you really want to add them.
hint: Disable this message with "git config advice.addIgnoredFile false"

Yeah well, .gitignore.d is ignored, but I am not trying to do anything with
that directory. The file I am actually adding is excluded from gitignore,
and it is also properly staged:

+lotus:vcsh:bugdemo|main|~% git status
On branch main
Changes to be committed:
  (use "git restore --staged <file>..." to unstage)
        modified:   .gitignore.d/bugdemo
        new file:   sub/dir/date

The same happens with any other file:

+lotus:vcsh:bugdemo|main|~% git commit -am.
[main 35cec3a] .
 2 files changed, 2 insertions(+)
 create mode 100644 sub/dir/date

+lotus:vcsh:bugdemo|main|~% cat .gitignore.d/bugdemo
*
!/.gitignore.d/bugdemo
!/sub/dir/date

+lotus:vcsh:bugdemo|main|~% date >| sub/dir/date

+lotus:vcsh:bugdemo|main|~% git add sub/dir/date
The following paths are ignored by one of your .gitignore files:
sub
hint: Use -f if you really want to add them.
hint: Disable this message with "git config advice.addIgnoredFile false"

+lotus:vcsh:bugdemo|main|~% git status
On branch main
Changes to be committed:
  (use "git restore --staged <file>..." to unstage)
        modified:   sub/dir/date

The way to fix this is IMHO by adding exclusions for all parent directories,
i.e. the .gitignore.d/bugdemo file should be:

*
!/.gitignore.d
!/.gitignore.d/bugdemo
!/sub
!/sub/dir
!/sub/dir/date

I believe this was the case in the past, and has changed. FTR, setting
VCSH_GITIGNORE=recursive has no effect on the above.

@alerque
Copy link
Collaborator

alerque commented Jul 2, 2024

Thanks for the detailed report. Without actually having dived into the nitty gritty yet, this seems like it is probably a regression related to #196/#334. Somewhene in between #311 also touched the ignore code.

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

No branches or pull requests

2 participants