Skip to content
New issue

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

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

Already on GitHub? # to your account

fix scm history going out of sync #71

Merged
merged 2 commits into from
Jun 2, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 15 additions & 5 deletions packages/scm-extra/src/browser/history/scm-history-widget.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -220,20 +220,30 @@ export class ScmHistoryWidget extends ScmNavigableListWidget<ScmHistoryListNode>
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({
Expand All @@ -250,7 +260,7 @@ export class ScmHistoryWidget extends ScmNavigableListWidget<ScmHistoryListNode>
selected: false
});
}
currentCommits.push(...commits);
currentCommits.unshift(...commits);
this.status = { state: 'ready', commits: currentCommits };
} catch (error) {
if (options && options.uri && repository) {
Expand Down