| @@ -66,6 +66,23 @@ public sealed class GitOptions |
| 66 |
66 |
|
| 67 |
67 |
public sealed partial class GitService(IOptions<GitOptions> options, ILogger<GitService> logger) |
| 68 |
68 |
{ |
|
69 |
+ static GitService() |
|
70 |
+ { |
|
71 |
+ |
|
72 |
+ |
|
73 |
+ |
|
74 |
+ |
|
75 |
+ |
|
76 |
+ |
|
77 |
+ |
|
78 |
+ |
|
79 |
+ |
|
80 |
+ |
|
81 |
+ |
|
82 |
+ |
|
83 |
+ GlobalSettings.SetOwnerValidation(false); |
|
84 |
+ } |
|
85 |
+ |
| 69 |
86 |
private readonly GitOptions _options = options.Value; |
| 70 |
87 |
|
| 71 |
88 |
|
| @@ -87,6 +104,7 @@ public sealed partial class GitService(IOptions<GitOptions> options, ILogger<Git |
| 87 |
104 |
} |
| 88 |
105 |
|
| 89 |
106 |
var found = new List<GitRepoSummary>(); |
|
107 |
+ var candidates = 0; |
| 90 |
108 |
|
| 91 |
109 |
try |
| 92 |
110 |
{ |
| @@ -95,6 +113,8 @@ public sealed partial class GitService(IOptions<GitOptions> options, ILogger<Git |
| 95 |
113 |
var name = Path.GetFileName(directory); |
| 96 |
114 |
if (!IsRepositoryName(name)) continue; |
| 97 |
115 |
|
|
116 |
+ candidates++; |
|
117 |
+ |
| 98 |
118 |
try |
| 99 |
119 |
{ |
| 100 |
120 |
using var repository = Open(directory); |
| @@ -116,6 +136,25 @@ public sealed partial class GitService(IOptions<GitOptions> options, ILogger<Git |
| 116 |
136 |
return new GitIndexView([], $"{Root} cannot be read by the user this site runs as."); |
| 117 |
137 |
} |
| 118 |
138 |
|
|
139 |
+ if (found.Count == 0 && candidates > 0) |
|
140 |
+ { |
|
141 |
+ |
|
142 |
+ |
|
143 |
+ |
|
144 |
+ |
|
145 |
+ |
|
146 |
+ logger.LogWarning( |
|
147 |
+ "None of the {Candidates} directories under {Root} could be opened as a repository", |
|
148 |
+ candidates, |
|
149 |
+ Root); |
|
150 |
+ |
|
151 |
+ return new GitIndexView( |
|
152 |
+ [], |
|
153 |
+ $"Nothing under {Root} could be opened as a repository, though there " |
|
154 |
+ + $"{(candidates == 1 ? "is 1 directory" : $"are {candidates} directories")} there. " |
|
155 |
+ + "The user this site runs as most likely cannot read into them."); |
|
156 |
+ } |
|
157 |
+ |
| 119 |
158 |
return new GitIndexView( |
| 120 |
159 |
found.OrderBy(repository => repository.DisplayName, StringComparer.OrdinalIgnoreCase).ToArray(), |
| 121 |
160 |
null); |
| @@ -279,12 +318,26 @@ public sealed partial class GitService(IOptions<GitOptions> options, ILogger<Git |
| 279 |
318 |
|
| 280 |
319 |
|
| 281 |
320 |
|
| 282 |
|
- private static Repository? Open(string directory) |
|
321 |
+ private Repository? Open(string directory) |
| 283 |
322 |
{ |
| 284 |
323 |
if (Repository.IsValid(directory)) return new Repository(directory); |
| 285 |
324 |
|
| 286 |
325 |
var dotGit = Path.Combine(directory, ".git"); |
| 287 |
|
- return Repository.IsValid(dotGit) ? new Repository(dotGit) : null; |
|
326 |
+ if (Repository.IsValid(dotGit)) return new Repository(dotGit); |
|
327 |
+ |
|
328 |
+ |
|
329 |
+ |
|
330 |
+ |
|
331 |
+ |
|
332 |
+ if (File.Exists(Path.Combine(directory, "HEAD")) && Directory.Exists(Path.Combine(directory, "objects"))) |
|
333 |
+ { |
|
334 |
+ logger.LogWarning( |
|
335 |
+ "{Directory} looks like a bare repository, but libgit2 will not open it. Check that " |
|
336 |
+ + "the user this site runs as can read it", |
|
337 |
+ directory); |
|
338 |
+ } |
|
339 |
+ |
|
340 |
+ return null; |
| 288 |
341 |
} |
| 289 |
342 |
|
| 290 |
343 |
private GitRepoSummary Summarise(Repository repository, string name) |