Skip to content

Commit dd82de0

Browse files
committed
Fixes more detached head state issues
1 parent c8d5480 commit dd82de0

File tree

4 files changed

+14
-7
lines changed

4 files changed

+14
-7
lines changed

src/git/models/status.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ export interface GitStatusUpstreamState {
1313
}
1414

1515
export class GitStatus {
16+
readonly detached: boolean;
17+
1618
constructor(
1719
public readonly repoPath: string,
1820
public readonly branch: string,
@@ -21,11 +23,16 @@ export class GitStatus {
2123
public readonly state: GitStatusUpstreamState,
2224
public readonly upstream?: string
2325
) {
24-
if (GitBranch.isDetached(branch)) {
26+
this.detached = GitBranch.isDetached(branch);
27+
if (this.detached) {
2528
this.branch = GitBranch.formatDetached(this.sha);
2629
}
2730
}
2831

32+
get ref() {
33+
return this.detached ? this.sha : this.branch;
34+
}
35+
2936
private _diff?: {
3037
added: number;
3138
deleted: number;

src/quickpicks/repoStatusQuickPick.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -391,9 +391,9 @@ export class RepoStatusQuickPick {
391391
},
392392
Commands.ShowQuickBranchHistory,
393393
[
394-
GitUri.fromRepoPath(status.repoPath, `${status.upstream}..${status.branch}`),
394+
GitUri.fromRepoPath(status.repoPath, `${status.upstream}..${status.ref}`),
395395
{
396-
branch: status.branch,
396+
branch: status.ref,
397397
maxCount: 0,
398398
goBackCommand: currentCommand
399399
} as ShowQuickBranchHistoryCommandArgs
@@ -421,7 +421,7 @@ export class RepoStatusQuickPick {
421421
},
422422
Commands.ShowQuickBranchHistory,
423423
[
424-
GitUri.fromRepoPath(status.repoPath, `${status.branch}..${status.upstream}`),
424+
GitUri.fromRepoPath(status.repoPath, `${status.ref}..${status.upstream}`),
425425
{
426426
branch: status.upstream,
427427
maxCount: 0,

src/views/nodes/statusNode.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ export class StatusNode extends ExplorerNode {
3838
}
3939

4040
if (status.state.ahead || (status.files.length !== 0 && this.includeWorkingTree)) {
41-
const range = status.upstream ? `${status.upstream}..${status.branch}` : undefined;
41+
const range = status.upstream ? `${status.upstream}..${status.ref}` : undefined;
4242
children.push(new StatusFilesNode(status, range, this.explorer, this.active));
4343
}
4444
}

src/views/nodes/statusUpstreamNode.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ export class StatusUpstreamNode extends ExplorerNode {
2525
async getChildren(): Promise<ExplorerNode[]> {
2626
const range =
2727
this.direction === 'ahead'
28-
? `${this.status.upstream}..${this.status.branch}`
29-
: `${this.status.branch}..${this.status.upstream}`;
28+
? `${this.status.upstream}..${this.status.ref}`
29+
: `${this.status.ref}..${this.status.upstream}`;
3030

3131
let log = await Container.git.getLog(this.uri.repoPath!, { maxCount: 0, ref: range });
3232
if (log === undefined) return [];

0 commit comments

Comments
 (0)