diff --git a/packages/scm-extra/src/browser/history/scm-history-widget.tsx b/packages/scm-extra/src/browser/history/scm-history-widget.tsx index 9b8cd820bd804..3b96c26e409b9 100644 --- a/packages/scm-extra/src/browser/history/scm-history-widget.tsx +++ b/packages/scm-extra/src/browser/history/scm-history-widget.tsx @@ -220,20 +220,30 @@ export class ScmHistoryWidget extends ScmNavigableListWidget if (this.historySupport) { try { const currentCommits = this.status.state === 'ready' ? this.status.commits : []; + const historyOptions = { ...options }; - let sourceHistory = await this.historySupport.getCommitHistory(options); + // if we already have commits, get the latest one plus one more, we need at least one entry, otherwise an error is thrown + // when fetching the log + if (currentCommits.length > 1) { + historyOptions.range = { fromRevision: currentCommits[1].commitDetails.id, toRevision: 'HEAD' }; + } + + const history = await this.historySupport.getCommitHistory(historyOptions); if (token.isCancellationRequested || !this.hasMoreCommits) { return; } - if (options && ((options.maxCount && sourceHistory.length < options.maxCount) || (!options.maxCount && currentCommits))) { + if (options && ((options.maxCount && history.length < options.maxCount) || (!options.maxCount && currentCommits))) { this.hasMoreCommits = false; } + + // remove the extra commit if (currentCommits.length > 0) { - sourceHistory = sourceHistory.slice(1); + history.pop(); } + const commits: ScmCommitNode[] = []; - for (const commit of sourceHistory) { + for (const commit of history) { const fileChangeNodes: ScmFileChangeNode[] = []; await Promise.all(commit.fileChanges.map(async fileChange => { fileChangeNodes.push({ @@ -250,7 +260,7 @@ export class ScmHistoryWidget extends ScmNavigableListWidget selected: false }); } - currentCommits.push(...commits); + currentCommits.unshift(...commits); this.status = { state: 'ready', commits: currentCommits }; } catch (error) { if (options && options.uri && repository) {