Git - update base branch revision when it changes (#237558)

This commit is contained in:
Ladislau Szomoru
2025-01-09 12:47:34 +01:00
committed by GitHub
parent c65a0aba76
commit 744eec9595

View File

@@ -90,7 +90,7 @@ export class GitHistoryProvider implements SourceControlHistoryProvider, FileDec
readonly onDidChangeHistoryItemRefs: Event<SourceControlHistoryItemRefsChangeEvent> = this._onDidChangeHistoryItemRefs.event;
private _HEAD: Branch | undefined;
private historyItemRefs: SourceControlHistoryItemRef[] = [];
private _historyItemRefs: SourceControlHistoryItemRef[] = [];
private historyItemDecorations = new Map<string, FileDecoration>();
@@ -112,6 +112,14 @@ export class GitHistoryProvider implements SourceControlHistoryProvider, FileDec
return;
}
// Refs (alphabetically)
const historyItemRefs = this.repository.refs
.map(ref => toSourceControlHistoryItemRef(this.repository, ref))
.sort((a, b) => a.id.localeCompare(b.id));
const delta = deltaHistoryItemRefs(this._historyItemRefs, historyItemRefs);
this._historyItemRefs = historyItemRefs;
let historyItemRefId = '';
let historyItemRefName = '';
@@ -130,8 +138,9 @@ export class GitHistoryProvider implements SourceControlHistoryProvider, FileDec
icon: new ThemeIcon('cloud')
} : undefined;
// Base - compute only if the branch has changed
// Base
if (this._HEAD?.name !== this.repository.HEAD.name) {
// Compute base if the branch has changed
const mergeBase = await this.resolveHEADMergeBase();
this._currentHistoryItemBaseRef = mergeBase &&
@@ -142,6 +151,17 @@ export class GitHistoryProvider implements SourceControlHistoryProvider, FileDec
revision: mergeBase.commit,
icon: new ThemeIcon('cloud')
} : undefined;
} else {
// Update base revision if it has changed
const mergeBaseModified = delta.modified
.find(ref => ref.id === this._currentHistoryItemBaseRef?.id);
if (this._currentHistoryItemBaseRef && mergeBaseModified) {
this._currentHistoryItemBaseRef = {
...this._currentHistoryItemBaseRef,
revision: mergeBaseModified.revision
};
}
}
} else {
// Detached commit
@@ -178,18 +198,10 @@ export class GitHistoryProvider implements SourceControlHistoryProvider, FileDec
this.logger.trace(`[GitHistoryProvider][onDidRunWriteOperation] currentHistoryItemRemoteRef: ${JSON.stringify(this._currentHistoryItemRemoteRef)}`);
this.logger.trace(`[GitHistoryProvider][onDidRunWriteOperation] currentHistoryItemBaseRef: ${JSON.stringify(this._currentHistoryItemBaseRef)}`);
// Refs (alphabetically)
const historyItemRefs = this.repository.refs
.map(ref => toSourceControlHistoryItemRef(this.repository, ref))
.sort((a, b) => a.id.localeCompare(b.id));
// Auto-fetch
const silent = result.operation.kind === OperationKind.Fetch && result.operation.showProgress === false;
const delta = deltaHistoryItemRefs(this.historyItemRefs, historyItemRefs);
this._onDidChangeHistoryItemRefs.fire({ ...delta, silent });
this.historyItemRefs = historyItemRefs;
const deltaLog = {
added: delta.added.map(ref => ref.id),
modified: delta.modified.map(ref => ref.id),