forked from nodegit/nodegit
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrebase.js
More file actions
142 lines (127 loc) · 4.04 KB
/
Copy pathrebase.js
File metadata and controls
142 lines (127 loc) · 4.04 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
var NodeGit = require("../");
var Rebase = NodeGit.Rebase;
var normalizeOptions = NodeGit.Utils.normalizeOptions;
var shallowClone = NodeGit.Utils.shallowClone;
var _init = Rebase.init;
var _open = Rebase.open;
var _abort = Rebase.prototype.abort;
var _commit = Rebase.prototype.commit;
function defaultRebaseOptions(options, checkoutStrategy) {
let checkoutOptions;
let mergeOptions;
if (options) {
options = shallowClone(options);
checkoutOptions = options.checkoutOptions;
mergeOptions = options.mergeOptions;
delete options.checkoutOptions;
delete options.mergeOptions;
if (options.signingCb) {
let signingCb = options.signingCb;
options.signingCb = function (
signatureBuf,
signatureFieldBuf,
commitContent
) {
try {
const signingCbResult = signingCb(commitContent);
return Promise.resolve(signingCbResult)
.then(function({ code, field, signedData }) {
if (code === NodeGit.Error.CODE.OK) {
signatureBuf.setString(signedData);
if (field) {
signatureFieldBuf.setString(field);
}
}
return code;
})
.catch(function(error) {
if (error && error.code) {
return error.code;
}
return NodeGit.Error.CODE.ERROR;
});
} catch (error) {
if (error && error.code) {
return error.code;
}
return NodeGit.Error.CODE.ERROR;
}
};
}
options = normalizeOptions(options, NodeGit.RebaseOptions);
} else {
options = normalizeOptions({}, NodeGit.RebaseOptions);
if (checkoutStrategy) {
checkoutOptions = {
checkoutStrategy: checkoutStrategy
};
}
}
if (checkoutOptions) {
options.checkoutOptions = normalizeOptions(
checkoutOptions,
NodeGit.CheckoutOptions
);
}
if (mergeOptions) {
options.mergeOptions = normalizeOptions(
mergeOptions,
NodeGit.MergeOptions
);
}
return options;
}
// Save options on the rebase object. If we don't do this,
// the options may be cleaned up and cause a segfault
// when Rebase.prototype.commit is called.
const lockOptionsOnRebase = (options) => (rebase) => {
Object.defineProperty(rebase, "options", {
value: options,
writable: false
});
return rebase;
};
/**
* Initializes a rebase
* @async
* @param {Repository} repo The repository to perform the rebase
* @param {AnnotatedCommit} branch The terminal commit to rebase, or NULL to
* rebase the current branch
* @param {AnnotatedCommit} upstream The commit to begin rebasing from, or NULL
* to rebase all reachable commits
* @param {AnnotatedCommit} onto The branch to rebase onto, or NULL to rebase
* onto the given upstream
* @param {RebaseOptions} options Options to specify how rebase is performed,
* or NULL
* @return {Remote}
*/
Rebase.init = function(repository, branch, upstream, onto, options) {
options = defaultRebaseOptions(
options,
NodeGit.Checkout.STRATEGY.FORCE
);
return _init(repository, branch, upstream, onto, options)
.then(lockOptionsOnRebase(options));
};
/**
* Opens an existing rebase that was previously started by either an invocation
* of Rebase.open or by another client.
* @async
* @param {Repository} repo The repository that has a rebase in-progress
* @param {RebaseOptions} options Options to specify how rebase is performed
* @return {Remote}
*/
Rebase.open = function(repository, options) {
options = defaultRebaseOptions(
options,
NodeGit.Checkout.STRATEGY.SAFE
);
return _open(repository, options)
.then(lockOptionsOnRebase(options));
};
Rebase.prototype.commit = function(author, committer, encoding, message) {
return _commit.call(this, author, committer, encoding, message);
};
Rebase.prototype.abort = function() {
return _abort.call(this);
};