fix(side tree): for current branch not working for multiroot projects
I apologize for this "shotgun surgery" MR. I wasn't able to split the change into multiple commits and so I'll at least provide detailed commentary on the diff itself.
Motivation for the change
I've noticed that when I open a multi-root workspace, the For current branch section in the extension sidebar shows information for completely different project.
After a bit of investigation I found the bug caused by the following sequence of events:
- In
current_branch.js
provider we callworkspace_service.ts
.getCurrentWorkspaceFolder()
- In multi-root project, without an open editor, this method returns
undefined
as theworkspaceFolder
- We pass
undefined
as aworkspaceFolder
toGitService
- When
GitService
executes thegit
command, theundefined
workspaceFodler
causes the command to be run in the same folder as the extension host process - This location is nondeterministic (at least on Mac) and it is equal to the first folder in which we opened VS Code which might belong to a different project.
The "how to reproduce" section of the issue #310 (closed) describes the problem on a high level.
The solution
TS would warn us that the getCurrentWorkspaceFolder()
can return undefined and it wouldn't compile. So I did two things, I added an assert()
on the workspaceFolder
to make sure (during runtime) that this doesn't happen again. I also converted the current_branch
provider to TS. Which uncovered a multitude of other bugs.
Relates to #310 (closed)