Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings
Merged
Show file tree
Hide file tree
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
11 changes: 10 additions & 1 deletion 11 lib/repository.js
Original file line number Diff line number Diff line change
Expand Up @@ -539,7 +539,13 @@ Repository.prototype.treeBuilder = function() {
* @return {Signature}
*/
Repository.prototype.defaultSignature = function() {
return NodeGit.Signature.default(this);
var result = NodeGit.Signature.default(this);

if (!result.name()) {
result = NodeGit.Signature.now("unknown", "unknown@unknown.com");
}

return result;
};

/**
Expand Down Expand Up @@ -589,10 +595,12 @@ Repository.prototype.getRemote = function(remote, callback) {
* Fetches from a remote
*
* @param {String|Remote} remote
* @param {Object|RemoteCallback} remoteCallbacks Any custom callbacks needed
*/
Repository.prototype.fetch = function(
remote,
remoteCallbacks,

callback)
{
var repo = this;
Expand All @@ -613,6 +621,7 @@ Repository.prototype.fetch = function(

/**
* Fetches from all remotes
* @param {Object|RemoteCallback} remoteCallbacks Any custom callbacks needed
*/
Repository.prototype.fetchAll = function(
remoteCallbacks,
Expand Down
59 changes: 59 additions & 0 deletions 59 test/tests/signature.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,19 @@
var assert = require("assert");
var path = require("path");
var local = path.join.bind(path, __dirname);
var promisify = require("promisify-node");
var Promise = require("nodegit-promise");

// Have to wrap exec, since it has a weird callback signature.
var exec = promisify(function(command, opts, callback) {
return require("child_process").exec(command, opts, callback);
});

describe("Signature", function() {
var Signature = require(local("../../lib/signature"));
var Repository = require(local("../../lib/repository"));

var reposPath = local("../repos/workdir/.git");

var name = "Bob Gnarley";
var email = "gnarlee@bob.net";
Expand Down Expand Up @@ -33,4 +43,53 @@ describe("Signature", function() {
// libgit2 does its timezone offsets backwards from javascript
assert.equal(when.offset(), -now.getTimezoneOffset());
});

it("can get a default signature when no user name is set", function() {
var savedUserName;
var savedUserEmail;

var cleanUp = function() {
return exec("git config --global user.name \"" + savedUserName + "\"")
.then(function() {
return exec(
"git config --global user.email \"" +
savedUserEmail +
"\"");
});
};

return exec("git config --global user.name")
.then(function(userName) {
savedUserName = userName.trim();

return exec("git config --global user.email");
})
.then(function(userEmail) {
savedUserEmail = userEmail.trim();

return exec("git config --global --unset user.name");
})
.then(function() {
return exec("git config --global --unset user.email");
})
.then(function() {
return Repository.open(reposPath);
})
.then(function(repo) {
var sig = repo.defaultSignature();

assert.equal(sig.name(), "unknown");
assert.equal(sig.email(), "unknown@unknown.com");

})
.then(function() {
cleanUp();
})
.catch(function(e) {
cleanUp()
.then(function() {
return Promise.reject(e);
});
});
});
});
Morty Proxy This is a proxified and sanitized view of the page, visit original site.