pj-nodegit 0.18.4 → 0.18.5

Sign up to get free protection for your applications and to get access to all the features.
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/reset.js ADDED
@@ -0,0 +1,76 @@
1
+ var NodeGit = require("../");
2
+ var normalizeOptions = NodeGit.Utils.normalizeOptions;
3
+
4
+ var Reset = NodeGit.Reset;
5
+ var _default = Reset.default;
6
+ var _reset = Reset.reset;
7
+ var _fromAnnotated = Reset.fromAnnotated;
8
+
9
+ /**
10
+ * Look up a refs's commit.
11
+ *
12
+ * @async
13
+ * @param {Repository} repo Repository where to perform the reset operation.
14
+ * @param {Commit|Tag} target The committish which content will be used to reset
15
+ * the content of the index.
16
+ * @param {Strarray} pathspecs List of pathspecs to operate on.
17
+ *
18
+ * @return {Number} 0 on success or an error code
19
+ */
20
+ Reset.default = function(repo, target, pathspecs) {
21
+ return _default.call(this, repo, target, pathspecs);
22
+ };
23
+
24
+ /**
25
+ * Reset a repository's current HEAD to the specified target.
26
+ *
27
+ * @async
28
+ * @param {Repository} repo Repository where to perform the reset operation.
29
+ *
30
+ * @param {Commit|Tag} target Committish to which the Head should be moved to.
31
+ * This object must belong to the given `repo` and can
32
+ * either be a git_commit or a git_tag. When a git_tag is
33
+ * being passed, it should be dereferencable to a
34
+ * git_commit which oid will be used as the target of the
35
+ * branch.
36
+ * @param {Number} resetType Kind of reset operation to perform.
37
+ *
38
+ * @param {CheckoutOptions} opts Checkout options to be used for a HARD reset.
39
+ * The checkout_strategy field will be overridden
40
+ * (based on reset_type). This parameter can be
41
+ * used to propagate notify and progress
42
+ * callbacks.
43
+ *
44
+ * @return {Number} 0 on success or an error code
45
+ */
46
+ Reset.reset = function(repo, target, resetType, opts) {
47
+ opts = normalizeOptions(opts, NodeGit.CheckoutOptions);
48
+ if (repo !== target.repo) {
49
+ // this is the same that is performed on libgit2's side
50
+ // https://github.com/nodegit/libgit2/blob/8d89e409616831b7b30a5ca7b89354957137b65e/src/reset.c#L120-L124
51
+ throw new Error("Repository and target commit's repository does not match");
52
+ }
53
+ return _reset.call(this, repo, target, resetType, opts);
54
+ };
55
+
56
+ /**
57
+ * Sets the current head to the specified commit oid and optionally
58
+ * resets the index and working tree to match.
59
+ *
60
+ * This behaves like reset but takes an annotated commit, which lets
61
+ * you specify which extended sha syntax string was specified by a
62
+ * user, allowing for more exact reflog messages.
63
+ *
64
+ * See the documentation for reset.
65
+ *
66
+ * @async
67
+ * @param {Repository} repo
68
+ * @param {AnnotatedCommit} target
69
+ * @param {Number} resetType
70
+ * @param {CheckoutOptions} opts
71
+ */
72
+ Reset.fromAnnotated = function(repo, target, resetType, opts) {
73
+ opts = normalizeOptions(opts, NodeGit.CheckoutOptions);
74
+
75
+ return _fromAnnotated.call(this, repo, target, resetType, opts);
76
+ };
package/lib/revert.js ADDED
@@ -0,0 +1,77 @@
1
+ var NodeGit = require("../");
2
+ var shallowClone = NodeGit.Utils.shallowClone;
3
+ var normalizeOptions = NodeGit.Utils.normalizeOptions;
4
+
5
+ var Revert = NodeGit.Revert;
6
+ var _commit = Revert.commit;
7
+ var _revert = Revert.revert;
8
+
9
+ /**
10
+ * Reverts the given commit against the given "our" commit, producing an index
11
+ * that reflects the result of the revert.
12
+ *
13
+ * @async
14
+ * @param {Repository} repo the repository that contains the given commits.
15
+ * @param {Commit} revert_commit the commit to revert
16
+ * @param {Commit} our_commit the commit to revert against (e.g. HEAD)
17
+ * @param {Number} mainline the parent of the revert commit, if it is a merge
18
+ * @param {MergeOptions} merge_options the merge options (or null for defaults)
19
+ *
20
+ * @return {Index} the index result
21
+ */
22
+ Revert.commit = function(
23
+ repo,
24
+ revert_commit,
25
+ our_commit,
26
+ mainline,
27
+ merge_options
28
+ )
29
+ {
30
+ merge_options = normalizeOptions(merge_options, NodeGit.MergeOptions);
31
+
32
+ return _commit.call(
33
+ this,
34
+ repo,
35
+ revert_commit,
36
+ our_commit,
37
+ mainline,
38
+ merge_options
39
+ );
40
+ };
41
+
42
+ /**
43
+ * Reverts the given commit, producing changes in the index and
44
+ * working directory.
45
+ *
46
+ * @async
47
+ * @param {Repository} repo the repository to perform the revert in
48
+ * @param {Commit} commit the commit to revert
49
+ * @param {RevertOptions} revert_options the revert options
50
+ * (or null for defaults)
51
+ */
52
+ Revert.revert = function(repo, commit, revertOpts) {
53
+ var mergeOpts;
54
+ var checkoutOpts;
55
+
56
+ if (revertOpts) {
57
+ revertOpts = shallowClone(revertOpts);
58
+ mergeOpts = revertOpts.mergeOpts;
59
+ checkoutOpts = revertOpts.checkoutOpts;
60
+ delete revertOpts.mergeOpts;
61
+ delete revertOpts.checkoutOpts;
62
+ }
63
+
64
+ revertOpts = normalizeOptions(revertOpts, NodeGit.RevertOptions);
65
+
66
+ if (mergeOpts) {
67
+ revertOpts.mergeOpts =
68
+ normalizeOptions(mergeOpts, NodeGit.MergeOptions);
69
+ }
70
+
71
+ if (checkoutOpts) {
72
+ revertOpts.checkoutOpts =
73
+ normalizeOptions(checkoutOpts, NodeGit.CheckoutOptions);
74
+ }
75
+
76
+ return _revert.call(this, repo, commit, revertOpts);
77
+ };
package/lib/revwalk.js ADDED
@@ -0,0 +1,142 @@
1
+ var NodeGit = require("../");
2
+ var Revwalk = NodeGit.Revwalk;
3
+
4
+ Object.defineProperty(Revwalk.prototype, "repo", {
5
+ get: function () { return this.repository(); },
6
+ configurable: true
7
+ });
8
+
9
+ var _sorting = Revwalk.prototype.sorting;
10
+ /**
11
+ * @typedef historyEntry
12
+ * @type {Object}
13
+ * @property {Commit} commit the commit for this entry
14
+ * @property {Number} status the status of the file in the commit
15
+ * @property {String} newName the new name that is provided when status is
16
+ * renamed
17
+ * @property {String} oldName the old name that is provided when status is
18
+ * renamed
19
+ */
20
+ var fileHistoryWalk = Revwalk.prototype.fileHistoryWalk;
21
+ /**
22
+ * @param {String} filePath
23
+ * @param {Number} max_count
24
+ * @async
25
+ * @return {Array<historyEntry>}
26
+ */
27
+ Revwalk.prototype.fileHistoryWalk = fileHistoryWalk;
28
+
29
+ /**
30
+ * Get a number of commits.
31
+ *
32
+ * @async
33
+ * @param {Number} count (default: 10)
34
+ * @return {Array<Commit>}
35
+ */
36
+ Revwalk.prototype.getCommits = function(count) {
37
+ count = count || 10;
38
+ var promises = [];
39
+ var walker = this;
40
+
41
+ function walkCommitsCount(count) {
42
+ if (count === 0) { return; }
43
+
44
+ return walker.next().then(function(oid) {
45
+ promises.push(walker.repo.getCommit(oid));
46
+ return walkCommitsCount(count - 1);
47
+ })
48
+ .catch(function(error) {
49
+ if (error.errno !== NodeGit.Error.CODE.ITEROVER) {
50
+ throw error;
51
+ }
52
+ });
53
+ }
54
+
55
+ return walkCommitsCount(count).then(function() {
56
+ return Promise.all(promises);
57
+ });
58
+ };
59
+
60
+ /**
61
+ * Walk the history grabbing commits until the checkFn called with the
62
+ * current commit returns false.
63
+ *
64
+ * @async
65
+ * @param {Function} checkFn function returns false to stop walking
66
+ * @return {Array}
67
+ */
68
+ Revwalk.prototype.getCommitsUntil = function(checkFn) {
69
+ var commits = [];
70
+ var walker = this;
71
+
72
+ function walkCommitsCb() {
73
+ return walker.next().then(function(oid) {
74
+ return walker.repo.getCommit(oid).then(function(commit) {
75
+ commits.push(commit);
76
+ if (checkFn(commit)) {
77
+ return walkCommitsCb();
78
+ }
79
+ });
80
+ })
81
+ .catch(function(error) {
82
+ if (error.errno !== NodeGit.Error.CODE.ITEROVER) {
83
+ throw error;
84
+ }
85
+ });
86
+ }
87
+
88
+ return walkCommitsCb().then(function() {
89
+ return commits;
90
+ });
91
+ };
92
+
93
+ /**
94
+ * Set the sort order for the revwalk. This function takes variable arguments
95
+ * like `revwalk.sorting(NodeGit.RevWalk.Topological, NodeGit.RevWalk.Reverse).`
96
+ *
97
+ * @param {Number} sort
98
+ */
99
+ Revwalk.prototype.sorting = function() {
100
+ var sort = 0;
101
+
102
+ for (var i = 0; i < arguments.length; i++) {
103
+ sort |= arguments[i];
104
+ }
105
+
106
+ _sorting.call(this, sort);
107
+ };
108
+
109
+ /**
110
+ * Walk the history from the given oid. The callback is invoked for each commit;
111
+ * When the walk is over, the callback is invoked with `(null, null)`.
112
+ *
113
+ * @param {Oid} oid
114
+ * @param {Function} callback
115
+ */
116
+ Revwalk.prototype.walk = function(oid, callback) {
117
+ var revwalk = this;
118
+
119
+ this.push(oid);
120
+
121
+ function walk() {
122
+ revwalk.next().then(function(oid) {
123
+ if (!oid) {
124
+ if (typeof callback === "function") {
125
+ return callback();
126
+ }
127
+
128
+ return;
129
+ }
130
+
131
+ revwalk.repo.getCommit(oid).then(function(commit) {
132
+ if (typeof callback === "function") {
133
+ callback(null, commit);
134
+ }
135
+
136
+ walk();
137
+ });
138
+ }, callback);
139
+ }
140
+
141
+ walk();
142
+ };
@@ -0,0 +1,38 @@
1
+ var NodeGit = require("../");
2
+ var Signature = NodeGit.Signature;
3
+
4
+ const toPaddedDoubleDigitString = (number) => {
5
+ if (number < 10) {
6
+ return `0${number}`;
7
+ }
8
+
9
+ return `${number}`;
10
+ };
11
+
12
+ /**
13
+ * Standard string representation of an author.
14
+ * @param {Boolean} withTime Whether or not to include timestamp
15
+ * @return {String} Representation of the author.
16
+ */
17
+ Signature.prototype.toString = function(withTime) {
18
+ const name = this.name().toString();
19
+ const email = this.email().toString();
20
+
21
+ let stringifiedSignature = `${name} <${email}>`;
22
+
23
+ if (!withTime) {
24
+ return stringifiedSignature;
25
+ }
26
+
27
+ const when = this.when();
28
+ const offset = when.offset();
29
+ const offsetMagnitude = Math.abs(offset);
30
+ const time = when.time();
31
+
32
+ const sign = (offset < 0 || when.sign() === "-") ? "-" : "+";
33
+ const hours = toPaddedDoubleDigitString(Math.floor(offsetMagnitude / 60));
34
+ const minutes = toPaddedDoubleDigitString(offsetMagnitude % 60);
35
+
36
+ stringifiedSignature += ` ${time} ${sign}${hours}${minutes}`;
37
+ return stringifiedSignature;
38
+ };
package/lib/stash.js ADDED
@@ -0,0 +1,62 @@
1
+ var NodeGit = require("../");
2
+ var normalizeOptions = NodeGit.Utils.normalizeOptions;
3
+ var shallowClone = NodeGit.Utils.shallowClone;
4
+ var Stash = NodeGit.Stash;
5
+
6
+ var _apply = Stash.apply;
7
+ var _foreach = Stash.foreach;
8
+ var _pop = Stash.pop;
9
+
10
+ Stash.apply = function(repo, index, options) {
11
+ var checkoutOptions;
12
+
13
+ if (options) {
14
+ options = shallowClone(options);
15
+ checkoutOptions = options.checkoutOptions;
16
+ delete options.checkoutOptions;
17
+ } else {
18
+ options = {};
19
+ }
20
+
21
+ options = normalizeOptions(options, NodeGit.StashApplyOptions);
22
+
23
+ if (checkoutOptions) {
24
+ options.checkoutOptions =
25
+ normalizeOptions(checkoutOptions, NodeGit.CheckoutOptions);
26
+ }
27
+
28
+ return _apply(repo, index, options);
29
+ };
30
+
31
+ // Override Stash.foreach to eliminate the need to pass null payload
32
+ Stash.foreach = function(repo, callback) {
33
+ function wrappedCallback(index, message, oid) {
34
+ // We need to copy the OID since libgit2 types are getting cleaned up
35
+ // incorrectly right now in callbacks
36
+
37
+ return callback(index, message, oid.copy());
38
+ }
39
+
40
+ return _foreach(repo, wrappedCallback, null);
41
+ };
42
+
43
+ Stash.pop = function(repo, index, options) {
44
+ var checkoutOptions;
45
+
46
+ if (options) {
47
+ options = shallowClone(options);
48
+ checkoutOptions = options.checkoutOptions;
49
+ delete options.checkoutOptions;
50
+ } else {
51
+ options = {};
52
+ }
53
+
54
+ options = normalizeOptions(options, NodeGit.StashApplyOptions);
55
+
56
+ if (checkoutOptions) {
57
+ options.checkoutOptions =
58
+ normalizeOptions(checkoutOptions, NodeGit.CheckoutOptions);
59
+ }
60
+
61
+ return _pop(repo, index, options);
62
+ };
package/lib/status.js ADDED
@@ -0,0 +1,18 @@
1
+ var NodeGit = require("../");
2
+ var normalizeOptions = NodeGit.Utils.normalizeOptions;
3
+
4
+ var Status = NodeGit.Status;
5
+
6
+ var _foreach = Status.foreach;
7
+ var _foreachExt = Status.foreachExt;
8
+
9
+ // Override Status.foreach to eliminate the need to pass null payload
10
+ Status.foreach = function(repo, callback) {
11
+ return _foreach(repo, callback, null);
12
+ };
13
+
14
+ // Override Status.foreachExt to normalize opts
15
+ Status.foreachExt = function(repo, opts, callback) {
16
+ opts = normalizeOptions(opts, NodeGit.StatusOptions);
17
+ return _foreachExt(repo, opts, callback, null);
18
+ };
@@ -0,0 +1,106 @@
1
+ var NodeGit = require("../");
2
+ var Status = NodeGit.Status;
3
+
4
+ var StatusFile = function(args) {
5
+ var path = args.path;
6
+ var status = args.status;
7
+ var entry = args.entry;
8
+
9
+ if (entry) {
10
+ status = entry.status();
11
+ if (entry.indexToWorkdir()) {
12
+ path = entry.indexToWorkdir().newFile().path();
13
+ } else {
14
+ path = entry.headToIndex().newFile().path();
15
+ }
16
+ }
17
+
18
+ var codes = Status.STATUS;
19
+
20
+ var getStatus = function() {
21
+ var fileStatuses = [];
22
+
23
+ for(var key in Status.STATUS) {
24
+ if (status & Status.STATUS[key]) {
25
+ fileStatuses.push(key);
26
+ }
27
+ }
28
+
29
+ return fileStatuses;
30
+ };
31
+
32
+ var data = {
33
+ path: path,
34
+ entry: entry,
35
+ statusBit: status,
36
+ statuses: getStatus()
37
+ };
38
+
39
+ return {
40
+ headToIndex: function() {
41
+ if (data.entry) {
42
+ return entry.headToIndex();
43
+ } else {
44
+ return undefined;
45
+ }
46
+ },
47
+ indexToWorkdir: function() {
48
+ if (data.entry) {
49
+ return entry.indexToWorkdir();
50
+ } else {
51
+ return undefined;
52
+ }
53
+ },
54
+ inIndex: function() {
55
+ return status & codes.INDEX_NEW ||
56
+ status & codes.INDEX_MODIFIED ||
57
+ status & codes.INDEX_DELETED ||
58
+ status & codes.INDEX_TYPECHANGE ||
59
+ status & codes.INDEX_RENAMED;
60
+ },
61
+ inWorkingTree: function() {
62
+ return status & codes.WT_NEW ||
63
+ status & codes.WT_MODIFIED ||
64
+ status & codes.WT_DELETED ||
65
+ status & codes.WT_TYPECHANGE ||
66
+ status & codes.WT_RENAMED;
67
+ },
68
+ isConflicted: function() {
69
+ return status & codes.CONFLICTED;
70
+ },
71
+ isDeleted: function() {
72
+ return status & codes.WT_DELETED ||
73
+ status & codes.INDEX_DELETED;
74
+ },
75
+ isIgnored: function() {
76
+ return status & codes.IGNORED;
77
+ },
78
+ isModified: function() {
79
+ return status & codes.WT_MODIFIED ||
80
+ status & codes.INDEX_MODIFIED;
81
+ },
82
+ isNew: function() {
83
+ return status & codes.WT_NEW ||
84
+ status & codes.INDEX_NEW;
85
+ },
86
+ isRenamed: function() {
87
+ return status & codes.WT_RENAMED ||
88
+ status & codes.INDEX_RENAMED;
89
+ },
90
+ isTypechange: function() {
91
+ return status & codes.WT_TYPECHANGE ||
92
+ status & codes.INDEX_TYPECHANGE;
93
+ },
94
+ path: function() {
95
+ return data.path;
96
+ },
97
+ status: function() {
98
+ return data.statuses;
99
+ },
100
+ statusBit: function() {
101
+ return data.statusBit;
102
+ }
103
+ };
104
+ };
105
+
106
+ NodeGit.StatusFile = StatusFile;
@@ -0,0 +1,12 @@
1
+ var NodeGit = require("../");
2
+ var normalizeOptions = NodeGit.Utils.normalizeOptions;
3
+
4
+ var StatusList = NodeGit.StatusList;
5
+
6
+ var _create = StatusList.create;
7
+
8
+ // Override StatusList.create to normalize opts
9
+ StatusList.create = function(repo, opts) {
10
+ opts = normalizeOptions(opts, NodeGit.StatusOptions);
11
+ return _create(repo, opts);
12
+ };
@@ -0,0 +1,51 @@
1
+ var NodeGit = require("../");
2
+ var normalizeFetchOptions = NodeGit.Utils.normalizeFetchOptions;
3
+ var normalizeOptions = NodeGit.Utils.normalizeOptions;
4
+ var shallowClone = NodeGit.Utils.shallowClone;
5
+
6
+ var Submodule = NodeGit.Submodule;
7
+
8
+ var _foreach = Submodule.foreach;
9
+ var _update = Submodule.prototype.update;
10
+
11
+ // Override Submodule.foreach to eliminate the need to pass null payload
12
+ Submodule.foreach = function(repo, callback) {
13
+ return _foreach(repo, callback, null);
14
+ };
15
+
16
+ /**
17
+ * Updates a submodule
18
+ *
19
+ * @async
20
+ * @param {Number} init Setting this to 1 will initialize submodule
21
+ * before updating
22
+ * @param {SubmoduleUpdateOptions} options Submodule update settings
23
+ * @return {Number} 0 on success, any non-zero return value from a callback
24
+ */
25
+ Submodule.prototype.update = function(init, options) {
26
+ var fetchOpts;
27
+ var checkoutOpts;
28
+
29
+ if (options) {
30
+ options = shallowClone(options);
31
+ fetchOpts = options.fetchOpts;
32
+ checkoutOpts = options.checkoutOpts;
33
+ delete options.fetchOpts;
34
+ delete options.checkoutOpts;
35
+ }
36
+
37
+ options = normalizeOptions(options, NodeGit.SubmoduleUpdateOptions);
38
+
39
+ if (fetchOpts) {
40
+ options.fetchOpts = normalizeFetchOptions(fetchOpts);
41
+ }
42
+
43
+ if (checkoutOpts) {
44
+ options.checkoutOpts = normalizeOptions(
45
+ checkoutOpts,
46
+ NodeGit.CheckoutOptions
47
+ );
48
+ }
49
+
50
+ return _update.call(this, init, options);
51
+ };