fix(git): Remove Files.isHidden guard in AddExcludedFilesToIndex::prepare#346
Open
ytausch wants to merge 1 commit into
Open
fix(git): Remove Files.isHidden guard in AddExcludedFilesToIndex::prepare#346ytausch wants to merge 1 commit into
Files.isHidden guard in AddExcludedFilesToIndex::prepare#346ytausch wants to merge 1 commit into
Conversation
…prepare`
The goal of prepare() is to prepare a TreeSet<Path> `toExclude` which covers a set of arguments to pass to `git add` that cover all *destination-only* files in HEAD, without sweeping in any origin-owned file.
A check in line 73 defensively influences the algorithm to not assume that a `git add dir` also adds `dir/.file`, which is indicated in a surrounding comment.
Therefore, in a minimal example, where `tools` is destination-owned and contains `tools/.keep` and `tools/script.sh`, we would end up with `toExclude = {tools/.keep, tools/script.sh}`.
However, git does not behave like indicated and a `git add dir` also adds any hidden subdirectories or files. Thus, it would be sufficient to run `git add tools` in the example above and not `git add tools/.keep tools/script.sh`. The code is overdefensive.
The reason why I am fixing this is that, also, `Files.isHidden(relative)` is broken on Windows: While on POSIX, `isHidden` simply checks if the basename starts with a dot, it checks a filesystem attribute. However, since the file path is relative, this happens relative to the current working directory of the JVM, which is not the checked-out repository. This issue could alternatively be resolved by resolving the file path first, but removing the `isHidden` check is the correct fix.
5 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The goal of prepare() is to prepare a TreeSet
toExcludewhich covers a set of arguments to pass togit addthat cover all destination-only files in HEAD, without sweeping in any origin-owned file.A check in line 73 defensively influences the algorithm to not assume that a
git add diralso addsdir/.file, which is indicated in a surrounding comment:copybara/java/com/google/copybara/git/AddExcludedFilesToIndex.java
Lines 73 to 76 in f4f4f79
Therefore, in a minimal example, where
toolsis destination-owned and containstools/.keepandtools/script.sh, we would end up withtoExclude = {tools/.keep, tools/script.sh}.However, git does not behave like indicated and a
git add diralso adds any hidden subdirectories or files. Thus, it would be sufficient to rungit add toolsin the example above and notgit add tools/.keep tools/script.sh. The code is overdefensive.Therefore, this PR removes the
isHiddencheck.The reason why I am fixing this is that, also,
Files.isHidden(relative)is broken on Windows: While on POSIX,isHiddensimply checks if the basename starts with a dot, it checks a filesystem attribute on Windows. However, since the file path is relative, this happens relative to the current working directory of the JVM, which is not the checked-out repository. This issue could alternatively be fixed by resolving the file path first, but removing theisHiddencheck is the correct fix.Testing
I added a regression test, but I am not sure whether you run the CI on Windows as well. I still think it makes sense to keep.