Skip to content

Commit

Permalink
Git - add exception handling to handle edge cases (#221254)
Browse files Browse the repository at this point in the history
  • Loading branch information
lszomoru authored Jul 9, 2024
1 parent 1710635 commit fc8ade9
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, shortStats: true });

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, shortStats: true });

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 fc8ade9

Please sign in to comment.