Skip to content

Commit f1e16e1

Browse files
authored
Git - add exception handling to handle edge cases (microsoft#221268)
1 parent bc40ad6 commit f1e16e1

File tree

1 file changed

+26
-21
lines changed

1 file changed

+26
-21
lines changed

Diff for: extensions/git/src/historyProvider.ts

+26-21
Original file line numberDiff line numberDiff line change
@@ -145,29 +145,34 @@ export class GitHistoryProvider implements SourceControlHistoryProvider, FileDec
145145
return [];
146146
}
147147

148-
// Get the commits
149-
const commits = await this.repository.log({ range: `${refsMergeBase}^..`, refNames });
150-
151-
await ensureEmojis();
152-
153148
const historyItems: SourceControlHistoryItem[] = [];
154-
historyItems.push(...commits.map(commit => {
155-
const newLineIndex = commit.message.indexOf('\n');
156-
const subject = newLineIndex !== -1 ? commit.message.substring(0, newLineIndex) : commit.message;
157-
158-
const labels = this.resolveHistoryItemLabels(commit, refNames);
159149

160-
return {
161-
id: commit.hash,
162-
parentIds: commit.parents,
163-
message: emojify(subject),
164-
author: commit.authorName,
165-
icon: new ThemeIcon('git-commit'),
166-
timestamp: commit.authorDate?.getTime(),
167-
statistics: commit.shortStat ?? { files: 0, insertions: 0, deletions: 0 },
168-
labels: labels.length !== 0 ? labels : undefined
169-
};
170-
}));
150+
try {
151+
// Get the commits
152+
const commits = await this.repository.log({ range: `${refsMergeBase}^..`, refNames });
153+
154+
await ensureEmojis();
155+
156+
historyItems.push(...commits.map(commit => {
157+
const newLineIndex = commit.message.indexOf('\n');
158+
const subject = newLineIndex !== -1 ? commit.message.substring(0, newLineIndex) : commit.message;
159+
160+
const labels = this.resolveHistoryItemLabels(commit, refNames);
161+
162+
return {
163+
id: commit.hash,
164+
parentIds: commit.parents,
165+
message: emojify(subject),
166+
author: commit.authorName,
167+
icon: new ThemeIcon('git-commit'),
168+
timestamp: commit.authorDate?.getTime(),
169+
statistics: commit.shortStat ?? { files: 0, insertions: 0, deletions: 0 },
170+
labels: labels.length !== 0 ? labels : undefined
171+
};
172+
}));
173+
} catch (err) {
174+
this.logger.error(`[GitHistoryProvider][provideHistoryItems2] Failed to get history items '${refsMergeBase}^..': ${err}`);
175+
}
171176

172177
return historyItems;
173178
}

0 commit comments

Comments
 (0)