This repository was archived by the owner on Mar 3, 2023. It is now read-only.
This repository was archived by the owner on Mar 3, 2023. It is now read-only.
GitRepository getDirectoryStatus mishandles project root directory #9240
Closed
Description
When passed a project root directory, getDirectoryStatus
relativizes the path into a "/". As a result, subsequent checks never match any path, since they do not start with "/". The directory status of the root is always returned as zero.
Here is the current code from git-repository.coffee; note the trailing slash at @relativize
:
getDirectoryStatus: (directoryPath) ->
directoryPath = "#{@relativize(directoryPath)}/"
directoryStatus = 0
for path, status of @statuses
directoryStatus |= status if path.indexOf(directoryPath) is 0
directoryStatus
Suggestions:
- Change this so that
directoryStatus
is correctly calculated when given the project root - For performance consider using
.startsWith()
or.lastIndexOf(str, 0)
for path comparison so that entire strings are not compared - Consider early exit from the loop if the maximum possible value of
directoryStatus
is reached and logical OR of more bits won't change things (not sure what the maximum is)
Motivation for change and references:
Highlight git changes on the level of a project
atom/tree-view#564
getDirectoryStatus
code
https://github.com/atom/atom/blob/master/src/git-repository.coffee#L305
String prefix
http://stackoverflow.com/questions/646628/how-to-check-if-a-string-startswith-another-string#4579228
Activity
stale commentedon Aug 29, 2017
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
lock commentedon Mar 30, 2018
This issue has been automatically locked since there has not been any recent activity after it was closed. If you can still reproduce this issue in Safe Mode then please open a new issue and fill out the entire issue template to ensure that we have enough information to address your issue. Thanks!