Skip to content

Commit

Permalink
Git - add exception handling to handle edge cases (microsoft#221268)
Browse files Browse the repository at this point in the history
  • Loading branch information
lszomoru authored Jul 9, 2024
1 parent bc40ad6 commit f1e16e1
Showing 1 changed file with 26 additions and 21 deletions.
47 changes: 26 additions & 21 deletions extensions/git/src/historyProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -145,29 +145,34 @@ export class GitHistoryProvider implements SourceControlHistoryProvider, FileDec
return [];
}

// Get the commits
const commits = await this.repository.log({ range: `${refsMergeBase}^..`, refNames });

await ensureEmojis();

const historyItems: SourceControlHistoryItem[] = [];
historyItems.push(...commits.map(commit => {
const newLineIndex = commit.message.indexOf('\n');
const subject = newLineIndex !== -1 ? commit.message.substring(0, newLineIndex) : commit.message;

const labels = this.resolveHistoryItemLabels(commit, refNames);

return {
id: commit.hash,
parentIds: commit.parents,
message: emojify(subject),
author: commit.authorName,
icon: new ThemeIcon('git-commit'),
timestamp: commit.authorDate?.getTime(),
statistics: commit.shortStat ?? { files: 0, insertions: 0, deletions: 0 },
labels: labels.length !== 0 ? labels : undefined
};
}));
try {
// Get the commits
const commits = await this.repository.log({ range: `${refsMergeBase}^..`, refNames });

await ensureEmojis();

historyItems.push(...commits.map(commit => {
const newLineIndex = commit.message.indexOf('\n');
const subject = newLineIndex !== -1 ? commit.message.substring(0, newLineIndex) : commit.message;

const labels = this.resolveHistoryItemLabels(commit, refNames);

return {
id: commit.hash,
parentIds: commit.parents,
message: emojify(subject),
author: commit.authorName,
icon: new ThemeIcon('git-commit'),
timestamp: commit.authorDate?.getTime(),
statistics: commit.shortStat ?? { files: 0, insertions: 0, deletions: 0 },
labels: labels.length !== 0 ? labels : undefined
};
}));
} catch (err) {
this.logger.error(`[GitHistoryProvider][provideHistoryItems2] Failed to get history items '${refsMergeBase}^..': ${err}`);
}

return historyItems;
}
Expand Down

0 comments on commit f1e16e1

Please sign in to comment.