Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 18 additions & 7 deletions LibGit2Sharp/Configuration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -344,16 +344,27 @@ internal Signature BuildSignature(DateTimeOffset now, bool shouldThrowIfNotFound
var name = Get<string>("user.name");
var email = Get<string>("user.email");

if (shouldThrowIfNotFound && ((name == null) || (email == null)))
if (shouldThrowIfNotFound)
{
throw new LibGit2SharpException("Can not find Name or Email setting of the current user in Git configuration.");
if (name == null || string.IsNullOrEmpty(name.Value))
{
throw new LibGit2SharpException(
"Can not find Name setting of the current user in Git configuration.");
}

if (email == null || string.IsNullOrEmpty(email.Value))
{
throw new LibGit2SharpException(
"Can not find Email setting of the current user in Git configuration.");
}
}

return new Signature(
name != null ? name.Value : "unknown",
email != null ? email.Value : string.Format(
CultureInfo.InvariantCulture, "{0}@{1}", Environment.UserName, Environment.UserDomainName),
now);
var nameForSignature = name == null || string.IsNullOrEmpty(name.Value) ? "unknown" : name.Value;
var emailForSignature = email == null || string.IsNullOrEmpty(email.Value)
? string.Format("{0}@{1}", Environment.UserName, Environment.UserDomainName)
: email.Value;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We've already made sure that neither the name or email are null or empty. Shouldn't we get rid of the null handling here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All the null/empty value handling is within the if (shouldThrowIfNotFound) block. When that flag is turned off, the code you highlighted should still fall back to the defaults in case of null/empty values in settings.


return new Signature(nameForSignature, emailForSignature, now);
}

private ConfigurationSafeHandle Snapshot()
Expand Down