Thanks to visit codestin.com
Credit goes to github.com

Skip to content

ignore: allow unignoring basenames in subdirectories #3895

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

Merged
merged 1 commit into from
Aug 17, 2016

Conversation

pks-t
Copy link
Member

@pks-t pks-t commented Aug 12, 2016

The .gitignore file allows for patterns which unignore previous
ignore patterns. When unignoring a previous pattern, there are
basically three cases how this is matched when no globbing is
used:

  1. when a previous file has been ignored, it can be unignored by
    using its exact name, e.g.

    foo/bar
    !foo/bar

  2. when a file in a subdirectory has been ignored, it can be
    unignored by using its basename, e.g.

    foo/bar
    !bar

  3. when all files with a basename are ignored, a specific file
    can be unignored again by specifying its path in a
    subdirectory, e.g.

    bar
    !foo/bar

The first problem in libgit2 is that we did not correctly treat
the second case. While we verified that the negative pattern
matches the tail of the positive one, we did not verify if it
only matches the basename of the positive pattern. So e.g. we
would have also negated a pattern like

foo/fruz_bar
!bar

Furthermore, we did not check for the third case, where a
basename is being unignored in a certain subdirectory again.

Both issues are fixed with this commit.

@pks-t
Copy link
Member Author

pks-t commented Aug 12, 2016

This should fix #3894

assert_is_ignored("bar.txt");
assert_is_ignored("parent/bar.txt");
refute_is_ignored("parent/child/bar.txt");
assert_is_ignored("other/parent/child/bar.txt");
Copy link

@tgandrews tgandrews Aug 12, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be nested instead of other?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Uhm. Yes. Thanks 👍

The .gitignore file allows for patterns which unignore previous
ignore patterns. When unignoring a previous pattern, there are
basically three cases how this is matched when no globbing is
used:

1. when a previous file has been ignored, it can be unignored by
   using its exact name, e.g.

   foo/bar
   !foo/bar

2. when a file in a subdirectory has been ignored, it can be
   unignored by using its basename, e.g.

   foo/bar
   !bar

3. when all files with a basename are ignored, a specific file
   can be unignored again by specifying its path in a
   subdirectory, e.g.

   bar
   !foo/bar

The first problem in libgit2 is that we did not correctly treat
the second case. While we verified that the negative pattern
matches the tail of the positive one, we did not verify if it
only matches the basename of the positive pattern. So e.g. we
would have also negated a pattern like

    foo/fruz_bar
    !bar

Furthermore, we did not check for the third case, where a
basename is being unignored in a certain subdirectory again.

Both issues are fixed with this commit.
@pks-t pks-t force-pushed the pks/negate-basename-in-subdirs branch from 10fe553 to fcb2c1c Compare August 12, 2016 12:48
@ethomson ethomson merged commit 635a922 into libgit2:master Aug 17, 2016
@pks-t pks-t deleted the pks/negate-basename-in-subdirs branch August 17, 2016 14:05
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.

3 participants