Skip to content

Commit f3a6b7e

Browse files
committed
Make BuildSignature() throw a descriptive message
When global user.name or user.email is set to an empty value, it will now throw a LibGit2SharpException with proper explanatory message. Previously it would throw an ArgumentException with obscure message: "String cannot be empty\nParameter name: name".
1 parent f60ef6a commit f3a6b7e

File tree

1 file changed

+18
-7
lines changed

1 file changed

+18
-7
lines changed

LibGit2Sharp/Configuration.cs

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -344,16 +344,27 @@ internal Signature BuildSignature(DateTimeOffset now, bool shouldThrowIfNotFound
344344
var name = Get<string>("user.name");
345345
var email = Get<string>("user.email");
346346

347-
if (shouldThrowIfNotFound && ((name == null) || (email == null)))
347+
if (shouldThrowIfNotFound)
348348
{
349-
throw new LibGit2SharpException("Can not find Name or Email setting of the current user in Git configuration.");
349+
if (name == null || string.IsNullOrEmpty(name.Value))
350+
{
351+
throw new LibGit2SharpException(
352+
"Can not find Name setting of the current user in Git configuration.");
353+
}
354+
355+
if (email == null || string.IsNullOrEmpty(email.Value))
356+
{
357+
throw new LibGit2SharpException(
358+
"Can not find Email setting of the current user in Git configuration.");
359+
}
350360
}
351361

352-
return new Signature(
353-
name != null ? name.Value : "unknown",
354-
email != null ? email.Value : string.Format(
355-
CultureInfo.InvariantCulture, "{0}@{1}", Environment.UserName, Environment.UserDomainName),
356-
now);
362+
var nameForSignature = name == null || string.IsNullOrEmpty(name.Value) ? "unknown" : name.Value;
363+
var emailForSignature = email == null || string.IsNullOrEmpty(email.Value)
364+
? string.Format("{0}@{1}", Environment.UserName, Environment.UserDomainName)
365+
: email.Value;
366+
367+
return new Signature(nameForSignature, emailForSignature, now);
357368
}
358369

359370
private ConfigurationSafeHandle Snapshot()

0 commit comments

Comments
 (0)