Skip to content

ignore: treat paths with trailing "/" as directories#5040

Merged
ethomson merged 1 commit into
libgit2:masterfrom
pks-t:pks/ignore-treat-dirpaths-as-dir
Apr 7, 2019
Merged

ignore: treat paths with trailing "/" as directories#5040
ethomson merged 1 commit into
libgit2:masterfrom
pks-t:pks/ignore-treat-dirpaths-as-dir

Conversation

@pks-t
Copy link
Copy Markdown
Member

@pks-t pks-t commented Apr 5, 2019

The function git_ignore_path_is_ignored is there to test the
ignore status of paths that need not necessarily exist inside of
a repository. This has the implication that for a given path, we
cannot always decide whether it references a directory or a file,
and we need to distinguish those cases because ignore rules may
treat those differently. E.g. given the following gitignore file:

*
!/**/

we'd only want to unignore directories, while keeping files
ignored. But still, calling git_ignore_path_is_ignored("dir/")
will say that this directory is ignored because it treats "dir/"
as a file path.

As said, the is_ignored function cannot always decide whether
the given path is a file or directory, and thus it may produce
wrong results in some cases. While this is unfixable in the
general case, we can do better when we are being passed a path
name with a trailing path separator (e.g. "dir/") and always
treat them as directories.


Fixes #5037

The function `git_ignore_path_is_ignored` is there to test the
ignore status of paths that need not necessarily exist inside of
a repository. This has the implication that for a given path, we
cannot always decide whether it references a directory or a file,
and we need to distinguish those cases because ignore rules may
treat those differently. E.g. given the following gitignore file:

    *
    !/**/

we'd only want to unignore directories, while keeping files
ignored. But still, calling `git_ignore_path_is_ignored("dir/")`
will say that this directory is ignored because it treats "dir/"
as a file path.

As said, the `is_ignored` function cannot always decide whether
the given path is a file or directory, and thus it may produce
wrong results in some cases. While this is unfixable in the
general case, we can do better when we are being passed a path
name with a trailing path separator (e.g. "dir/") and always
treat them as directories.
@ethomson
Copy link
Copy Markdown
Member

ethomson commented Apr 7, 2019

Nice work, @pks-t.

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

Successfully merging this pull request may close these issues.

.gitignore syntax with cascaded rules fail

2 participants