|
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 | }); |
0 commit comments