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

Ensure that git_index_add_all handles ignored directories #6521

Merged
merged 3 commits into from Mar 3, 2023

Conversation

ethomson
Copy link
Member

@ethomson ethomson commented Mar 2, 2023

When all files beneath a directory are ignored, our diff machinery will return the directory itself. Obviously we do not operate on directories in the index, so git_index_add_all should ignore this case.

Fixes #6517

@@ -3453,6 +3453,13 @@ static int apply_each_file(const git_diff_delta *delta, float progress, void *pa
&match, NULL))
return 0;

/*
* diff returns the directory when all files are ignored; we never
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this behavior of diff intentional?
Filtering out trees in function named apply_each_file looks ... weird.

@georgthegreat
Copy link
Contributor

Unfortunately this does not work as intended.
GIT_INDEX_ADD_FORCE should add ignored files disregarding .gitignore contents.

At the time /folder/asdf is not added to the index (this is what I am seeing in my local executions with this patch applied).

Edward Thomson added 3 commits March 2, 2023 23:09
Ensure that when all files beneath a directory are ignored that we
actually ignore the files.
Ensure that when all files beneath a directory are ignored that we
add the files when FORCE is specified.
When the contents of an entire new directory is ignored, and `FORCE` is
specified to `git_index_add_all`, ensure that we expand the entire file
list. By default, diff will coalesce a fully ignored folder into a
single diff entry; expand it.
@ethomson
Copy link
Member Author

ethomson commented Mar 2, 2023

GIT_INDEX_ADD_FORCE should add ignored files disregarding .gitignore contents.

Ah, yes, thanks. I had it flipped around in my head.

In any case, the problem here is that diff coalesces a folder that has contents that are all ignored into a single diff entry. We need to expand that out to add files to the index. This update should do that.

@georgthegreat
Copy link
Contributor

@ethomson the latest version works for us.
Thanks a lot for the quick fix!

@ethomson ethomson merged commit 8164b48 into main Mar 3, 2023
@ethomson ethomson deleted the ethomson/weird_ignore branch March 3, 2023 21:03
@ethomson ethomson added the bug label Mar 21, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

.gitignore breaks git_index_add_all in certain cases
2 participants