dir: fix treat_leading_path() to return false on non-directories #1723
+3
−1
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.
Hi there!
I wanted to provide some extra context on the behavior I'm trying to fix. I noticed in one of my git hook scripts that it was showing a warning error message when running
git status
on a deleted directory. You can reproduce with the following on the git repo:However, this warning doesn't show if you give a non-directory from the root of the repo:
Also doesn't show if you give it a directory in gitignore (
/bin
is int/unit-tests/.gitignore
)I found it strange that sometimes git is able to detect non-directories without warnings. Even stranger, an older version of git didn't show this warning in the first example.
After running
git bisect
, I was able to track down the commit that introduced this behavior: b9670c1 ("dir: fix checks on common prefix directory", 2019-12-19).Before, that change,
!is_directory(sb.buf)
would break out of the loop and return 0 since the branch of code that changesrc
to 1 hasn't been reached yet. The change introduces the conditionalstate == path_recurse
as the new return statement. Thisstate
variable could be from a previous iteration of the loop which is causing this new behavior. The fix is to ensure the is_directory conditional results in the overall method returning false.I'm not sure if this is considered a bug or not since it's just a warning message. If this isn't noteworthy, then feel free to ignore this pull request!