user3838784
user3838784

Reputation:

Get the user's identity/signature from git configuration in libgit2sharp for committing

How can I get the user's identity and signature using libgit2sharp in order to create commits? The documentation only shows how to create a brand new signature, but I want to use the one the user has already set up using git config.

The documentation page at https://github.com/libgit2/libgit2sharp/wiki/Git-commit only shows how to create a signature, not how to retrieve the user's identity.

// Create the committer's signature and commit
Signature author = new Signature("James", "@jugglingnutcase", DateTime.Now);
Signature committer = author;

// Commit to the repository
Commit commit = repo.Commit("Here's a commit i made!", author, committer);

Upvotes: 4

Views: 2137

Answers (1)

user3838784
user3838784

Reputation:

This is done by using the Configuration object, which you can get from the repository directly:

Configuration config = repo.Config;
Signature author = config.BuildSignature(DateTimeOffset.Now); // or something else if you want to commit at a different time

You can then create the commit the regular way, with repo.Commit(...)

Upvotes: 3

Related Questions