| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 617e74e commit bd9e893
2 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -539,7 +539,13 @@ Repository.prototype.treeBuilder = function() { | |||
| 539 | 539 | * @return {Signature} | |
| 540 | 540 | */ | |
| 541 | 541 | 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; | ||
| 543 | 549 | }; | |
| 544 | 550 | ||
| 545 | 551 | /** | |
@@ -589,10 +595,12 @@ Repository.prototype.getRemote = function(remote, callback) { | |||
| 589 | 595 | * Fetches from a remote | |
| 590 | 596 | * | |
| 591 | 597 | * @param {String|Remote} remote | |
| 598 | + * @param {Object|RemoteCallback} remoteCallbacks Any custom callbacks needed | ||
| 592 | 599 | */ | |
| 593 | 600 | Repository.prototype.fetch = function( | |
| 594 | 601 | remote, | |
| 595 | 602 | remoteCallbacks, | |
| 603 | + | ||
| 596 | 604 | callback) | |
| 597 | 605 | { | |
| 598 | 606 | var repo = this; | |
@@ -613,6 +621,7 @@ Repository.prototype.fetch = function( | |||
| 613 | 621 | ||
| 614 | 622 | /** | |
| 615 | 623 | * Fetches from all remotes | |
| 624 | + * @param {Object|RemoteCallback} remoteCallbacks Any custom callbacks needed | ||
| 616 | 625 | */ | |
| 617 | 626 | Repository.prototype.fetchAll = function( | |
| 618 | 627 | remoteCallbacks, | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,9 +1,19 @@ | |||
| 1 | 1 | var assert = require("assert"); | |
| 2 | 2 | var path = require("path"); | |
| 3 | 3 | 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 | + }); | ||
| 4 | 11 | ||
| 5 | 12 | describe("Signature", function() { | |
| 6 | 13 | var Signature = require(local("../../lib/signature")); | |
| 14 | + var Repository = require(local("../../lib/repository")); | ||
| 15 | + | ||
| 16 | + var reposPath = local("../repos/workdir/.git"); | ||
| 7 | 17 | ||
| 8 | 18 | var name = "Bob Gnarley"; | |
| 9 | 19 | var email = "gnarlee@bob.net"; | |
@@ -33,4 +43,53 @@ describe("Signature", function() { | |||
| 33 | 43 | // libgit2 does its timezone offsets backwards from javascript | |
| 34 | 44 | assert.equal(when.offset(), -now.getTimezoneOffset()); | |
| 35 | 45 | }); | |
| 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 | + }); | ||
| 36 | 95 | }); | |
| Back | FazBrowse Home | New Git URL |
0 commit comments