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.
Files changed (49) hide show
  1. package/lib/README.md +3 -0
  2. package/lib/attr.js +20 -0
  3. package/lib/blame.js +20 -0
  4. package/lib/blob.js +73 -0
  5. package/lib/branch.js +19 -0
  6. package/lib/buf.js +11 -0
  7. package/lib/checkout.js +51 -0
  8. package/lib/cherrypick.js +73 -0
  9. package/lib/clone.js +33 -0
  10. package/lib/commit.js +437 -0
  11. package/lib/config.js +25 -0
  12. package/lib/convenient_hunks.js +61 -0
  13. package/lib/convenient_patch.js +131 -0
  14. package/lib/credential.js +33 -0
  15. package/lib/diff.js +113 -0
  16. package/lib/diff_file.js +38 -0
  17. package/lib/diff_line.js +32 -0
  18. package/lib/enums.js +689 -0
  19. package/lib/error.js +17 -0
  20. package/lib/filter_registry.js +25 -0
  21. package/lib/index.js +103 -0
  22. package/lib/libgit2.js +6 -0
  23. package/lib/merge.js +72 -0
  24. package/lib/nodegit.js +1333 -0
  25. package/lib/note.js +17 -0
  26. package/lib/object.js +45 -0
  27. package/lib/odb_object.js +9 -0
  28. package/lib/oid.js +23 -0
  29. package/lib/rebase.js +142 -0
  30. package/lib/reference.js +213 -0
  31. package/lib/remote.js +270 -0
  32. package/lib/repository.js +1982 -0
  33. package/lib/reset.js +76 -0
  34. package/lib/revert.js +77 -0
  35. package/lib/revwalk.js +142 -0
  36. package/lib/signature.js +38 -0
  37. package/lib/stash.js +62 -0
  38. package/lib/status.js +18 -0
  39. package/lib/status_file.js +106 -0
  40. package/lib/status_list.js +12 -0
  41. package/lib/submodule.js +51 -0
  42. package/lib/tag.js +135 -0
  43. package/lib/tree.js +175 -0
  44. package/lib/tree_entry.js +99 -0
  45. package/lib/utils/lookup_wrapper.js +39 -0
  46. package/lib/utils/normalize_fetch_options.js +43 -0
  47. package/lib/utils/normalize_options.js +29 -0
  48. package/lib/utils/shallow_clone.js +14 -0
  49. package/package.json +1 -1
package/lib/tag.js ADDED
@@ -0,0 +1,135 @@
1
+ var NodeGit = require("../");
2
+ var LookupWrapper = NodeGit.Utils.lookupWrapper;
3
+ var Tag = NodeGit.Tag;
4
+
5
+ const signatureRegexesBySignatureType = {
6
+ gpgsig: [
7
+ /-----BEGIN PGP SIGNATURE-----[\s\S]+?-----END PGP SIGNATURE-----/gm,
8
+ /-----BEGIN PGP MESSAGE-----[\s\S]+?-----END PGP MESSAGE-----/gm,
9
+ ],
10
+ x509: [
11
+ /-----BEGIN SIGNED MESSAGE-----[\s\S]+?-----END SIGNED MESSAGE-----/gm,
12
+ ]
13
+ };
14
+
15
+ /**
16
+ * Retrieves the tag pointed to by the oid
17
+ * @async
18
+ * @param {Repository} repo The repo that the tag lives in
19
+ * @param {String|Oid|Tag} id The tag to lookup
20
+ * @return {Tag}
21
+ */
22
+ Tag.lookup = LookupWrapper(Tag);
23
+
24
+ /**
25
+ * @async
26
+ * @param {Repository} repo
27
+ * @param {String} tagName
28
+ * @param {Oid} target
29
+ * @param {Signature} tagger
30
+ * @return {String}
31
+ */
32
+ Tag.createBuffer = function(repo, tagName, target, tagger, message) {
33
+ return NodeGit.Object.lookup(repo, target, NodeGit.Object.TYPE.ANY)
34
+ .then((object) => {
35
+ if (!NodeGit.Object.typeisloose(object.type())) {
36
+ throw new Error("Object must be a loose type");
37
+ }
38
+
39
+ const id = object.id().toString();
40
+ const objectType = NodeGit.Object.type2String(object.type());
41
+ const lines = [
42
+ `object ${id}`,
43
+ `type ${objectType}`,
44
+ `tag ${tagName}`,
45
+ `tagger ${tagger.toString(true)}\n`,
46
+ `${message}${message.endsWith("\n") ? "" : "\n"}`
47
+ ];
48
+ return lines.join("\n");
49
+ });
50
+ };
51
+
52
+ /**
53
+ * @async
54
+ * @param {Repository} repo
55
+ * @param {String} tagName
56
+ * @param {Oid} target
57
+ * @param {Signature} tagger
58
+ * @param {String} message
59
+ * @param {Number} force
60
+ * @param {Function} signingCallback Takes a string and returns a string
61
+ * representing the signed message
62
+ * @return {Oid}
63
+ */
64
+ Tag.createWithSignature = function(
65
+ repo,
66
+ tagName,
67
+ target,
68
+ tagger,
69
+ message,
70
+ force,
71
+ signingCallback
72
+ ) {
73
+ let tagBuffer;
74
+ return Tag.createBuffer(repo, tagName, target, tagger, message)
75
+ .then((tagBufferResult) => {
76
+ tagBuffer = tagBufferResult;
77
+ return signingCallback(tagBuffer);
78
+ })
79
+ .then(({ code, signedData }) => {
80
+ switch (code) {
81
+ case NodeGit.Error.CODE.OK: {
82
+ const normalizedEnding = signedData.endsWith("\n") ? "" : "\n";
83
+ const signedTagString = tagBuffer + signedData + normalizedEnding;
84
+ return Tag.createFromBuffer(repo, signedTagString, force);
85
+ }
86
+ case NodeGit.Error.CODE.PASSTHROUGH:
87
+ return Tag.create(
88
+ repo,
89
+ tagName,
90
+ target,
91
+ tagger,
92
+ message,
93
+ force
94
+ );
95
+ default: {
96
+ const error = new Error(
97
+ `Tag.createWithSignature threw with error code ${code}`
98
+ );
99
+ error.errno = code;
100
+ throw error;
101
+ }
102
+ }
103
+ });
104
+ };
105
+
106
+ /**
107
+ * Retrieves the signature of an annotated tag
108
+ * @async
109
+ * @param {String} signatureType
110
+ * @return {String|null}
111
+ */
112
+ Tag.prototype.extractSignature = function(signatureType = "gpgsig") {
113
+ const id = this.id();
114
+ const repo = this.repo;
115
+ const signatureRegexes = signatureRegexesBySignatureType[signatureType];
116
+ if (!signatureRegexes) {
117
+ throw new Error("Unsupported signature type");
118
+ }
119
+
120
+ return repo.odb().then((odb) => {
121
+ return odb.read(id);
122
+ }).then((odbObject) => {
123
+ const odbData = odbObject.toString();
124
+
125
+ for (const regex of signatureRegexes) {
126
+ const matchResult = odbData.match(regex);
127
+
128
+ if (matchResult !== null) {
129
+ return matchResult[0];
130
+ }
131
+ }
132
+
133
+ throw new Error("this tag is not signed");
134
+ });
135
+ };
package/lib/tree.js ADDED
@@ -0,0 +1,175 @@
1
+ var path = require("path");
2
+ var events = require("events");
3
+ var NodeGit = require("../");
4
+ var Diff = NodeGit.Diff;
5
+ var LookupWrapper = NodeGit.Utils.lookupWrapper;
6
+ var Tree = NodeGit.Tree;
7
+ var Treebuilder = NodeGit.Treebuilder;
8
+
9
+ /**
10
+ * Retrieves the tree pointed to by the oid
11
+ * @async
12
+ * @param {Repository} repo The repo that the tree lives in
13
+ * @param {String|Oid|Tree} id The tree to lookup
14
+ * @return {Tree}
15
+ */
16
+ Tree.lookup = LookupWrapper(Tree);
17
+
18
+ /**
19
+ * Make builder. This is helpful for modifying trees.
20
+ * @return {Treebuilder}
21
+ */
22
+ Tree.prototype.builder = function() {
23
+ var builder = Treebuilder.create(this);
24
+
25
+ builder.root = builder;
26
+ builder.repo = this.repo;
27
+
28
+ return builder;
29
+ };
30
+
31
+ /**
32
+ * Diff two trees
33
+ * @async
34
+ * @param {Tree} tree to diff against
35
+ * @return {Diff}
36
+ */
37
+ Tree.prototype.diff = function(tree) {
38
+ return this.diffWithOptions(tree, null);
39
+ };
40
+
41
+ /**
42
+ * Diff two trees with options
43
+ * @async
44
+ * @param {Tree} tree to diff against
45
+ * @param {Object} options
46
+ * @return {Diff}
47
+ */
48
+ Tree.prototype.diffWithOptions = function(tree, options) {
49
+ return Diff.treeToTree(this.repo, tree, this, options);
50
+ };
51
+
52
+ /**
53
+ * Return an array of the entries in this tree (excluding its children).
54
+ * @return {Array<TreeEntry>} an array of TreeEntrys
55
+ */
56
+ Tree.prototype.entries = function() {
57
+ var size = this.entryCount();
58
+ var result = [];
59
+
60
+ for (var i = 0; i < size; i++) {
61
+ result.push(this.entryByIndex(i));
62
+ }
63
+
64
+ return result;
65
+ };
66
+
67
+ /**
68
+ * Get an entry at the ith position.
69
+ *
70
+ * @param {Number} i
71
+ * @return {TreeEntry}
72
+ */
73
+ Tree.prototype.entryByIndex = function(i) {
74
+ var entry = this._entryByIndex(i);
75
+ entry.parent = this;
76
+ return entry;
77
+ };
78
+
79
+ /**
80
+ * Get an entry by name; if the tree is a directory, the name is the filename.
81
+ *
82
+ * @param {String} name
83
+ * @return {TreeEntry}
84
+ */
85
+ Tree.prototype.entryByName = function(name) {
86
+ var entry = this._entryByName(name);
87
+ entry.parent = this;
88
+ return entry;
89
+ };
90
+
91
+ /**
92
+ * Get an entry at a path. Unlike by name, this takes a fully
93
+ * qualified path, like `/foo/bar/baz.javascript`
94
+ * @async
95
+ * @param {String} filePath
96
+ * @return {TreeEntry}
97
+ */
98
+ Tree.prototype.getEntry = function(filePath) {
99
+ var tree = this;
100
+
101
+ return this.entryByPath(filePath).then(function(entry) {
102
+ entry.parent = tree;
103
+ entry.dirtoparent = path.dirname(filePath);
104
+ return entry;
105
+ });
106
+ };
107
+
108
+ /**
109
+ * Return the path of this tree, like `/lib/foo/bar`
110
+ * @return {String}
111
+ */
112
+ Tree.prototype.path = function(blobsOnly) {
113
+ return this.entry ? this.entry.path() : "";
114
+ };
115
+
116
+ /**
117
+ * Recursively walk the tree in breadth-first order. Fires an event for each
118
+ * entry.
119
+ *
120
+ * @fires EventEmitter#entry Tree
121
+ * @fires EventEmitter#end Array<Tree>
122
+ * @fires EventEmitter#error Error
123
+ *
124
+ * @param {Boolean} [blobsOnly = true] True to emit only blob & blob executable
125
+ * entries.
126
+ *
127
+ * @return {EventEmitter}
128
+ */
129
+ Tree.prototype.walk = function(blobsOnly) {
130
+ blobsOnly = typeof blobsOnly === "boolean" ? blobsOnly : true;
131
+
132
+ var self = this;
133
+ var event = new events.EventEmitter();
134
+
135
+ var total = 1;
136
+ var entries = new Set();
137
+ var finalEntires = [];
138
+
139
+ // This looks like a DFS, but it is a BFS because of implicit queueing in
140
+ // the recursive call to `entry.getTree(bfs)`
141
+ function bfs(error, tree) {
142
+ total--;
143
+
144
+ if (error) {
145
+ return event.emit("error", error);
146
+ }
147
+
148
+ tree.entries().forEach(function (entry, entryIndex) {
149
+ if (!blobsOnly || entry.isFile() && !entries.has(entry)) {
150
+ event.emit("entry", entry);
151
+ entries.add(entry);
152
+
153
+ // Node 0.12 doesn't support either [v for (v of entries)] nor
154
+ // Array.from so we'll just maintain our own list.
155
+ finalEntires.push(entry);
156
+ }
157
+
158
+ if (entry.isTree()) {
159
+ total++;
160
+ entry.getTree()
161
+ .then(result => bfs(null, result), bfs);
162
+ }
163
+ });
164
+
165
+ if (total === 0) {
166
+ event.emit("end", finalEntires);
167
+ }
168
+ }
169
+
170
+ event.start = function() {
171
+ bfs(null, self);
172
+ };
173
+
174
+ return event;
175
+ };
@@ -0,0 +1,99 @@
1
+ var path = require("path").posix;
2
+ var NodeGit = require("../");
3
+ var TreeEntry = NodeGit.TreeEntry;
4
+
5
+ /**
6
+ * Retrieve the blob for this entry. Make sure to call `isBlob` first!
7
+ * @async
8
+ * @return {Blob}
9
+ */
10
+ TreeEntry.prototype.getBlob = function() {
11
+ return this.parent.repo.getBlob(this.id());
12
+ };
13
+
14
+ /**
15
+ * Retrieve the tree for this entry. Make sure to call `isTree` first!
16
+ * @async
17
+ * @return {Tree}
18
+ */
19
+ TreeEntry.prototype.getTree = function() {
20
+ var entry = this;
21
+
22
+ return this.parent.repo.getTree(this.id()).then(function(tree) {
23
+ tree.entry = entry;
24
+ return tree;
25
+ });
26
+ };
27
+
28
+ /**
29
+ * Is this TreeEntry a blob? Alias for `isFile`
30
+ * @return {Boolean}
31
+ */
32
+ TreeEntry.prototype.isBlob = function() {
33
+ return this.isFile();
34
+ };
35
+
36
+ /**
37
+ * Is this TreeEntry a directory? Alias for `isTree`
38
+ * @return {Boolean}
39
+ */
40
+ TreeEntry.prototype.isDirectory = function() {
41
+ return this.isTree();
42
+ };
43
+
44
+ /**
45
+ * Is this TreeEntry a blob? (i.e., a file)
46
+ * @return {Boolean}
47
+ */
48
+ TreeEntry.prototype.isFile = function() {
49
+ return this.filemode() === TreeEntry.FILEMODE.BLOB ||
50
+ this.filemode() === TreeEntry.FILEMODE.EXECUTABLE;
51
+ };
52
+
53
+ /**
54
+ * Is this TreeEntry a submodule?
55
+ * @return {Boolean}
56
+ */
57
+ TreeEntry.prototype.isSubmodule = function() {
58
+ return this.filemode() === TreeEntry.FILEMODE.COMMIT;
59
+ };
60
+
61
+ /**
62
+ * Is this TreeEntry a tree? (i.e., a directory)
63
+ * @return {Boolean}
64
+ */
65
+ TreeEntry.prototype.isTree = function() {
66
+ return this.filemode() === TreeEntry.FILEMODE.TREE;
67
+ };
68
+
69
+ /**
70
+ * Retrieve the SHA for this TreeEntry. Alias for `sha`
71
+ * @return {String}
72
+ */
73
+ TreeEntry.prototype.oid = function() {
74
+ return this.sha();
75
+ };
76
+
77
+ /**
78
+ * Returns the path for this entry.
79
+ * @return {String}
80
+ */
81
+ TreeEntry.prototype.path = function() {
82
+ var dirtoparent = this.dirtoparent || "";
83
+ return path.join(this.parent.path(), dirtoparent, this.name());
84
+ };
85
+
86
+ /**
87
+ * Retrieve the SHA for this TreeEntry.
88
+ * @return {String}
89
+ */
90
+ TreeEntry.prototype.sha = function() {
91
+ return this.id().toString();
92
+ };
93
+
94
+ /**
95
+ * Alias for `path`
96
+ */
97
+ TreeEntry.prototype.toString = function() {
98
+ return this.path();
99
+ };
@@ -0,0 +1,39 @@
1
+ var NodeGit = require("../../");
2
+
3
+ /**
4
+ * Wraps a method so that you can pass in either a string, OID or the object
5
+ * itself and you will always get back a promise that resolves to the object.
6
+ * @param {Object} objectType The object type that you're expecting to receive.
7
+ * @param {Function} lookupFunction The function to do the lookup for the
8
+ * object. Defaults to `objectType.lookup`.
9
+ * @return {Function}
10
+ */
11
+ function lookupWrapper(objectType, lookupFunction) {
12
+ lookupFunction = lookupFunction || objectType.lookup;
13
+
14
+ return function(repo, id, callback) {
15
+ if (id instanceof objectType) {
16
+ return Promise.resolve(id).then(function(obj) {
17
+ obj.repo = repo;
18
+
19
+ if (typeof callback === "function") {
20
+ callback(null, obj);
21
+ }
22
+
23
+ return obj;
24
+ }, callback);
25
+ }
26
+
27
+ return lookupFunction(repo, id).then(function(obj) {
28
+ obj.repo = repo;
29
+
30
+ if (typeof callback === "function") {
31
+ callback(null, obj);
32
+ }
33
+
34
+ return obj;
35
+ }, callback);
36
+ };
37
+ }
38
+
39
+ NodeGit.Utils.lookupWrapper = lookupWrapper;
@@ -0,0 +1,43 @@
1
+ var NodeGit = require("../../");
2
+ var normalizeOptions = NodeGit.Utils.normalizeOptions;
3
+ var shallowClone = NodeGit.Utils.shallowClone;
4
+
5
+ /**
6
+ * Normalize an object to match a struct.
7
+ *
8
+ * @param {String, Object} oid - The oid string or instance.
9
+ * @return {Object} An Oid instance.
10
+ */
11
+ function normalizeFetchOptions(options) {
12
+ if (options instanceof NodeGit.FetchOptions) {
13
+ return options;
14
+ }
15
+
16
+ var callbacks;
17
+ var proxyOpts;
18
+
19
+ if (options) {
20
+ options = shallowClone(options);
21
+ callbacks = options.callbacks;
22
+ proxyOpts = options.proxyOpts;
23
+ delete options.callbacks;
24
+ delete options.proxyOpts;
25
+ } else {
26
+ options = {};
27
+ }
28
+
29
+ options = normalizeOptions(options, NodeGit.FetchOptions);
30
+
31
+ if (callbacks) {
32
+ options.callbacks =
33
+ normalizeOptions(callbacks, NodeGit.RemoteCallbacks);
34
+ }
35
+
36
+ if (proxyOpts) {
37
+ options.proxyOpts =
38
+ normalizeOptions(proxyOpts, NodeGit.ProxyOptions);
39
+ }
40
+ return options;
41
+ }
42
+
43
+ NodeGit.Utils.normalizeFetchOptions = normalizeFetchOptions;
@@ -0,0 +1,29 @@
1
+ var NodeGit = require("../../");
2
+
3
+ /**
4
+ * Normalize an object to match a struct.
5
+ *
6
+ * @param {String, Object} oid - The oid string or instance.
7
+ * @return {Object} An Oid instance.
8
+ */
9
+ function normalizeOptions(options, Ctor) {
10
+ if (!options) {
11
+ return null;
12
+ }
13
+
14
+ if (options instanceof Ctor) {
15
+ return options;
16
+ }
17
+
18
+ var instance = new Ctor();
19
+
20
+ Object.keys(options).forEach(function(key) {
21
+ if (typeof options[key] !== "undefined") {
22
+ instance[key] = options[key];
23
+ }
24
+ });
25
+
26
+ return instance;
27
+ }
28
+
29
+ NodeGit.Utils.normalizeOptions = normalizeOptions;
@@ -0,0 +1,14 @@
1
+ var NodeGit = require("../../");
2
+
3
+ function shallowClone() {
4
+ var merges = Array.prototype.slice.call(arguments);
5
+
6
+ return merges.reduce(function(obj, merge) {
7
+ return Object.keys(merge).reduce(function(obj, key) {
8
+ obj[key] = merge[key];
9
+ return obj;
10
+ }, obj);
11
+ }, {});
12
+ }
13
+
14
+ NodeGit.Utils.shallowClone = shallowClone;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "pj-nodegit",
3
3
  "description": "Node.js libgit2 asynchronous native bindings",
4
- "version": "0.18.4",
4
+ "version": "0.18.5",
5
5
  "homepage": "http://nodegit.org",
6
6
  "keywords": [
7
7
  "libgit2",