Skip to content

write-gitignore confusion when using git-add #346

@madduck

Description

@madduck

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.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions