-
Notifications
You must be signed in to change notification settings - Fork 696
Expand file tree
/
Copy pathindex_setup.js
More file actions
93 lines (86 loc) · 3.02 KB
/
index_setup.js
File metadata and controls
93 lines (86 loc) · 3.02 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
var NodeGit = require("../../");
var path = require("path");
var promisify = require("promisify-node");
var fse = promisify(require("fs-extra"));
var RepoUtils = require("../utils/repository_setup");
var IndexSetup = {
createConflict: function createConflict(
repository,
_ourBranchName,
_theirBranchName,
_fileName
) {
var fileName = _fileName || "everyonesFile.txt";
var ourBranchName = _ourBranchName || "ours";
var theirBranchName = _theirBranchName || "theirs";
var baseFileContent = "How do you feel about Toll Roads?\n";
var ourFileContent = "I like Toll Roads. I have an EZ-Pass!\n";
var theirFileContent = "I'm skeptical about Toll Roads\n";
var ourSignature = NodeGit.Signature.create
("Ron Paul", "RonPaul@TollRoadsRBest.info", 123456789, 60);
var theirSignature = NodeGit.Signature.create
("Greg Abbott", "Gregggg@IllTollYourFace.us", 123456789, 60);
var ourCommit;
var ourBranch;
var theirBranch;
return fse.writeFile(
path.join(repository.workdir(), fileName),
baseFileContent
)
.then(function() {
return RepoUtils.addFileToIndex(repository, fileName);
})
.then(function(oid) {
return repository.createCommit("HEAD", ourSignature,
ourSignature, "initial commit", oid, []);
})
.then(function(commitOid) {
return repository.getCommit(commitOid).then(function(commit) {
ourCommit = commit;
}).then(function() {
return repository.createBranch(ourBranchName, commitOid)
.then(function(branch) {
ourBranch = branch;
return repository.createBranch(theirBranchName, commitOid);
});
});
})
.then(function(branch) {
theirBranch = branch;
return fse.writeFile(path.join(repository.workdir(), fileName),
baseFileContent + theirFileContent);
})
.then(function() {
return RepoUtils.addFileToIndex(repository, fileName);
})
.then(function(oid) {
return repository.createCommit(theirBranch.name(), theirSignature,
theirSignature, "they made a commit", oid, [ourCommit]);
})
.then(function(commitOid) {
return fse.writeFile(path.join(repository.workdir(), fileName),
baseFileContent + ourFileContent);
})
.then(function() {
return RepoUtils.addFileToIndex(repository, fileName);
})
.then(function(oid) {
return repository.createCommit(ourBranch.name(), ourSignature,
ourSignature, "we made a commit", oid, [ourCommit]);
})
.then(function() {
return repository.checkoutBranch(
ourBranch,
new NodeGit.CheckoutOptions()
);
})
.then(function() {
return repository.mergeBranches(ourBranchName, theirBranchName);
})
.catch(function(index) {
return NodeGit.Checkout.index(repository, index)
.then(function() { return index; });
});
}
};
module.exports = IndexSetup;