pj-nodegit 0.18.4 → 0.18.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/README.md +3 -0
- package/lib/attr.js +20 -0
- package/lib/blame.js +20 -0
- package/lib/blob.js +73 -0
- package/lib/branch.js +19 -0
- package/lib/buf.js +11 -0
- package/lib/checkout.js +51 -0
- package/lib/cherrypick.js +73 -0
- package/lib/clone.js +33 -0
- package/lib/commit.js +437 -0
- package/lib/config.js +25 -0
- package/lib/convenient_hunks.js +61 -0
- package/lib/convenient_patch.js +131 -0
- package/lib/credential.js +33 -0
- package/lib/diff.js +113 -0
- package/lib/diff_file.js +38 -0
- package/lib/diff_line.js +32 -0
- package/lib/enums.js +689 -0
- package/lib/error.js +17 -0
- package/lib/filter_registry.js +25 -0
- package/lib/index.js +103 -0
- package/lib/libgit2.js +6 -0
- package/lib/merge.js +72 -0
- package/lib/nodegit.js +1333 -0
- package/lib/note.js +17 -0
- package/lib/object.js +45 -0
- package/lib/odb_object.js +9 -0
- package/lib/oid.js +23 -0
- package/lib/rebase.js +142 -0
- package/lib/reference.js +213 -0
- package/lib/remote.js +270 -0
- package/lib/repository.js +1982 -0
- package/lib/reset.js +76 -0
- package/lib/revert.js +77 -0
- package/lib/revwalk.js +142 -0
- package/lib/signature.js +38 -0
- package/lib/stash.js +62 -0
- package/lib/status.js +18 -0
- package/lib/status_file.js +106 -0
- package/lib/status_list.js +12 -0
- package/lib/submodule.js +51 -0
- package/lib/tag.js +135 -0
- package/lib/tree.js +175 -0
- package/lib/tree_entry.js +99 -0
- package/lib/utils/lookup_wrapper.js +39 -0
- package/lib/utils/normalize_fetch_options.js +43 -0
- package/lib/utils/normalize_options.js +29 -0
- package/lib/utils/shallow_clone.js +14 -0
- package/package.json +1 -1
package/lib/note.js
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
var NodeGit = require("../");
|
2
|
+
|
3
|
+
var Note = NodeGit.Note;
|
4
|
+
|
5
|
+
var _foreach = Note.foreach;
|
6
|
+
|
7
|
+
// Override Note.foreach to eliminate the need to pass null payload
|
8
|
+
Note.foreach = function(repo, notesRef, callback) {
|
9
|
+
function wrapperCallback(blobId, objectId) {
|
10
|
+
// We need to copy the OID since libgit2 types are getting cleaned up
|
11
|
+
// incorrectly right now in callbacks
|
12
|
+
|
13
|
+
return callback(blobId.copy(), objectId.copy());
|
14
|
+
}
|
15
|
+
|
16
|
+
return _foreach(repo, notesRef, wrapperCallback, null);
|
17
|
+
};
|
package/lib/object.js
ADDED
@@ -0,0 +1,45 @@
|
|
1
|
+
var util = require("util");
|
2
|
+
var NodeGit = require("../");
|
3
|
+
|
4
|
+
var Obj = NodeGit.Object;
|
5
|
+
|
6
|
+
/**
|
7
|
+
* Is this object a blob?
|
8
|
+
* @return {Boolean}
|
9
|
+
*/
|
10
|
+
Obj.prototype.isBlob = function() {
|
11
|
+
return this.type() == Obj.TYPE.BLOB;
|
12
|
+
};
|
13
|
+
|
14
|
+
/**
|
15
|
+
* Is this object a commit?
|
16
|
+
* @return {Boolean}
|
17
|
+
*/
|
18
|
+
Obj.prototype.isCommit = function() {
|
19
|
+
return this.type() == Obj.TYPE.COMMIT;
|
20
|
+
};
|
21
|
+
|
22
|
+
/**
|
23
|
+
* Is this object a tag?
|
24
|
+
* @return {Boolean}
|
25
|
+
*/
|
26
|
+
Obj.prototype.isTag = function() {
|
27
|
+
return this.type() == Obj.TYPE.TAG;
|
28
|
+
};
|
29
|
+
|
30
|
+
/**
|
31
|
+
* Is this object a tree?
|
32
|
+
* @return {Boolean}
|
33
|
+
*/
|
34
|
+
Obj.prototype.isTree = function() {
|
35
|
+
return this.type() == Obj.TYPE.TREE;
|
36
|
+
};
|
37
|
+
|
38
|
+
// Deprecated -----------------------------------------------------------------
|
39
|
+
|
40
|
+
Object.defineProperty(Obj.TYPE, "BAD", {
|
41
|
+
get: util.deprecate(
|
42
|
+
() => Obj.TYPE.INVALID,
|
43
|
+
"Use NodeGit.Object.TYPE.INVALID instead of NodeGit.Object.TYPE.BAD."
|
44
|
+
)
|
45
|
+
});
|
package/lib/oid.js
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
var NodeGit = require("../");
|
2
|
+
|
3
|
+
var Oid = NodeGit.Oid;
|
4
|
+
|
5
|
+
// Backwards compatibility.
|
6
|
+
Object.defineProperties(Oid.prototype, {
|
7
|
+
"allocfmt": {
|
8
|
+
value: Oid.prototype.tostrS,
|
9
|
+
enumerable: false
|
10
|
+
},
|
11
|
+
"toString": {
|
12
|
+
value: Oid.prototype.tostrS,
|
13
|
+
enumerable: false
|
14
|
+
}
|
15
|
+
});
|
16
|
+
|
17
|
+
Oid.prototype.copy = function() {
|
18
|
+
return this.cpy(); // seriously???
|
19
|
+
};
|
20
|
+
|
21
|
+
Oid.prototype.inspect = function() {
|
22
|
+
return "[Oid " + this.allocfmt() + "]";
|
23
|
+
};
|
package/lib/rebase.js
ADDED
@@ -0,0 +1,142 @@
|
|
1
|
+
var NodeGit = require("../");
|
2
|
+
var Rebase = NodeGit.Rebase;
|
3
|
+
var normalizeOptions = NodeGit.Utils.normalizeOptions;
|
4
|
+
var shallowClone = NodeGit.Utils.shallowClone;
|
5
|
+
|
6
|
+
var _init = Rebase.init;
|
7
|
+
var _open = Rebase.open;
|
8
|
+
var _abort = Rebase.prototype.abort;
|
9
|
+
var _commit = Rebase.prototype.commit;
|
10
|
+
|
11
|
+
function defaultRebaseOptions(options, checkoutStrategy) {
|
12
|
+
let checkoutOptions;
|
13
|
+
let mergeOptions;
|
14
|
+
|
15
|
+
if (options) {
|
16
|
+
options = shallowClone(options);
|
17
|
+
checkoutOptions = options.checkoutOptions;
|
18
|
+
mergeOptions = options.mergeOptions;
|
19
|
+
delete options.checkoutOptions;
|
20
|
+
delete options.mergeOptions;
|
21
|
+
|
22
|
+
if (options.signingCb) {
|
23
|
+
let signingCb = options.signingCb;
|
24
|
+
options.signingCb = function (
|
25
|
+
signatureBuf,
|
26
|
+
signatureFieldBuf,
|
27
|
+
commitContent
|
28
|
+
) {
|
29
|
+
try {
|
30
|
+
const signingCbResult = signingCb(commitContent);
|
31
|
+
|
32
|
+
return Promise.resolve(signingCbResult)
|
33
|
+
.then(function({ code, field, signedData }) {
|
34
|
+
if (code === NodeGit.Error.CODE.OK) {
|
35
|
+
signatureBuf.setString(signedData);
|
36
|
+
if (field) {
|
37
|
+
signatureFieldBuf.setString(field);
|
38
|
+
}
|
39
|
+
}
|
40
|
+
|
41
|
+
return code;
|
42
|
+
})
|
43
|
+
.catch(function(error) {
|
44
|
+
if (error && error.code) {
|
45
|
+
return error.code;
|
46
|
+
}
|
47
|
+
return NodeGit.Error.CODE.ERROR;
|
48
|
+
});
|
49
|
+
} catch (error) {
|
50
|
+
if (error && error.code) {
|
51
|
+
return error.code;
|
52
|
+
}
|
53
|
+
return NodeGit.Error.CODE.ERROR;
|
54
|
+
}
|
55
|
+
};
|
56
|
+
}
|
57
|
+
|
58
|
+
options = normalizeOptions(options, NodeGit.RebaseOptions);
|
59
|
+
} else {
|
60
|
+
options = normalizeOptions({}, NodeGit.RebaseOptions);
|
61
|
+
if (checkoutStrategy) {
|
62
|
+
checkoutOptions = {
|
63
|
+
checkoutStrategy: checkoutStrategy
|
64
|
+
};
|
65
|
+
}
|
66
|
+
}
|
67
|
+
|
68
|
+
if (checkoutOptions) {
|
69
|
+
options.checkoutOptions = normalizeOptions(
|
70
|
+
checkoutOptions,
|
71
|
+
NodeGit.CheckoutOptions
|
72
|
+
);
|
73
|
+
}
|
74
|
+
|
75
|
+
if (mergeOptions) {
|
76
|
+
options.mergeOptions = normalizeOptions(
|
77
|
+
mergeOptions,
|
78
|
+
NodeGit.MergeOptions
|
79
|
+
);
|
80
|
+
}
|
81
|
+
|
82
|
+
return options;
|
83
|
+
}
|
84
|
+
|
85
|
+
// Save options on the rebase object. If we don't do this,
|
86
|
+
// the options may be cleaned up and cause a segfault
|
87
|
+
// when Rebase.prototype.commit is called.
|
88
|
+
const lockOptionsOnRebase = (options) => (rebase) => {
|
89
|
+
Object.defineProperty(rebase, "options", {
|
90
|
+
value: options,
|
91
|
+
writable: false
|
92
|
+
});
|
93
|
+
return rebase;
|
94
|
+
};
|
95
|
+
|
96
|
+
/**
|
97
|
+
* Initializes a rebase
|
98
|
+
* @async
|
99
|
+
* @param {Repository} repo The repository to perform the rebase
|
100
|
+
* @param {AnnotatedCommit} branch The terminal commit to rebase, or NULL to
|
101
|
+
* rebase the current branch
|
102
|
+
* @param {AnnotatedCommit} upstream The commit to begin rebasing from, or NULL
|
103
|
+
* to rebase all reachable commits
|
104
|
+
* @param {AnnotatedCommit} onto The branch to rebase onto, or NULL to rebase
|
105
|
+
* onto the given upstream
|
106
|
+
* @param {RebaseOptions} options Options to specify how rebase is performed,
|
107
|
+
* or NULL
|
108
|
+
* @return {Remote}
|
109
|
+
*/
|
110
|
+
Rebase.init = function(repository, branch, upstream, onto, options) {
|
111
|
+
options = defaultRebaseOptions(
|
112
|
+
options,
|
113
|
+
NodeGit.Checkout.STRATEGY.FORCE
|
114
|
+
);
|
115
|
+
return _init(repository, branch, upstream, onto, options)
|
116
|
+
.then(lockOptionsOnRebase(options));
|
117
|
+
};
|
118
|
+
|
119
|
+
/**
|
120
|
+
* Opens an existing rebase that was previously started by either an invocation
|
121
|
+
* of Rebase.open or by another client.
|
122
|
+
* @async
|
123
|
+
* @param {Repository} repo The repository that has a rebase in-progress
|
124
|
+
* @param {RebaseOptions} options Options to specify how rebase is performed
|
125
|
+
* @return {Remote}
|
126
|
+
*/
|
127
|
+
Rebase.open = function(repository, options) {
|
128
|
+
options = defaultRebaseOptions(
|
129
|
+
options,
|
130
|
+
NodeGit.Checkout.STRATEGY.SAFE
|
131
|
+
);
|
132
|
+
return _open(repository, options)
|
133
|
+
.then(lockOptionsOnRebase(options));
|
134
|
+
};
|
135
|
+
|
136
|
+
Rebase.prototype.commit = function(author, committer, encoding, message) {
|
137
|
+
return _commit.call(this, author, committer, encoding, message);
|
138
|
+
};
|
139
|
+
|
140
|
+
Rebase.prototype.abort = function() {
|
141
|
+
return _abort.call(this);
|
142
|
+
};
|
package/lib/reference.js
ADDED
@@ -0,0 +1,213 @@
|
|
1
|
+
var util = require("util");
|
2
|
+
var NodeGit = require("../");
|
3
|
+
var LookupWrapper = NodeGit.Utils.lookupWrapper;
|
4
|
+
|
5
|
+
var Reference = NodeGit.Reference;
|
6
|
+
var Branch = NodeGit.Branch;
|
7
|
+
|
8
|
+
/**
|
9
|
+
* Retrieves the reference by it's short name
|
10
|
+
* @async
|
11
|
+
* @param {Repository} repo The repo that the reference lives in
|
12
|
+
* @param {String|Reference} id The reference to lookup
|
13
|
+
* @param {Function} callback
|
14
|
+
* @return {Reference}
|
15
|
+
*/
|
16
|
+
Reference.dwim = LookupWrapper(Reference, Reference.dwim);
|
17
|
+
|
18
|
+
/**
|
19
|
+
* Retrieves the reference pointed to by the oid
|
20
|
+
* @async
|
21
|
+
* @param {Repository} repo The repo that the reference lives in
|
22
|
+
* @param {String|Reference} id The reference to lookup
|
23
|
+
* @param {Function} callback
|
24
|
+
* @return {Reference}
|
25
|
+
*/
|
26
|
+
Reference.lookup = LookupWrapper(Reference);
|
27
|
+
|
28
|
+
/**
|
29
|
+
* Returns true if this reference is not symbolic
|
30
|
+
* @return {Boolean}
|
31
|
+
*/
|
32
|
+
Reference.prototype.isConcrete = function() {
|
33
|
+
return this.type() == Reference.TYPE.DIRECT;
|
34
|
+
};
|
35
|
+
|
36
|
+
/**
|
37
|
+
* Returns if the ref is pointed at by HEAD
|
38
|
+
* @return {Boolean}
|
39
|
+
*/
|
40
|
+
Reference.prototype.isHead = function() {
|
41
|
+
return Branch.isHead(this);
|
42
|
+
};
|
43
|
+
|
44
|
+
/**
|
45
|
+
* Returns true if this reference is symbolic
|
46
|
+
* @return {Boolean}
|
47
|
+
*/
|
48
|
+
Reference.prototype.isSymbolic = function() {
|
49
|
+
return this.type() == Reference.TYPE.SYMBOLIC;
|
50
|
+
};
|
51
|
+
|
52
|
+
/**
|
53
|
+
* Returns true if this reference is valid
|
54
|
+
* @return {Boolean}
|
55
|
+
*/
|
56
|
+
Reference.prototype.isValid = function() {
|
57
|
+
return this.type() != Reference.TYPE.INVALID;
|
58
|
+
};
|
59
|
+
|
60
|
+
/**
|
61
|
+
* Returns the name of the reference.
|
62
|
+
* @return {String}
|
63
|
+
*/
|
64
|
+
Reference.prototype.toString = function() {
|
65
|
+
return this.name();
|
66
|
+
};
|
67
|
+
|
68
|
+
const getTerminal = (repo, refName, depth = 10, prevRef = null) => {
|
69
|
+
if (depth <= 0) {
|
70
|
+
return Promise.resolve({
|
71
|
+
error: NodeGit.Error.CODE.ENOTFOUND,
|
72
|
+
out: prevRef
|
73
|
+
});
|
74
|
+
}
|
75
|
+
|
76
|
+
return NodeGit.Reference.lookup(repo, refName)
|
77
|
+
.then((ref) => {
|
78
|
+
if (ref.type() === NodeGit.Reference.TYPE.DIRECT) {
|
79
|
+
return {
|
80
|
+
error: NodeGit.Error.CODE.OK,
|
81
|
+
out: ref
|
82
|
+
};
|
83
|
+
} else {
|
84
|
+
return getTerminal(repo, ref.symbolicTarget(), depth - 1, ref)
|
85
|
+
.then(({ error, out }) => {
|
86
|
+
if (error === NodeGit.Error.CODE.ENOTFOUND && !out) {
|
87
|
+
return { error, out: ref };
|
88
|
+
} else {
|
89
|
+
return { error, out };
|
90
|
+
}
|
91
|
+
});
|
92
|
+
}
|
93
|
+
})
|
94
|
+
.catch((error) => {
|
95
|
+
return {
|
96
|
+
error: error.errno,
|
97
|
+
out: null
|
98
|
+
};
|
99
|
+
});
|
100
|
+
};
|
101
|
+
|
102
|
+
const getSignatureForReflog = (repo) => {
|
103
|
+
const { email, name } = repo.ident();
|
104
|
+
if (email && name) {
|
105
|
+
return Promise.resolve(NodeGit.Signature.now(name, email));
|
106
|
+
}
|
107
|
+
|
108
|
+
return NodeGit.Signature.default(repo)
|
109
|
+
.catch(() => NodeGit.Signature.now("unknown", "unknown"));
|
110
|
+
};
|
111
|
+
|
112
|
+
/**
|
113
|
+
* Given a reference name, follows symbolic links and updates the direct
|
114
|
+
* reference to point to a given OID. Updates the reflog with a given message.
|
115
|
+
*
|
116
|
+
* @async
|
117
|
+
* @param {Repository} repo The repo where the reference and objects live
|
118
|
+
* @param {String} refName The reference name to update
|
119
|
+
* @param {Oid} oid The target OID that the reference will point to
|
120
|
+
* @param {String} logMessage The reflog message to be writted
|
121
|
+
* @param {Signature} signature Optional signature to use for the reflog entry
|
122
|
+
*/
|
123
|
+
Reference.updateTerminal = function (
|
124
|
+
repo,
|
125
|
+
refName,
|
126
|
+
oid,
|
127
|
+
logMessage,
|
128
|
+
signature
|
129
|
+
) {
|
130
|
+
let signatureToUse;
|
131
|
+
let promiseChain = Promise.resolve();
|
132
|
+
|
133
|
+
if (!signature) {
|
134
|
+
promiseChain = promiseChain
|
135
|
+
.then(() => getSignatureForReflog(repo))
|
136
|
+
.then((sig) => {
|
137
|
+
signatureToUse = sig;
|
138
|
+
return Promise.resolve();
|
139
|
+
});
|
140
|
+
} else {
|
141
|
+
signatureToUse = signature;
|
142
|
+
}
|
143
|
+
|
144
|
+
return promiseChain
|
145
|
+
.then(() => getTerminal(repo, refName))
|
146
|
+
.then(({ error, out }) => {
|
147
|
+
if (error === NodeGit.Error.CODE.ENOTFOUND && out) {
|
148
|
+
return NodeGit.Reference.create(
|
149
|
+
repo,
|
150
|
+
out.symbolicTarget(),
|
151
|
+
oid,
|
152
|
+
0,
|
153
|
+
logMessage
|
154
|
+
);
|
155
|
+
} else if (error === NodeGit.Error.CODE.ENOTFOUND) {
|
156
|
+
return NodeGit.Reference.create(
|
157
|
+
repo,
|
158
|
+
refName,
|
159
|
+
oid,
|
160
|
+
0,
|
161
|
+
logMessage
|
162
|
+
);
|
163
|
+
} else {
|
164
|
+
return NodeGit.Reference.createMatching(
|
165
|
+
repo,
|
166
|
+
out.name(),
|
167
|
+
oid,
|
168
|
+
1,
|
169
|
+
out.target(),
|
170
|
+
logMessage
|
171
|
+
);
|
172
|
+
}
|
173
|
+
})
|
174
|
+
.then(() => NodeGit.Reflog.read(repo, refName))
|
175
|
+
.then((reflog) => {
|
176
|
+
// Janky, but works. Ideally, we would want to generate the correct reflog
|
177
|
+
// entry in the first place, rather than drop the most recent entry and
|
178
|
+
// write the correct one.
|
179
|
+
// NOTE: There is a theoretical race condition that could happen here.
|
180
|
+
// We may want to consider some kind of transactional logic to make sure
|
181
|
+
// that the reflog on disk isn't modified before we can write back.
|
182
|
+
reflog.drop(0, 1);
|
183
|
+
reflog.append(oid, signatureToUse, logMessage);
|
184
|
+
return reflog.write();
|
185
|
+
});
|
186
|
+
};
|
187
|
+
|
188
|
+
// Deprecated -----------------------------------------------------------------
|
189
|
+
|
190
|
+
Object.defineProperty(NodeGit.Reference.TYPE, "OID", {
|
191
|
+
get: util.deprecate(
|
192
|
+
() => NodeGit.Reference.TYPE.DIRECT,
|
193
|
+
"Use NodeGit.Reference.TYPE.DIRECT instead of NodeGit.Reference.TYPE.OID."
|
194
|
+
)
|
195
|
+
});
|
196
|
+
|
197
|
+
Object.defineProperty(NodeGit.Reference.TYPE, "LISTALL", {
|
198
|
+
get: util.deprecate(
|
199
|
+
() => NodeGit.Reference.TYPE.ALL,
|
200
|
+
"Use NodeGit.Reference.TYPE.ALL instead of NodeGit.Reference.TYPE.LISTALL."
|
201
|
+
)
|
202
|
+
});
|
203
|
+
|
204
|
+
NodeGit.Reference.NORMALIZE = {};
|
205
|
+
Object.keys(NodeGit.Reference.FORMAT).forEach((key) => {
|
206
|
+
Object.defineProperty(NodeGit.Reference.NORMALIZE, `REF_FORMAT_${key}`, {
|
207
|
+
get: util.deprecate(
|
208
|
+
() => NodeGit.Reference.FORMAT[key],
|
209
|
+
`Use NodeGit.Reference.FORMAT.${key} instead of ` +
|
210
|
+
`NodeGit.Reference.NORMALIZE.REF_FORMAT_${key}.`
|
211
|
+
)
|
212
|
+
});
|
213
|
+
});
|