@swimlane/nodegit 1.1.2
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/.dockerignore +2 -0
- package/.github/workflows/publish.yml +126 -0
- package/.github/workflows/tests.yml +85 -0
- package/LICENSE +19 -0
- package/README.md +193 -0
- package/lib/attr.js +20 -0
- package/lib/blob.js +51 -0
- package/lib/branch.js +19 -0
- package/lib/buf.js +43 -0
- package/lib/commit.js +437 -0
- package/lib/config.js +48 -0
- package/lib/convenient_hunks.js +61 -0
- package/lib/convenient_patch.js +131 -0
- package/lib/credential.js +33 -0
- package/lib/deprecated/structs/ApplyOptions.js +3 -0
- package/lib/deprecated/structs/BlameOptions.js +6 -0
- package/lib/deprecated/structs/BlobFilterOptions.js +3 -0
- package/lib/deprecated/structs/CheckoutOptions.js +8 -0
- package/lib/deprecated/structs/CherrypickOptions.js +5 -0
- package/lib/deprecated/structs/CloneOptions.js +6 -0
- package/lib/deprecated/structs/DescribeFormatOptions.js +4 -0
- package/lib/deprecated/structs/DescribeOptions.js +6 -0
- package/lib/deprecated/structs/DiffFindOptions.js +8 -0
- package/lib/deprecated/structs/DiffOptions.js +8 -0
- package/lib/deprecated/structs/FetchOptions.js +7 -0
- package/lib/deprecated/structs/MergeFileInput.js +4 -0
- package/lib/deprecated/structs/MergeFileOptions.js +5 -0
- package/lib/deprecated/structs/MergeOptions.js +8 -0
- package/lib/deprecated/structs/ProxyOptions.js +3 -0
- package/lib/deprecated/structs/PushOptions.js +5 -0
- package/lib/deprecated/structs/RebaseOptions.js +6 -0
- package/lib/deprecated/structs/RemoteCreateOptions.js +3 -0
- package/lib/deprecated/structs/RepositoryInitOptions.js +4 -0
- package/lib/deprecated/structs/RevertOptions.js +5 -0
- package/lib/deprecated/structs/StashApplyOptions.js +4 -0
- package/lib/deprecated/structs/StatusOptions.js +4 -0
- package/lib/deprecated/structs/SubmoduleUpdateOptions.js +5 -0
- package/lib/diff.js +67 -0
- package/lib/diff_file.js +38 -0
- package/lib/diff_line.js +32 -0
- package/lib/error.js +17 -0
- package/lib/filter_registry.js +22 -0
- package/lib/graph.js +15 -0
- package/lib/index.js +103 -0
- package/lib/merge.js +41 -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 +86 -0
- package/lib/reference.js +213 -0
- package/lib/remote.js +45 -0
- package/lib/repository.js +1973 -0
- package/lib/reset.js +51 -0
- package/lib/revparse.js +18 -0
- package/lib/revwalk.js +142 -0
- package/lib/signature.js +38 -0
- package/lib/stash.js +16 -0
- package/lib/status.js +16 -0
- package/lib/status_file.js +106 -0
- package/lib/submodule.js +10 -0
- package/lib/tag.js +141 -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/shallow_clone.js +14 -0
- package/lifecycleScripts/clean.js +5 -0
- package/lifecycleScripts/install.js +32 -0
- package/lifecycleScripts/postinstall.js +83 -0
- package/lifecycleScripts/preinstall.js +47 -0
- package/lifecycleScripts/submodules/getStatus.js +50 -0
- package/lifecycleScripts/submodules/index.js +84 -0
- package/package.json +83 -0
- package/prebuilds/darwin-arm64/@swimlane+nodegit.glibc.node +0 -0
- package/prebuilds/darwin-x64/@swimlane+nodegit.glibc.node +0 -0
- package/prebuilds/linux-arm64/@swimlane+nodegit.glibc.node +0 -0
- package/prebuilds/linux-x64/@swimlane+nodegit.glibc.node +0 -0
- package/prebuilds/linux-x64/@swimlane+nodegit.musl.node +0 -0
- package/scripts/Dockerfile.alpine +10 -0
- package/scripts/Dockerfile.debian +15 -0
- package/utils/acquireOpenSSL.js +436 -0
- package/utils/build-openssl.bat +13 -0
- package/utils/buildFlags.js +19 -0
- package/utils/configureLibssh2.js +54 -0
- package/utils/defaultCxxStandard.js +18 -0
- package/utils/execPromise.js +24 -0
- package/utils/getElectronOpenSSLRoot.js +10 -0
- package/utils/gitExecutableLocation.js +23 -0
- package/utils/isBuildingForElectron.js +30 -0
- package/utils/retry.js +51 -0
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
|
+
});
|
package/lib/remote.js
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
var util = require("util");
|
|
2
|
+
var NodeGit = require("../");
|
|
3
|
+
var lookupWrapper = NodeGit.Utils.lookupWrapper;
|
|
4
|
+
|
|
5
|
+
var Remote = NodeGit.Remote;
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Retrieves the remote by name
|
|
9
|
+
* @async
|
|
10
|
+
* @param {Repository} repo The repo that the remote lives in
|
|
11
|
+
* @param {String|Remote} name The remote to lookup
|
|
12
|
+
* @param {Function} callback
|
|
13
|
+
* @return {Remote}
|
|
14
|
+
*/
|
|
15
|
+
Remote.lookup = lookupWrapper(Remote);
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Lists advertised references from a remote. You must connect to the remote
|
|
19
|
+
* before using referenceList.
|
|
20
|
+
*
|
|
21
|
+
* @async
|
|
22
|
+
* @return {Promise<Array<RemoteHead>>} a list of the remote heads the remote
|
|
23
|
+
* had available at the last established
|
|
24
|
+
* connection.
|
|
25
|
+
*
|
|
26
|
+
*/
|
|
27
|
+
Remote.prototype.referenceList = Remote.prototype.referenceList;
|
|
28
|
+
|
|
29
|
+
NodeGit.Remote.COMPLETION_TYPE = {};
|
|
30
|
+
var DEPRECATED_STATES = {
|
|
31
|
+
COMPLETION_DOWNLOAD: "DOWNLOAD",
|
|
32
|
+
COMPLETION_INDEXING: "INDEXING",
|
|
33
|
+
COMPLETION_ERROR: "ERROR"
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
Object.keys(DEPRECATED_STATES).forEach((key) => {
|
|
37
|
+
const newKey = DEPRECATED_STATES[key];
|
|
38
|
+
Object.defineProperty(NodeGit.Remote.COMPLETION_TYPE, key, {
|
|
39
|
+
get: util.deprecate(
|
|
40
|
+
() => NodeGit.Remote.COMPLETION[newKey],
|
|
41
|
+
`Use NodeGit.Remote.COMPLETION.${newKey} instead of ` +
|
|
42
|
+
`NodeGit.Remote.COMPLETION_TYPE.${key}.`
|
|
43
|
+
)
|
|
44
|
+
});
|
|
45
|
+
});
|