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

Pattern-based exceptions in .gitignore not working #3224

Closed
swisspol opened this issue Jun 16, 2015 · 8 comments
Closed

Pattern-based exceptions in .gitignore not working #3224

swisspol opened this issue Jun 16, 2015 · 8 comments

Comments

@swisspol
Copy link
Contributor

Example case:

*.data
!dont_ignore/*.data

Then add a couple files in the workdir: foo.data and dont_ignore/bar.data.

git_diff_index_to_workdir() will correctly ignore foo.data but incorrectly also ignore dont_ignore/bar.data.

Note that the .gitignore file is working as expected when testing with git status --ignored.

@swisspol swisspol changed the title Exceptions not taken into account in .gitignore Pattern-based exceptions in .gitignore not working Jun 16, 2015
@swisspol
Copy link
Contributor Author

Doing a bit more testing, this exception works: !test.data.

@carlosmn
Copy link
Member

It looks like the *.data rule satisfies the restriction that negation rules must negate an existing pattern.

void test_status_ignore__deeper(void)
{
   int ignored;

    g_repo = cl_git_sandbox_init("empty_standard_repo");

    cl_git_mkfile("empty_standard_repo/.gitignore",
          "*.data\n"
          "!dont_ignore/*.data\n");

    cl_git_pass(p_mkdir("empty_standard_repo/dont_ignore", 0777));
    cl_git_mkfile("empty_standard_repo/foo.data", "");
    cl_git_mkfile("empty_standard_repo/bar.data", "");
    cl_git_mkfile("empty_standard_repo/dont_ignore/foo.data", "");
    cl_git_mkfile("empty_standard_repo/dont_ignore/bar.data", "");

    cl_git_pass(git_ignore_path_is_ignored(&ignored, g_repo, "foo.data"));
    cl_assert_equal_i(1, ignored);
    cl_git_pass(git_ignore_path_is_ignored(&ignored, g_repo, "bar.data"));
    cl_assert_equal_i(1, ignored);

    cl_git_pass(git_ignore_path_is_ignored(&ignored, g_repo, "dont_ignore/foo.data"));
    cl_assert_equal_i(0, ignored);
    cl_git_pass(git_ignore_path_is_ignored(&ignored, g_repo, "dont_ignore/bar.data"));
    cl_assert_equal_i(0, ignored);
}

@fogaztuc
Copy link

Just found this issue as well.

@overboen
Copy link

I believe that there is an issue in the Atom tree-view project that is caused by this via Atom's git-utils' project's dependency on this project. It looks like the project is using v0.24.3 of libgit2.

atom/tree-view#902

@segevfiner
Copy link
Contributor

Not sure if this is the same, but in the CPython repository they have this:

/python
!/Python/

The "Python" directory is ignored by libgit2 but not by Git.

Tested on Windows.

@pks-t
Copy link
Member

pks-t commented Jul 7, 2017

@segevfiner I guess your issue is different, as it is caused by issues with case-insensitivity. It would be very nice if you could create a new issue describing the problem.

@vringar
Copy link
Contributor

vringar commented Apr 13, 2022

This issue should have been closed when #4296 was merged but wasn't

@ethomson
Copy link
Member

Thanks @vringar !

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

No branches or pull requests

8 participants