Skip to content

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:

  1. In current_branch.js provider we call workspace_service.ts.getCurrentWorkspaceFolder()
  2. In multi-root project, without an open editor, this method returns undefined as the workspaceFolder
  3. We pass undefined as a workspaceFolder to GitService
  4. When GitService executes the git command, the undefined workspaceFodler causes the command to be run in the same folder as the extension host process
  5. 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)

Edited by Tomas Vik (OOO back on 2024-11-19)

Merge request reports

Loading