forked from nodegit/nodegit
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconfig.js
More file actions
95 lines (83 loc) · 2.44 KB
/
config.js
File metadata and controls
95 lines (83 loc) · 2.44 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
var assert = require("assert");
var path = require("path");
var local = path.join.bind(path, __dirname);
var exec = require("../../utils/execPromise");
describe("Config", function() {
var NodeGit = require("../../");
var reposPath = local("../repos/workdir");
it("can get and set a global value", function() {
var savedUserName;
function finallyFn() {
return exec("git config --global user.name \"" + savedUserName + "\"");
}
return exec("git config --global user.name")
.then(function(userName) {
savedUserName = userName.trim();
return exec(
"git config --global user.name \"" + savedUserName + "-test\"");
})
.then(function() {
return NodeGit.Config.openDefault();
})
.then(function(config) {
return config.getString("user.name");
})
.then(function(userNameFromNodeGit) {
assert.equal(savedUserName + "-test", userNameFromNodeGit);
})
.then(finallyFn)
.catch(function(e) {
return finallyFn()
.then(function() {
throw e;
});
});
});
it("will reject when getting value of non-existent config key", function() {
// Test initially for finding source of a segfault. There was a problem
// where getting an empty config value crashes nodegit.
return NodeGit.Config.openDefault()
.then(function(config) {
return config.getString("user.fakevalue");
})
.catch(function (e) {
return true;
});
});
it("can get and set a repo config value", function() {
var savedUserName;
function finallyFn() {
return exec("git config user.name \"" + savedUserName + "\"", {
cwd: reposPath
});
}
return exec("git config user.name", {
cwd: reposPath
})
.then(function(userName) {
savedUserName = userName.trim();
return exec("git config user.name \"" + savedUserName + "-test\"", {
cwd: reposPath
});
})
.then(function() {
return NodeGit.Repository.open(reposPath);
})
.then(function(repo) {
return repo.config();
})
.then(function(config) {
return config.getString("user.name");
})
.then(function(userNameFromNodeGit) {
assert.equal(savedUserName + "-test", userNameFromNodeGit);
})
.then(finallyFn)
.catch(function(e) {
return finallyFn()
.then(function() {
throw e;
});
});
});
});