Skip to content

Commit d440ea1

Browse files
committed
Merge pull request #450 from nodegit/fetch-all-signature
Default signature always returns valid signature
2 parents 617e74e + bd9e893 commit d440ea1

File tree

2 files changed

+69
-1
lines changed

2 files changed

+69
-1
lines changed

lib/repository.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -539,7 +539,13 @@ Repository.prototype.treeBuilder = function() {
539539
* @return {Signature}
540540
*/
541541
Repository.prototype.defaultSignature = function() {
542-
return NodeGit.Signature.default(this);
542+
var result = NodeGit.Signature.default(this);
543+
544+
if (!result.name()) {
545+
result = NodeGit.Signature.now("unknown", "unknown@unknown.com");
546+
}
547+
548+
return result;
543549
};
544550

545551
/**
@@ -589,10 +595,12 @@ Repository.prototype.getRemote = function(remote, callback) {
589595
* Fetches from a remote
590596
*
591597
* @param {String|Remote} remote
598+
* @param {Object|RemoteCallback} remoteCallbacks Any custom callbacks needed
592599
*/
593600
Repository.prototype.fetch = function(
594601
remote,
595602
remoteCallbacks,
603+
596604
callback)
597605
{
598606
var repo = this;
@@ -613,6 +621,7 @@ Repository.prototype.fetch = function(
613621

614622
/**
615623
* Fetches from all remotes
624+
* @param {Object|RemoteCallback} remoteCallbacks Any custom callbacks needed
616625
*/
617626
Repository.prototype.fetchAll = function(
618627
remoteCallbacks,

test/tests/signature.js

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,19 @@
11
var assert = require("assert");
22
var path = require("path");
33
var local = path.join.bind(path, __dirname);
4+
var promisify = require("promisify-node");
5+
var Promise = require("nodegit-promise");
6+
7+
// Have to wrap exec, since it has a weird callback signature.
8+
var exec = promisify(function(command, opts, callback) {
9+
return require("child_process").exec(command, opts, callback);
10+
});
411

512
describe("Signature", function() {
613
var Signature = require(local("../../lib/signature"));
14+
var Repository = require(local("../../lib/repository"));
15+
16+
var reposPath = local("../repos/workdir/.git");
717

818
var name = "Bob Gnarley";
919
var email = "gnarlee@bob.net";
@@ -33,4 +43,53 @@ describe("Signature", function() {
3343
// libgit2 does its timezone offsets backwards from javascript
3444
assert.equal(when.offset(), -now.getTimezoneOffset());
3545
});
46+
47+
it("can get a default signature when no user name is set", function() {
48+
var savedUserName;
49+
var savedUserEmail;
50+
51+
var cleanUp = function() {
52+
return exec("git config --global user.name \"" + savedUserName + "\"")
53+
.then(function() {
54+
return exec(
55+
"git config --global user.email \"" +
56+
savedUserEmail +
57+
"\"");
58+
});
59+
};
60+
61+
return exec("git config --global user.name")
62+
.then(function(userName) {
63+
savedUserName = userName.trim();
64+
65+
return exec("git config --global user.email");
66+
})
67+
.then(function(userEmail) {
68+
savedUserEmail = userEmail.trim();
69+
70+
return exec("git config --global --unset user.name");
71+
})
72+
.then(function() {
73+
return exec("git config --global --unset user.email");
74+
})
75+
.then(function() {
76+
return Repository.open(reposPath);
77+
})
78+
.then(function(repo) {
79+
var sig = repo.defaultSignature();
80+
81+
assert.equal(sig.name(), "unknown");
82+
assert.equal(sig.email(), "unknown@unknown.com");
83+
84+
})
85+
.then(function() {
86+
cleanUp();
87+
})
88+
.catch(function(e) {
89+
cleanUp()
90+
.then(function() {
91+
return Promise.reject(e);
92+
});
93+
});
94+
});
3695
});

0 commit comments

Comments
 (0)