Skip to content
This repository was archived by the owner on Jun 21, 2023. It is now read-only.

Commit d33ec4a

Browse files
committed
Merge pull request #31 from github/shana/23-crash
Make sure we don't crash when VS's git service returns bogus data
2 parents 391151c + bc3d148 commit d33ec4a

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

src/GitHub.VisualStudio/Base/TeamExplorerServiceHolder.cs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,19 @@ async void UIContextChanged(bool active)
125125
{
126126
GitService = GitService ?? ServiceProvider.GetService<IGitExt>();
127127
if (ActiveRepo == null)
128-
ActiveRepo = await System.Threading.Tasks.Task.Run(() => GitService.ActiveRepositories.FirstOrDefault());
128+
ActiveRepo = await System.Threading.Tasks.Task.Run(() =>
129+
{
130+
var repos = GitService?.ActiveRepositories;
131+
// Looks like this might return null after a while, for some unknown reason
132+
// if it does, let's refresh the GitService instance in case something got wonky
133+
// and try again. See issue #23
134+
if (repos == null)
135+
{
136+
GitService = ServiceProvider?.GetService<IGitExt>();
137+
repos = GitService?.ActiveRepositories;
138+
}
139+
return repos?.FirstOrDefault();
140+
});
129141
}
130142
else
131143
ActiveRepo = null;

0 commit comments

Comments
 (0)