-
Notifications
You must be signed in to change notification settings - Fork 696
Expand file tree
/
Copy pathcherrypick.js
More file actions
159 lines (133 loc) · 4.63 KB
/
cherrypick.js
File metadata and controls
159 lines (133 loc) · 4.63 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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
var assert = require("assert");
var path = require("path");
var local = path.join.bind(path, __dirname);
var fse = require("fs-extra");
describe("Cherrypick", function() {
var RepoUtils = require("../utils/repository_setup");
var NodeGit = require("../../");
var Cherrypick = NodeGit.Cherrypick;
var repoPath = local("../repos/cherrypick");
beforeEach(function() {
var test = this;
return RepoUtils.createRepository(repoPath)
.then(function(repo) {
test.repository = repo;
});
});
after(function() {
return fse.remove(repoPath);
});
it("can cherrypick a commit onto the index", function() {
var repo = this.repository;
var workDirPath = repo.workdir();
var repoInfo;
return RepoUtils.setupBranches(repo, true)
.then(function(info) {
repoInfo = info;
assert(!fse.existsSync(path.join(workDirPath, repoInfo.theirFileName)),
repoInfo.theirFileName + " shouldn't exist");
var promise = Cherrypick.cherrypick(repo, repoInfo.theirCommit, {});
assert(promise.then);
return promise;
})
.then(function() {
assert(fse.existsSync(path.join(workDirPath, repoInfo.theirFileName)),
repoInfo.theirFileName + " should exist");
// Cherrypick.cherrypick leaves the repo in a cherrypick state
assert.equal(repo.state(), NodeGit.Repository.STATE.CHERRYPICK);
assert.ok(repo.isCherrypicking());
// cleanup
assert.equal(repo.stateCleanup(), 0);
assert.equal(repo.state(), NodeGit.Repository.STATE.NONE);
assert.ok(repo.isDefaultState());
});
});
it("can cherrypick a commit onto another specified commit", function() {
var repo = this.repository;
var workDirPath = repo.workdir();
var repoInfo;
return RepoUtils.setupBranches(repo)
.then(function(info) {
repoInfo = info;
assert(!fse.existsSync(path.join(workDirPath, repoInfo.ourFileName)),
repoInfo.ourFileName + " shouldn't exist");
assert(!fse.existsSync(path.join(workDirPath, repoInfo.theirFileName)),
repoInfo.theirFileName + " shouldn't exist");
var promise = Cherrypick.commit(repo, repoInfo.theirCommit,
repoInfo.ourCommit, 0, {});
assert(promise.then);
return promise;
})
.then(function(index) {
assert(index);
return index.writeTreeTo(repo);
})
.then(function(oid) {
return repo.getTree(oid);
})
.then(function(tree) {
var opts = {
checkoutStrategy: NodeGit.Checkout.STRATEGY.FORCE
};
return NodeGit.Checkout.tree(repo, tree, opts);
})
.then(function() {
assert(fse.existsSync(path.join(workDirPath, repoInfo.ourFileName)),
repoInfo.ourFileName + " should exist");
assert(fse.existsSync(path.join(workDirPath, repoInfo.theirFileName)),
repoInfo.theirFileName + " should exist");
});
});
it("can cherrypick a stash to apply it", function() {
var repo = this.repository;
var workDirPath = repo.workdir();
var repoInfo;
var cherrypickOid;
var addedContent = "\nIt makes things E-Z!";
return RepoUtils.setupBranches(repo, true)
.then(function(info) {
repoInfo = info;
return repo.getStatus();
})
.then(function(statuses) {
assert.equal(statuses.length, 0);
return fse.writeFile(path.join(workDirPath, repoInfo.ourFileName),
repoInfo.ourFileContent + addedContent);
})
.then(function() {
return repo.getStatus();
})
.then(function(statuses) {
assert.equal(statuses.length, 1);
return NodeGit.Stash.save(repo, repoInfo.ourSignature, "our stash", 0);
})
.then(function(oid) {
cherrypickOid = oid;
return fse.readFile(path.join(workDirPath, repoInfo.ourFileName));
})
.then(function(fileContent) {
assert.equal(fileContent, repoInfo.ourFileContent);
return repo.getStatus();
})
.then(function(statuses) {
assert.equal(statuses.length, 0);
return repo.getCommit(cherrypickOid);
})
.then(function(commit) {
var opts = {
mainline: 1
};
return Cherrypick.cherrypick(repo, commit, opts);
})
.then(function() {
return repo.getStatus();
})
.then(function(statuses) {
assert.equal(statuses.length, 1);
return fse.readFile(path.join(workDirPath, repoInfo.ourFileName));
})
.then(function(fileContent) {
assert.equal(fileContent, repoInfo.ourFileContent + addedContent);
});
});
});