Skip to content

Commit cfc04dc

Browse files
authored
Git - read the HEAD of each worktree (microsoft#257532)
1 parent 618daea commit cfc04dc

File tree

1 file changed

+13
-5
lines changed

1 file changed

+13
-5
lines changed

extensions/git/src/git.ts

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -867,6 +867,7 @@ export class GitStatusParser {
867867
export interface Worktree {
868868
readonly name: string;
869869
readonly path: string;
870+
readonly ref: string;
870871
}
871872

872873
export interface Submodule {
@@ -2805,13 +2806,20 @@ export class Repository {
28052806
continue;
28062807
}
28072808

2808-
const gitdirPath = path.join(worktreesPath, dirent.name, 'gitdir');
2809-
28102809
try {
2810+
const headPath = path.join(worktreesPath, dirent.name, 'HEAD');
2811+
const headContent = (await fs.readFile(headPath, 'utf8')).trim();
2812+
2813+
const gitdirPath = path.join(worktreesPath, dirent.name, 'gitdir');
28112814
const gitdirContent = (await fs.readFile(gitdirPath, 'utf8')).trim();
2812-
// Remove trailing '/.git'
2813-
const gitdirTrimmed = gitdirContent.replace(/\.git.*$/, '');
2814-
result.push({ name: dirent.name, path: gitdirTrimmed });
2815+
2816+
result.push({
2817+
name: dirent.name,
2818+
// Remove '/.git' suffix
2819+
path: gitdirContent.replace(/\.git.*$/, ''),
2820+
// Remove 'ref: ' prefix
2821+
ref: headContent.replace(/^ref: /, ''),
2822+
});
28152823
} catch (err) {
28162824
if (/ENOENT/.test(err.message)) {
28172825
continue;

0 commit comments

Comments
 (0)