Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Source Control menu showing wrong branches of worktrees contained in bare repository #164363

Closed
iferc opened this issue Oct 23, 2022 · 14 comments
Closed
Assignees
Labels
bug Issue identified by VS Code Team member as probable bug candidate Issue identified as probable candidate for fixing in the next release git GIT issues verified Verification succeeded

Comments

@iferc
Copy link

iferc commented Oct 23, 2022

Does this issue occur when all extensions are disabled?: Yes

  • VS Code Version: 1.73.0-insider
  • OS Version: MacOS 12.4

Steps to Reproduce:

  1. Clone a bare repository. (ex: git clone --bare git@github.com:microsoft/vscode.git)
  2. Go into the directory of the cloned bare repository. (ex: cd vscode.git)
  3. Create a trees folder in the bare repository folder. (ex: mkdir trees)
  4. Add a worktree for multiple valid branches (ex: git worktree add trees/1.70 release/1.70; git worktree add trees/1.71 release/1.71; git worktree add trees/1.72 release/1.72)
  5. Add the folders trees/1.70, trees/1.71, and trees/1.72 to a VSCode workspace.
  6. Open the Source Control menu.
  7. See that each each worktree folder shows up as a distinct repository, but that they all show the primary branch as though it were the branch that is checked out instead of their actual checked out branch. (ex: all would be main but should be release/1.70, release/1.71, and release/1.72)

Screenshot included is from the example instructions above where none of these folders have main checked out, yet all show main as their checked out branch:

Screen Shot 2022-10-23 at 2 35 28 AM

I can confirm that the correct branch names were displayed at least as of 1.70.2 but I have not yet tried more versions in-between.

@lszomoru lszomoru added bug Issue identified by VS Code Team member as probable bug git GIT issues labels Oct 24, 2022
@jarrodldavis
Copy link

I'm having the same issue with a non-bare repository. I have an additional worktree and today's VSCode update is showing the checked out branch of the main worktree instead of the current directory's worktree. This worked fine in v1.72, and is now broken in v1.73. This also messes up the GitHub Pull Requests extension since it is using the wrong branch to get PR information.

@bluemonkmn
Copy link

This was working correctly in the prior version, but today when I applied the newly available v1.73 I am seeing this problem is all my secondary worktrees.

@jarrodldavis
Copy link

This appears to be caused by #162572, specifically here where it's getting the HEAD branch from the filesystem (instead of using git commands):

const raw = await fs.readFile(path.join(this.dotGit.commonPath ?? this.dotGit.path, 'HEAD'), 'utf8');

this.dotGit.commonPath seems to refer to the main worktree's .git path, and this.dotGit.path is the current working directory's .git path. This should be checking path before commonPath:

diff --git a/extensions/git/src/git.ts b/extensions/git/src/git.ts
index 7c49b545f8c..1538a356a31 100644
--- a/extensions/git/src/git.ts
+++ b/extensions/git/src/git.ts
@@ -2083,7 +2083,7 @@ export class Repository {
 	}
 
 	async getHEADFS(): Promise<Ref> {
-		const raw = await fs.readFile(path.join(this.dotGit.commonPath ?? this.dotGit.path, 'HEAD'), 'utf8');
+		const raw = await fs.readFile(path.join(this.dotGit.path ?? this.dotGit.commonPath, 'HEAD'), 'utf8');
 
 		// Branch
 		const branchMatch = raw.match(/^ref: refs\/heads\/(?<name>.*)$/m);

@Patrick-Ze
Copy link

Patrick-Ze commented Nov 3, 2022

I have the same problem with VS Code 1.73.0. This issue also breaks GitLab extension since it gets wrong branch. I downgrad to 1.72.2 to avoid this issue temporarily. If anyone needs it, the download link is:
https://update.code.visualstudio.com/1.72.2/win32-x64-archive/stable

@lszomoru lszomoru added the candidate Issue identified as probable candidate for fixing in the next release label Nov 4, 2022
@brainz80
Copy link

brainz80 commented Nov 4, 2022

Can the builtin extensions be updated independently from updating vscode? In that case this shouldn't be hard to fix.

@lszomoru
Copy link
Member

lszomoru commented Nov 4, 2022

@brainz80, it cannot. I am looking at having this fixed in Insiders early next week.

@crossan007
Copy link

I'm having this same issue in 1.73.0 (user setup).

I've got 3 repositories each having 4 active git-worktrees in a multi-root workspace, and each worktree seems to indicate the same checked out branch.

@jportner
Copy link

jportner commented Nov 4, 2022

I'm also having a problem in 1.73.0 that appears to be the same root cause.
I have a single repo with three working trees checked out, and VS Code always thinks that I'm on the primary working trees.

This is causing problems for the GitHub Pull Requests and Issues extension (I can only review PRs when using the primary working tree).

@f4n0
Copy link

f4n0 commented Nov 4, 2022

yep, me too!

@dmy147
Copy link

dmy147 commented Nov 5, 2022

same issue

@vscodenpa vscodenpa added the unreleased Patch has not yet been released in VS Code Insiders label Nov 5, 2022
@vscodenpa vscodenpa added this to the November 2022 milestone Nov 5, 2022
@lszomoru lszomoru reopened this Nov 5, 2022
@vscodenpa vscodenpa removed the unreleased Patch has not yet been released in VS Code Insiders label Nov 5, 2022
@lszomoru
Copy link
Member

lszomoru commented Nov 5, 2022

The fix will be included into Monday's Insiders release. Apologies for the inconvenience.

@iferc
Copy link
Author

iferc commented Nov 5, 2022

I appreciate the quick fix! Thank you.

@SimonHarrisonSH
Copy link

@lszomoru Any idea when this will be in the regular release? I'd rather not have to switch to the insiders build.

@lszomoru
Copy link
Member

lszomoru commented Nov 9, 2022

Verification steps:

mkdir main && cd main
git init .
echo a >> a
git commit . -m 'init'
git worktree add -b dev ../dev # important!
code ../dev

Expected: VS Code status indicator should show dev as the branch name

@hediet hediet added the verified Verification succeeded label Nov 9, 2022
@github-actions github-actions bot locked and limited conversation to collaborators Dec 24, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Issue identified by VS Code Team member as probable bug candidate Issue identified as probable candidate for fixing in the next release git GIT issues verified Verification succeeded
Projects
None yet
Development

No branches or pull requests