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

Commit 53a2f89

Browse files
committed
Don't dispose of repo before task completes
1 parent 9002364 commit 53a2f89

File tree

1 file changed

+18
-17
lines changed

1 file changed

+18
-17
lines changed

src/GitHub.Exports/Services/GitService.cs

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -85,30 +85,31 @@ public UriString GetRemoteUri(IRepository repo, string remote = "origin")
8585
public Task<string> GetLatestPushedSha(string path)
8686
{
8787
Guard.ArgumentNotNull(path, nameof(path));
88-
using (var repo = GetRepository(path))
89-
{
90-
if (repo == null)
91-
return null;
9288

93-
if (repo.Head.IsTracking && repo.Head.Tip.Sha == repo.Head.TrackedBranch.Tip.Sha)
94-
{
95-
return Task.FromResult(repo.Head.Tip.Sha);
96-
}
97-
98-
return Task.Factory.StartNew(() =>
89+
return Task.Factory.StartNew(() =>
90+
{
91+
using (var repo = GetRepository(path))
9992
{
100-
var remoteHeads = repo.Refs.Where(r => r.IsRemoteTrackingBranch).ToList();
101-
102-
foreach (var c in repo.Commits)
93+
if (repo != null)
10394
{
104-
if (repo.Refs.ReachableFrom(remoteHeads, new[] { c }).Any())
95+
if (repo.Head.IsTracking && repo.Head.Tip.Sha == repo.Head.TrackedBranch.Tip.Sha)
96+
{
97+
return repo.Head.Tip.Sha;
98+
}
99+
100+
var remoteHeads = repo.Refs.Where(r => r.IsRemoteTrackingBranch).ToList();
101+
foreach (var c in repo.Commits)
105102
{
106-
return c.Sha;
103+
if (repo.Refs.ReachableFrom(remoteHeads, new[] { c }).Any())
104+
{
105+
return c.Sha;
106+
}
107107
}
108108
}
109+
109110
return null;
110-
});
111-
}
111+
}
112+
});
112113
}
113114
}
114115
}

0 commit comments

Comments
 (0)