Home > other >  Use cake to perform git commit without name and email
Use cake to perform git commit without name and email

Time:08-12

The cake GitCommit alias wants a name and email:

public static GitCommit GitCommit(this ICakeContext context, DirectoryPath repositoryDirectoryPath, string name, string email, string message)

How can I commit without specifying them (and it would use the repo's defaults)?

For example, the same as I can do in the shell: $ git commit -m message.

CodePudding user response:

I found a reasonable workaround:

var name  = GitConfigGet<string>(repoDirectory, "user.name"));
var email = GitConfigGet<string>(repoDirectory, "user.email");

GitCommit(repoDirectory, name, email, "message");

CodePudding user response:

The git cli does a lot a of things other clients might or might not do.

Cake.Git uses libgit2sharp to provide access to git. libgit2sharp, in turn, uses libgit2.

libgit2 requires a username and email to be explicitly specified when adding a commit and so does Cake.Git.

You can, as you wrote in your answer, check the config for existing values, but I would strongly suggest checking them not to be empty, before using them.

  • Related