Skip to content

Commit e3108d4

Browse files
committed
Publicize Configuration.BuildSignature()
1 parent 4f4819e commit e3108d4

File tree

4 files changed

+28
-6
lines changed

4 files changed

+28
-6
lines changed

LibGit2Sharp/Configuration.cs

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -308,7 +308,29 @@ private static ConfigurationEntry<string> BuildConfigEntry(IntPtr entryPtr)
308308
(ConfigurationLevel)entry.level);
309309
}
310310

311-
internal Signature BuildSignatureFromGlobalConfiguration(DateTimeOffset now, bool shouldThrowIfNotFound)
311+
/// <summary>
312+
/// Builds a <see cref="Signature"/> based on current configuration.
313+
/// <para>
314+
/// Name is populated from the user.name setting, and is "unknown" if unspecified.
315+
/// Email is populated from the user.email setting, and is built from
316+
/// <see cref="Environment.UserName"/> and <see cref="Environment.UserDomainName"/> if unspecified.
317+
/// </para>
318+
/// <para>
319+
/// The same escalation logic than in git.git will be used when looking for the key in the config files:
320+
/// - local: the Git file in the current repository
321+
/// - global: the Git file specific to the current interactive user (usually in `$HOME/.gitconfig`)
322+
/// - xdg: another Git file specific to the current interactive user (usually in `$HOME/.config/git/config`)
323+
/// - system: the system-wide Git file
324+
/// </para>
325+
/// </summary>
326+
/// <param name="now">The timestamp to use for the <see cref="Signature"/>.</param>
327+
/// <returns>The signature.</returns>
328+
public virtual Signature BuildSignature(DateTimeOffset now)
329+
{
330+
return BuildSignature(now, false);
331+
}
332+
333+
internal Signature BuildSignature(DateTimeOffset now, bool shouldThrowIfNotFound)
312334
{
313335
var name = Get<string>("user.name");
314336
var email = Get<string>("user.email");

LibGit2Sharp/NoteCollectionExtensions.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ public static class NoteCollectionExtensions
1818
/// <returns>The note which was just saved.</returns>
1919
public static Note Add(this NoteCollection collection, ObjectId targetId, string message, string @namespace)
2020
{
21-
Signature author = collection.repo.Config.BuildSignatureFromGlobalConfiguration(DateTimeOffset.Now, true);
21+
Signature author = collection.repo.Config.BuildSignature(DateTimeOffset.Now, true);
2222

2323
return collection.Add(targetId, message, author, author, @namespace);
2424
}
@@ -32,7 +32,7 @@ public static Note Add(this NoteCollection collection, ObjectId targetId, string
3232
/// <param name="namespace">The namespace on which the note will be removed. It can be either a canonical namespace or an abbreviated namespace ('refs/notes/myNamespace' or just 'myNamespace').</param>
3333
public static void Remove(this NoteCollection collection, ObjectId targetId, string @namespace)
3434
{
35-
Signature author = collection.repo.Config.BuildSignatureFromGlobalConfiguration(DateTimeOffset.Now, true);
35+
Signature author = collection.repo.Config.BuildSignature(DateTimeOffset.Now, true);
3636

3737
collection.Remove(targetId, author, author, @namespace);
3838
}

LibGit2Sharp/ReflogCollection.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ internal virtual void Append(ObjectId target, string reflogMessage, Signature co
126126
/// <param name="reflogMessage">the message associated with the new <see cref="ReflogEntry"/>.</param>
127127
internal void Append(ObjectId target, string reflogMessage)
128128
{
129-
Signature author = repo.Config.BuildSignatureFromGlobalConfiguration(DateTimeOffset.Now, false);
129+
Signature author = repo.Config.BuildSignature(DateTimeOffset.Now, false);
130130
Append(target, reflogMessage, author);
131131
}
132132
}

LibGit2Sharp/RepositoryExtensions.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ private static Commit LookUpCommit(IRepository repository, string committish)
212212
/// <returns>The generated <see cref="LibGit2Sharp.Commit"/>.</returns>
213213
public static Commit Commit(this IRepository repository, string message, bool amendPreviousCommit = false)
214214
{
215-
Signature author = repository.Config.BuildSignatureFromGlobalConfiguration(DateTimeOffset.Now, true);
215+
Signature author = repository.Config.BuildSignature(DateTimeOffset.Now, true);
216216

217217
return repository.Commit(message, author, amendPreviousCommit);
218218
}
@@ -230,7 +230,7 @@ public static Commit Commit(this IRepository repository, string message, bool am
230230
/// <returns>The generated <see cref="LibGit2Sharp.Commit"/>.</returns>
231231
public static Commit Commit(this IRepository repository, string message, Signature author, bool amendPreviousCommit = false)
232232
{
233-
Signature committer = repository.Config.BuildSignatureFromGlobalConfiguration(DateTimeOffset.Now, true);
233+
Signature committer = repository.Config.BuildSignature(DateTimeOffset.Now, true);
234234

235235
return repository.Commit(message, author, committer, amendPreviousCommit);
236236
}

0 commit comments

Comments
 (0)