Initial commit

This commit is contained in:
jiapengyu
2026-07-27 13:37:48 +08:00
commit ecba71e2a5
39123 changed files with 5989154 additions and 0 deletions
+21
View File
@@ -0,0 +1,21 @@
"use strict";
var util = require("util");
var NodeGit = require("../");
NodeGit.Attr.STATES = {};
var DEPRECATED_STATES = {
UNSPECIFIED_T: "UNSPECIFIED",
TRUE_T: "TRUE",
FALSE_T: "FALSE",
VALUE_T: "STRING"
};
Object.keys(DEPRECATED_STATES).forEach(function (key) {
var newKey = DEPRECATED_STATES[key];
Object.defineProperty(NodeGit.Attr.STATES, key, {
get: util.deprecate(function () {
return NodeGit.Attr.VALUE[newKey];
}, "Use NodeGit.Attr.VALUE." + newKey + " instead of NodeGit.Attr.STATES." + key + ".")
});
});
+22
View File
@@ -0,0 +1,22 @@
"use strict";
var NodeGit = require("../");
var normalizeOptions = NodeGit.Utils.normalizeOptions;
var Blame = NodeGit.Blame;
var _file = Blame.file;
/**
* Retrieve the blame of a file
*
* @async
* @param {Repository} repo that contains the file
* @param {String} path to the file to get the blame of
* @param {BlameOptions} [options] Options for the blame
* @return {Blame} the blame
*/
Blame.file = function (repo, path, options) {
options = normalizeOptions(options, NodeGit.BlameOptions);
return _file.call(this, repo, path, options);
};
+71
View File
@@ -0,0 +1,71 @@
"use strict";
var util = require("util");
var NodeGit = require("../");
var Blob = NodeGit.Blob;
var LookupWrapper = NodeGit.Utils.lookupWrapper;
var TreeEntry = NodeGit.TreeEntry;
var normalizeOptions = NodeGit.Utils.normalizeOptions;
var _filteredContent = Blob.filteredContent;
var _filter = Blob.prototype.filter;
/**
* Retrieves the blob pointed to by the oid
* @async
* @param {Repository} repo The repo that the blob lives in
* @param {String|Oid|Blob} id The blob to lookup
* @return {Blob}
*/
Blob.lookup = LookupWrapper(Blob);
/**
* Retrieve the content of the Blob.
*
* @return {Buffer} Contents as a buffer.
*/
Blob.prototype.content = function () {
return this.rawcontent().toBuffer(this.rawsize());
};
/**
* Retrieve the Blob's type.
*
* @return {Number} The filemode of the blob.
*/
Blob.prototype.filemode = function () {
var FileMode = TreeEntry.FILEMODE;
return this.isBinary() ? FileMode.EXECUTABLE : FileMode.BLOB;
};
/**
* Retrieve the Blob's content as String.
*
* @return {String} Contents as a string.
*/
Blob.prototype.toString = function () {
return this.content().toString();
};
/**
* Get a buffer with the filtered content of a blob.
*
* This applies filters as if the blob was being checked out to the
* working directory under the specified filename. This may apply
* CRLF filtering or other types of changes depending on the file
* attributes set for the blob and the content detected in it.
*
* @async
* @param asPath Path used for file attribute lookups, etc.
* @param opts Options to use for filtering the blob
* @return {Promise<string>}
*/
Blob.prototype.filter = function (asPath, opts) {
if (opts) {
opts = normalizeOptions(opts, NodeGit.BlobFilterOptions);
}
return _filter.call(this, asPath, opts);
};
Blob.filteredContent = util.deprecate(_filteredContent, "NodeGit.Blob.filteredContent is deprecated" + "use NodeGit.Blob.prototype.filter instead.");
+20
View File
@@ -0,0 +1,20 @@
"use strict";
var NodeGit = require("../");
var Branch = NodeGit.Branch;
var _remoteName = Branch.remoteName;
/**
* Retrieve the Branch's Remote Name as a String.
*
* @async
* @param {Repository} repo The repo to get the remote name from
* @param {String} the refname of the branch
* @return {String} remote name as a string.
*/
Branch.remoteName = function (repo, remoteRef) {
return _remoteName.call(this, repo, remoteRef).then(function (remoteNameBuffer) {
return remoteNameBuffer.toString();
});
};
+16
View File
@@ -0,0 +1,16 @@
"use strict";
var _require = require("../"),
Buf = _require.Buf;
/**
* Sets the content of a GitBuf to a string.
* @param {string} The utf8 value to set in the buffer.
* The string will be null terminated.
*/
Buf.prototype.setString = function (content) {
var buf = Buffer.from(content + "\0", "utf8");
this.set(buf, buf.length);
};
+53
View File
@@ -0,0 +1,53 @@
"use strict";
var NodeGit = require("../");
var normalizeOptions = NodeGit.Utils.normalizeOptions;
var Checkout = NodeGit.Checkout;
var _head = Checkout.head;
var _index = Checkout.index;
var _tree = Checkout.tree;
/**
* Patch head checkout to automatically coerce objects.
*
* @async
* @param {Repository} repo The repo to checkout head
* @param {CheckoutOptions} [options] Options for the checkout
* @return {Void} checkout complete
*/
Checkout.head = function (url, options) {
options = normalizeOptions(options || {}, NodeGit.CheckoutOptions);
return _head.call(this, url, options);
};
/**
* Patch index checkout to automatically coerce objects.
*
* @async
* @param {Repository} repo The repo to checkout an index
* @param {Index} index The index to checkout
* @param {CheckoutOptions} [options] Options for the checkout
* @return {Void} checkout complete
*/
Checkout.index = function (repo, index, options) {
options = normalizeOptions(options || {}, NodeGit.CheckoutOptions);
return _index.call(this, repo, index, options);
};
/**
* Patch tree checkout to automatically coerce objects.
*
* @async
* @param {Repository} repo
* @param {String|Tree|Commit|Reference} treeish
* @param {CheckoutOptions} [options]
* @return {Void} checkout complete
*/
Checkout.tree = function (repo, treeish, options) {
options = normalizeOptions(options || {}, NodeGit.CheckoutOptions);
return _tree.call(this, repo, treeish, options);
};
+62
View File
@@ -0,0 +1,62 @@
"use strict";
var NodeGit = require("../");
var shallowClone = NodeGit.Utils.shallowClone;
var normalizeOptions = NodeGit.Utils.normalizeOptions;
var Cherrypick = NodeGit.Cherrypick;
var _cherrypick = Cherrypick.cherrypick;
var _commit = Cherrypick.commit;
/**
* Cherrypick a commit and, changing the index and working directory
*
* @async
* @param {Repository} repo The repo to checkout head
* @param {Commit} commit The commit to cherrypick
* @param {CherrypickOptions} [options] Options for the cherrypick
* @return {int} 0 on success, -1 on failure
*/
Cherrypick.cherrypick = function (repo, commit, options) {
var mergeOpts;
var checkoutOpts;
if (options) {
options = shallowClone(options);
mergeOpts = options.mergeOpts;
checkoutOpts = options.checkoutOpts;
delete options.mergeOpts;
delete options.checkoutOpts;
}
options = normalizeOptions(options, NodeGit.CherrypickOptions);
if (mergeOpts) {
options.mergeOpts = normalizeOptions(mergeOpts, NodeGit.MergeOptions);
}
if (checkoutOpts) {
options.checkoutOpts = normalizeOptions(checkoutOpts, NodeGit.CheckoutOptions);
}
return _cherrypick.call(this, repo, commit, options);
};
/**
* Cherrypicks the given commit against "our" commit, producing an index that
* reflects the result of the cherrypick. The index is not backed by a repo.
*
* @async
* @param {Repository} repo The repo to cherrypick commits
* @param {Commit} cherrypick_commit The commit to cherrypick
* @param {Commit} our_commit The commit to revert against
* @param {int} mainline The parent of the revert commit (1 or
* 2) if it's a merge, 0 otherwise
* @param {MergeOptions} [merge_options] Merge options for the cherrypick
* @return {int} 0 on success, -1 on failure
*/
Cherrypick.commit = function (repo, cherrypick_commit, our_commit, mainline, merge_options) {
merge_options = normalizeOptions(merge_options, NodeGit.MergeOptions);
return _commit.call(this, repo, cherrypick_commit, our_commit, mainline, merge_options);
};
+35
View File
@@ -0,0 +1,35 @@
"use strict";
var NodeGit = require("../");
var shallowClone = NodeGit.Utils.shallowClone;
var normalizeFetchOptions = NodeGit.Utils.normalizeFetchOptions;
var normalizeOptions = NodeGit.Utils.normalizeOptions;
var Clone = NodeGit.Clone;
var _clone = Clone.clone;
/**
* Patch repository cloning to automatically coerce objects.
*
* @async
* @param {String} url url of the repository
* @param {String} local_path local path to store repository
* @param {CloneOptions} [options]
* @return {Repository} repo
*/
Clone.clone = function (url, local_path, options) {
var fetchOpts = normalizeFetchOptions(options && options.fetchOpts);
if (options) {
options = shallowClone(options);
delete options.fetchOpts;
}
options = normalizeOptions(options, NodeGit.CloneOptions);
if (options) {
options.fetchOpts = fetchOpts;
}
return _clone.call(this, url, local_path, options);
};
+387
View File
@@ -0,0 +1,387 @@
"use strict";
var events = require("events");
var fp = require("lodash/fp");
var NodeGit = require("../");
var Commit = NodeGit.Commit;
var LookupWrapper = NodeGit.Utils.lookupWrapper;
var _amend = Commit.prototype.amend;
var _parent = Commit.prototype.parent;
/**
* Retrieves the commit pointed to by the oid
* @async
* @param {Repository} repo The repo that the commit lives in
* @param {String|Oid|Commit} id The commit to lookup
* @return {Commit}
*/
Commit.lookup = LookupWrapper(Commit);
/**
* @async
* @param {Number} n
* @return {Commit}
*/
Commit.prototype.parent = function (n) {
var repo = this.repo;
return _parent.call(this, n).then(function (p) {
p.repo = repo;
return p;
});
};
/**
* Amend a commit
* @async
* @param {String} update_ref
* @param {Signature} author
* @param {Signature} committer
* @param {String} message_encoding
* @param {String} message
* @param {Tree|Oid} tree
* @return {Oid}
*/
Commit.prototype.amend = function (updateRef, author, committer, message_encoding, message, tree) {
var repo = this.repo;
var _this = this;
var treePromise;
if (tree instanceof NodeGit.Oid) {
treePromise = repo.getTree(tree);
} else {
treePromise = Promise.resolve(tree);
}
return treePromise.then(function (treeObject) {
return _amend.call(_this, updateRef, author, committer, message_encoding, message, treeObject);
});
};
/**
* Amend a commit with the given signature
* @async
* @param {String} updateRef
* @param {Signature} author
* @param {Signature} committer
* @param {String} messageEncoding
* @param {String} message
* @param {Tree|Oid} tree
* @param {Function} onSignature Callback to be called with string to be signed
* @return {Oid}
*/
Commit.prototype.amendWithSignature = function (updateRef, author, committer, messageEncoding, message, tree, onSignature) {
var repo = this.repo;
var parentOids = this.parents();
var _this = this;
var promises = [];
if (tree instanceof NodeGit.Oid) {
promises.push(repo.getTree(tree));
} else {
promises.push(Promise.resolve(tree));
}
parentOids.forEach(function (parentOid) {
promises.push(repo.getCommit(parentOid));
});
var treeObject = void 0;
var parents = void 0;
var commitContent = void 0;
var commit = void 0;
var skippedSigning = void 0;
var resolvedAuthor = void 0;
var resolvedCommitter = void 0;
var resolvedMessageEncoding = void 0;
var resolvedMessage = void 0;
var resolvedTree = void 0;
var createCommitPromise = Promise.all(promises).then(function (results) {
treeObject = fp.head(results);
parents = fp.tail(results);
return _this.getTree();
}).then(function (commitTreeResult) {
var commitTree = commitTreeResult;
var truthyArgs = fp.omitBy(fp.isNil, {
author: author,
committer: committer,
messageEncoding: messageEncoding,
message: message,
tree: treeObject
});
var commitFields = {
author: _this.author(),
committer: _this.committer(),
messageEncoding: _this.messageEncoding(),
message: _this.message(),
tree: commitTree
};
var _fp$assign = fp.assign(commitFields, truthyArgs);
resolvedAuthor = _fp$assign.author;
resolvedCommitter = _fp$assign.committer;
resolvedMessageEncoding = _fp$assign.messageEncoding;
resolvedMessage = _fp$assign.message;
resolvedTree = _fp$assign.tree;
return Commit.createBuffer(repo, resolvedAuthor, resolvedCommitter, resolvedMessageEncoding, resolvedMessage, resolvedTree, parents.length, parents);
}).then(function (commitContentResult) {
commitContent = commitContentResult;
if (!commitContent.endsWith("\n")) {
commitContent += "\n";
}
return onSignature(commitContent);
}).then(function (_ref) {
var code = _ref.code,
field = _ref.field,
signedData = _ref.signedData;
switch (code) {
case NodeGit.Error.CODE.OK:
return Commit.createWithSignature(repo, commitContent, signedData, field);
case NodeGit.Error.CODE.PASSTHROUGH:
skippedSigning = true;
return Commit.create(repo, updateRef, resolvedAuthor, resolvedCommitter, resolvedMessageEncoding, resolvedMessage, resolvedTree, parents.length, parents);
default:
{
var error = new Error("Commit.amendWithSignature threw with error code " + code);
error.errno = code;
throw error;
}
}
});
if (!updateRef) {
return createCommitPromise;
}
return createCommitPromise.then(function (commitOid) {
if (skippedSigning) {
return commitOid;
}
return repo.getCommit(commitOid).then(function (commitResult) {
commit = commitResult;
return repo.getReference(updateRef);
}).then(function (ref) {
return ref.setTarget(commitOid, "commit (amend): " + commit.summary());
}).then(function () {
return commitOid;
});
});
};
/**
* Retrieve the commit time as a Date object.
* @return {Date}
*/
Commit.prototype.date = function () {
return new Date(this.timeMs());
};
/**
* Generate an array of diff trees showing changes between this commit
* and its parent(s).
*
* @async
* @return {Array<Diff>} an array of diffs
*/
Commit.prototype.getDiff = function () {
return this.getDiffWithOptions(null);
};
/**
* Generate an array of diff trees showing changes between this commit
* and its parent(s).
*
* @async
* @param {Object} options
* @return {Array<Diff>} an array of diffs
*/
Commit.prototype.getDiffWithOptions = function (options) {
var commit = this;
return commit.getTree().then(function (thisTree) {
return commit.getParents().then(function (parents) {
var diffs;
if (parents.length) {
diffs = parents.map(function (parent) {
return parent.getTree().then(function (parentTree) {
return thisTree.diffWithOptions(parentTree, options);
});
});
} else {
diffs = [thisTree.diffWithOptions(null, options)];
}
return Promise.all(diffs);
});
});
};
/**
* Retrieve the entry represented by path for this commit.
* Path must be relative to repository root.
*
* @async
* @param {String} path
* @return {TreeEntry}
*/
Commit.prototype.getEntry = function (path) {
return this.getTree().then(function (tree) {
return tree.getEntry(path);
});
};
/**
* Retrieve the commit's parents as commit objects.
*
* @async
* @param {number} limit Optional amount of parents to return.
* @return {Array<Commit>} array of commits
*/
Commit.prototype.getParents = function (limit) {
var parents = [];
// If no limit was set, default to the maximum parents.
limit = typeof limit === "number" ? limit : this.parentcount();
limit = Math.min(limit, this.parentcount());
for (var i = 0; i < limit; i++) {
var oid = this.parentId(i);
var parent = this.repo.getCommit(oid);
parents.push(parent);
}
// Wait for all parents to complete, before returning.
return Promise.all(parents);
};
/**
* @typedef extractedSignature
* @type {Object}
* @property {String} signature the signature of the commit
* @property {String} signedData the extracted signed data
*/
/**
* Retrieve the signature and signed data for a commit.
* @param {String} field Optional field to get from the signature,
* defaults to gpgsig
* @return {extractedSignature}
*/
Commit.prototype.getSignature = function (field) {
return Commit.extractSignature(this.repo, this.id(), field);
};
/**
* Get the tree associated with this commit.
*
* @async
* @return {Tree}
*/
Commit.prototype.getTree = function () {
return this.repo.getTree(this.treeId());
};
/**
* Walk the history from this commit backwards.
*
* An EventEmitter is returned that will emit a "commit" event for each
* commit in the history, and one "end" event when the walk is completed.
* Don't forget to call `start()` on the returned event.
*
* @fires EventEmitter#commit Commit
* @fires EventEmitter#end Array<Commit>
* @fires EventEmitter#error Error
*
* @return {EventEmitter}
* @start start()
*/
Commit.prototype.history = function () {
var event = new events.EventEmitter();
var oid = this.id();
var revwalk = this.repo.createRevWalk();
revwalk.sorting.apply(revwalk, arguments);
var commits = [];
event.start = function () {
revwalk.walk(oid, function commitRevWalk(error, commit) {
if (error) {
if (error.errno === NodeGit.Error.CODE.ITEROVER) {
event.emit("end", commits);
return;
} else {
return event.emit("error", error);
}
}
event.emit("commit", commit);
commits.push(commit);
});
};
return event;
};
/**
* Get the specified parent of the commit.
*
* @param {number} the position of the parent, starting from 0
* @async
* @return {Commit} the parent commit at the specified position
*/
Commit.prototype.parent = function (id) {
var repository = this.repo;
return _parent.call(this, id).then(function (parent) {
parent.repo = repository;
return parent;
});
};
/**
* Retrieve the commit's parent shas.
*
* @return {Array<Oid>} array of oids
*/
Commit.prototype.parents = function () {
var result = [];
for (var i = 0; i < this.parentcount(); i++) {
result.push(this.parentId(i));
}
return result;
};
/**
* Retrieve the SHA.
* @return {String}
*/
Commit.prototype.sha = function () {
return this.id().toString();
};
/**
* Retrieve the commit time as a unix timestamp.
* @return {Number}
*/
Commit.prototype.timeMs = function () {
return this.time() * 1000;
};
/**
* The sha of this commit
* @return {String}
*/
Commit.prototype.toString = function () {
return this.sha();
};
+21
View File
@@ -0,0 +1,21 @@
"use strict";
var util = require("util");
var NodeGit = require("../");
var Config = NodeGit.Config;
// Backwards compatibility.
Config.prototype.getString = function () {
return this.getStringBuf.apply(this, arguments);
};
NodeGit.Enums.CVAR = {};
var DEPRECATED_CVAR_ENUMS = ["FALSE", "TRUE", "INT32", "STRING"];
DEPRECATED_CVAR_ENUMS.forEach(function (key) {
Object.defineProperty(NodeGit.Enums.CVAR, key, {
get: util.deprecate(function () {
return Config.MAP[key];
}, "Use NodeGit.Config.MAP." + key + " instead of NodeGit.Enums.CVAR." + key + ".")
});
});
+63
View File
@@ -0,0 +1,63 @@
"use strict";
var NodeGit = require("../");
var ConvenientHunk = NodeGit.ConvenientHunk;
var header = ConvenientHunk.prototype.header;
/**
* Diff header string that represents the context of this hunk
* of the diff. Something like `@@ -169,14 +167,12 @@ ...`
* @return {String}
*/
ConvenientHunk.prototype.header = header;
var headerLen = ConvenientHunk.prototype.headerLen;
/**
* The length of the header
* @return {Number}
*/
ConvenientHunk.prototype.headerLen = headerLen;
var lines = ConvenientHunk.prototype.lines;
/**
* The lines in this hunk
* @async
* @return {Array<DiffLine>}
*/
ConvenientHunk.prototype.lines = lines;
var newLines = ConvenientHunk.prototype.newLines;
/**
* The number of new lines in the hunk
* @return {Number}
*/
ConvenientHunk.prototype.newLines = newLines;
var newStart = ConvenientHunk.prototype.newStart;
/**
* The starting offset of the first new line in the file
* @return {Number}
*/
ConvenientHunk.prototype.newStart = newStart;
var oldLines = ConvenientHunk.prototype.oldLines;
/**
* The number of old lines in the hunk
* @return {Number}
*/
ConvenientHunk.prototype.oldLines = oldLines;
var oldStart = ConvenientHunk.prototype.oldStart;
/**
* The starting offset of the first old line in the file
* @return {Number}
*/
ConvenientHunk.prototype.oldStart = oldStart;
var size = ConvenientHunk.prototype.size;
/**
* Number of lines in this hunk
* @return {Number}
*/
ConvenientHunk.prototype.size = size;
+133
View File
@@ -0,0 +1,133 @@
"use strict";
var NodeGit = require("../");
var ConvenientPatch = NodeGit.ConvenientPatch;
var hunks = ConvenientPatch.prototype.hunks;
/**
* The hunks in this patch
* @async
* @return {Array<ConvenientHunk>} a promise that resolves to an array of
* ConvenientHunks
*/
ConvenientPatch.prototype.hunks = hunks;
var isAdded = ConvenientPatch.prototype.isAdded;
/**
* Is this an added patch?
* @return {Boolean}
*/
ConvenientPatch.prototype.isAdded = isAdded;
var isConflicted = ConvenientPatch.prototype.isConflicted;
/**
* Is this a conflicted patch?
* @return {Boolean}
*/
ConvenientPatch.prototype.isConflicted = isConflicted;
var isCopied = ConvenientPatch.prototype.isCopied;
/**
* Is this a copied patch?
* @return {Boolean}
*/
ConvenientPatch.prototype.isCopied = isCopied;
var isDeleted = ConvenientPatch.prototype.isDeleted;
/**
* Is this a deleted patch?
* @return {Boolean}
*/
ConvenientPatch.prototype.isDeleted = isDeleted;
var isIgnored = ConvenientPatch.prototype.isIgnored;
/**
* Is this an ignored patch?
* @return {Boolean}
*/
ConvenientPatch.prototype.isIgnored = isIgnored;
var isModified = ConvenientPatch.prototype.isModified;
/**
* Is this an modified patch?
* @return {Boolean}
*/
ConvenientPatch.prototype.isModified = isModified;
var isRenamed = ConvenientPatch.prototype.isRenamed;
/**
* Is this a renamed patch?
* @return {Boolean}
*/
ConvenientPatch.prototype.isRenamed = isRenamed;
var isTypeChange = ConvenientPatch.prototype.isTypeChange;
/**
* Is this a type change?
* @return {Boolean}
*/
ConvenientPatch.prototype.isTypeChange = isTypeChange;
var isUnmodified = ConvenientPatch.prototype.isUnmodified;
/**
* Is this an unmodified patch?
* @return {Boolean}
*/
ConvenientPatch.prototype.isUnmodified = isUnmodified;
var isUnreadable = ConvenientPatch.prototype.isUnreadable;
/**
* Is this an undreadable patch?
* @return {Boolean}
*/
ConvenientPatch.prototype.isUnreadable = isUnreadable;
var isUntracked = ConvenientPatch.prototype.isUntracked;
/**
* Is this an untracked patch?
* @return {Boolean}
*/
ConvenientPatch.prototype.isUntracked = isUntracked;
/**
* @typedef lineStats
* @type {Object}
* @property {number} total_context # of contexts in the patch
* @property {number} total_additions # of lines added in the patch
* @property {number} total_deletions # of lines deleted in the patch
*/
var lineStats = ConvenientPatch.prototype.lineStats;
/**
* The line statistics of this patch (#contexts, #added, #deleted)
* @return {lineStats}
*/
ConvenientPatch.prototype.lineStats = lineStats;
var newFile = ConvenientPatch.prototype.newFile;
/**
* New attributes of the file
* @return {DiffFile}
*/
ConvenientPatch.prototype.newFile = newFile;
var oldFile = ConvenientPatch.prototype.oldFile;
/**
* Old attributes of the file
* @return {DiffFile}
*/
ConvenientPatch.prototype.oldFile = oldFile;
var size = ConvenientPatch.prototype.size;
/**
* The number of hunks in this patch
* @return {Number}
*/
ConvenientPatch.prototype.size = size;
var status = ConvenientPatch.prototype.status;
/**
* The status of this patch (unmodified, added, deleted)
* @return {Number}
*/
ConvenientPatch.prototype.status = status;
+94
View File
@@ -0,0 +1,94 @@
"use strict";
var NodeGit = require("../");
var Diff = NodeGit.Diff;
var normalizeOptions = NodeGit.Utils.normalizeOptions;
var Patch = NodeGit.Patch;
var _blobToBuffer = Diff.blobToBuffer;
var _indexToWorkdir = Diff.indexToWorkdir;
var _treeToIndex = Diff.treeToIndex;
var _treeToTree = Diff.treeToTree;
var _treeToWorkdir = Diff.treeToWorkdir;
var _treeToWorkdirWithIndex = Diff.treeToWorkdirWithIndex;
var _findSimilar = Diff.prototype.findSimilar;
/**
* Directly run a diff between a blob and a buffer.
* @async
* @param {Blob} old_blob Blob for old side of diff, or NULL for empty blob
* @param {String} old_as_path Treat old blob as if it had this filename;
* can be NULL
* @param {String} buffer Raw data for new side of diff, or NULL for empty
* @param {String} buffer_as_path Treat buffer as if it had this filename;
* can be NULL
* @param {DiffOptions} opts Options for diff, or NULL for default options
* @param {Function} file_cb Callback for "file"; made once if there is a diff;
* can be NULL
* @param {Function} binary_cb Callback for binary files; can be NULL
* @param {Function} hunk_cb Callback for each hunk in diff; can be NULL
* @param {Function} line_cb Callback for each line in diff; can be NULL
*/
Diff.blobToBuffer = function (old_blob, old_as_path, buffer, buffer_as_path, opts, file_cb, binary_cb, hunk_cb, line_cb) {
var bufferText;
var bufferLength;
if (buffer instanceof Buffer) {
bufferText = buffer.toString("utf8");
bufferLength = Buffer.byteLength(buffer, "utf8");
} else {
bufferText = buffer;
bufferLength = !buffer ? 0 : Buffer.byteLength(buffer, "utf8");
}
opts = normalizeOptions(opts, NodeGit.DiffOptions);
return _blobToBuffer.call(this, old_blob, old_as_path, bufferText, bufferLength, buffer_as_path, opts, file_cb, binary_cb, hunk_cb, line_cb, null);
};
// Override Diff.indexToWorkdir to normalize opts
Diff.indexToWorkdir = function (repo, index, opts) {
opts = normalizeOptions(opts, NodeGit.DiffOptions);
return _indexToWorkdir(repo, index, opts);
};
// Override Diff.treeToIndex to normalize opts
Diff.treeToIndex = function (repo, tree, index, opts) {
opts = normalizeOptions(opts, NodeGit.DiffOptions);
return _treeToIndex(repo, tree, index, opts);
};
// Override Diff.treeToTree to normalize opts
Diff.treeToTree = function (repo, from_tree, to_tree, opts) {
opts = normalizeOptions(opts, NodeGit.DiffOptions);
return _treeToTree(repo, from_tree, to_tree, opts);
};
// Override Diff.treeToWorkdir to normalize opts
Diff.treeToWorkdir = function (repo, tree, opts) {
opts = normalizeOptions(opts, NodeGit.DiffOptions);
return _treeToWorkdir(repo, tree, opts);
};
// Override Diff.treeToWorkdir to normalize opts
Diff.treeToWorkdirWithIndex = function (repo, tree, opts) {
opts = normalizeOptions(opts, NodeGit.DiffOptions);
return _treeToWorkdirWithIndex(repo, tree, opts);
};
// Override Diff.findSimilar to normalize opts
Diff.prototype.findSimilar = function (opts) {
opts = normalizeOptions(opts, NodeGit.DiffFindOptions);
return _findSimilar.call(this, opts);
};
/**
* Retrieve patches in this difflist
*
* @async
* @return {Array<ConvenientPatch>} a promise that resolves to an array of
* ConvenientPatches
*/
Diff.prototype.patches = function () {
return Patch.convenientFromDiff(this);
};
+40
View File
@@ -0,0 +1,40 @@
"use strict";
var NodeGit = require("../");
var DiffFile = NodeGit.DiffFile;
var flags = DiffFile.prototype.flags;
/**
* Returns the file's flags
* @return {Number}
*/
DiffFile.prototype.flags = flags;
var id = DiffFile.prototype.id;
/**
* Returns the file's Oid
* @return {Oid}
*/
DiffFile.prototype.id = id;
var mode = DiffFile.prototype.mode;
/**
* Returns the file's mode
* @return {Number}
*/
DiffFile.prototype.mode = mode;
var path = DiffFile.prototype.path;
/**
* Returns the file's path
* @return {String}
*/
DiffFile.prototype.path = path;
var size = DiffFile.prototype.size;
/**
* Returns the file's size
* @return {Number}
*/
DiffFile.prototype.size = size;
+32
View File
@@ -0,0 +1,32 @@
"use strict";
var NodeGit = require("../");
var DiffLine = NodeGit.DiffLine;
var _rawContent = DiffLine.prototype.content;
/**
* The relevant line
* @return {String}
*/
DiffLine.prototype.content = function () {
if (!this._cache) {
this._cache = {};
}
if (!this._cache.content) {
this._cache.content = new Buffer(this.rawContent()).slice(0, this.contentLen()).toString("utf8");
}
return this._cache.content;
};
/**
* The non utf8 translated text
* @return {String}
*/
DiffLine.prototype.rawContent = function () {
return _rawContent.call(this);
};
NodeGit.DiffLine = DiffLine;
+689
View File
@@ -0,0 +1,689 @@
"use strict";
// This is a generated file, modify: generate/templates/templates/enums.js
var NodeGit = require("../");
NodeGit.Enums = {};
NodeGit.Apply.FLAGS = {
CHECK: 1
};
NodeGit.Apply.LOCATION = {
WORKDIR: 0,
INDEX: 1,
BOTH: 2
};
NodeGit.Attr.VALUE = {
UNSPECIFIED: 0,
TRUE: 1,
FALSE: 2,
STRING: 3
};
NodeGit.Blame.FLAG = {
NORMAL: 0,
TRACK_COPIES_SAME_FILE: 1,
TRACK_COPIES_SAME_COMMIT_MOVES: 2,
TRACK_COPIES_SAME_COMMIT_COPIES: 4,
TRACK_COPIES_ANY_COMMIT_COPIES: 8,
FIRST_PARENT: 16,
USE_MAILMAP: 32
};
NodeGit.Blob.FILTER_FLAG = {
CHECK_FOR_BINARY: 1,
NO_SYSTEM_ATTRIBUTES: 2,
ATTTRIBUTES_FROM_HEAD: 4
};
NodeGit.Branch.BRANCH = {
LOCAL: 1,
REMOTE: 2,
ALL: 3
};
NodeGit.Cert.TYPE = {
NONE: 0,
X509: 1,
HOSTKEY_LIBSSH2: 2,
STRARRAY: 3
};
NodeGit.Cert.SSH = {
MD5: 1,
SHA1: 2,
SHA256: 4
};
NodeGit.Checkout.NOTIFY = {
NONE: 0,
CONFLICT: 1,
DIRTY: 2,
UPDATED: 4,
UNTRACKED: 8,
IGNORED: 16,
ALL: 65535
};
NodeGit.Checkout.STRATEGY = {
NONE: 0,
SAFE: 1,
FORCE: 2,
RECREATE_MISSING: 4,
ALLOW_CONFLICTS: 16,
REMOVE_UNTRACKED: 32,
REMOVE_IGNORED: 64,
UPDATE_ONLY: 128,
DONT_UPDATE_INDEX: 256,
NO_REFRESH: 512,
SKIP_UNMERGED: 1024,
USE_OURS: 2048,
USE_THEIRS: 4096,
DISABLE_PATHSPEC_MATCH: 8192,
SKIP_LOCKED_DIRECTORIES: 262144,
DONT_OVERWRITE_IGNORED: 524288,
CONFLICT_STYLE_MERGE: 1048576,
CONFLICT_STYLE_DIFF3: 2097152,
DONT_REMOVE_EXISTING: 4194304,
DONT_WRITE_INDEX: 8388608,
UPDATE_SUBMODULES: 65536,
UPDATE_SUBMODULES_IF_CHANGED: 131072
};
NodeGit.Clone.LOCAL = {
AUTO: 0,
LOCAL: 1,
NO_LOCAL: 2,
NO_LINKS: 3
};
NodeGit.Config.LEVEL = {
PROGRAMDATA: 1,
SYSTEM: 2,
XDG: 3,
GLOBAL: 4,
LOCAL: 5,
APP: 6,
HIGHEST_LEVEL: -1
};
NodeGit.Config.MAP = {
FALSE: 0,
TRUE: 1,
INT32: 2,
STRING: 3
};
NodeGit.Cred.TYPE = {
USERPASS_PLAINTEXT: 1,
SSH_KEY: 2,
SSH_CUSTOM: 4,
DEFAULT: 8,
SSH_INTERACTIVE: 16,
USERNAME: 32,
SSH_MEMORY: 64
};
NodeGit.Diff.DELTA = {
UNMODIFIED: 0,
ADDED: 1,
DELETED: 2,
MODIFIED: 3,
RENAMED: 4,
COPIED: 5,
IGNORED: 6,
UNTRACKED: 7,
TYPECHANGE: 8,
UNREADABLE: 9,
CONFLICTED: 10
};
NodeGit.DiffBinary.DIFF_BINARY = {
NONE: 0,
LITERAL: 1,
DELTA: 2
};
NodeGit.Diff.FIND = {
BY_CONFIG: 0,
RENAMES: 1,
RENAMES_FROM_REWRITES: 2,
COPIES: 4,
COPIES_FROM_UNMODIFIED: 8,
REWRITES: 16,
BREAK_REWRITES: 32,
AND_BREAK_REWRITES: 48,
FOR_UNTRACKED: 64,
ALL: 255,
IGNORE_LEADING_WHITESPACE: 0,
IGNORE_WHITESPACE: 4096,
DONT_IGNORE_WHITESPACE: 8192,
EXACT_MATCH_ONLY: 16384,
BREAK_REWRITES_FOR_RENAMES_ONLY: 32768,
REMOVE_UNMODIFIED: 65536
};
NodeGit.Diff.FLAG = {
BINARY: 1,
NOT_BINARY: 2,
VALID_ID: 4,
EXISTS: 8
};
NodeGit.Diff.FORMAT = {
PATCH: 1,
PATCH_HEADER: 2,
RAW: 3,
NAME_ONLY: 4,
NAME_STATUS: 5,
PATCH_ID: 6
};
NodeGit.Diff.FORMAT_EMAIL_FLAGS = {
FORMAT_EMAIL_NONE: 0,
FORMAT_EMAIL_EXCLUDE_SUBJECT_PATCH_MARKER: 1
};
NodeGit.Diff.LINE = {
CONTEXT: 32,
ADDITION: 43,
DELETION: 45,
CONTEXT_EOFNL: 61,
ADD_EOFNL: 62,
DEL_EOFNL: 60,
FILE_HDR: 70,
HUNK_HDR: 72,
BINARY: 66
};
NodeGit.Diff.OPTION = {
NORMAL: 0,
REVERSE: 1,
INCLUDE_IGNORED: 2,
RECURSE_IGNORED_DIRS: 4,
INCLUDE_UNTRACKED: 8,
RECURSE_UNTRACKED_DIRS: 16,
INCLUDE_UNMODIFIED: 32,
INCLUDE_TYPECHANGE: 64,
INCLUDE_TYPECHANGE_TREES: 128,
IGNORE_FILEMODE: 256,
IGNORE_SUBMODULES: 512,
IGNORE_CASE: 1024,
INCLUDE_CASECHANGE: 2048,
DISABLE_PATHSPEC_MATCH: 4096,
SKIP_BINARY_CHECK: 8192,
ENABLE_FAST_UNTRACKED_DIRS: 16384,
UPDATE_INDEX: 32768,
INCLUDE_UNREADABLE: 65536,
INCLUDE_UNREADABLE_AS_UNTRACKED: 131072,
INDENT_HEURISTIC: 262144,
FORCE_TEXT: 1048576,
FORCE_BINARY: 2097152,
IGNORE_WHITESPACE: 4194304,
IGNORE_WHITESPACE_CHANGE: 8388608,
IGNORE_WHITESPACE_EOL: 16777216,
SHOW_UNTRACKED_CONTENT: 33554432,
SHOW_UNMODIFIED: 67108864,
PATIENCE: 268435456,
MINIMAL: 536870912,
SHOW_BINARY: 1073741824
};
NodeGit.Diff.STATS_FORMAT = {
STATS_NONE: 0,
STATS_FULL: 1,
STATS_SHORT: 2,
STATS_NUMBER: 4,
STATS_INCLUDE_SUMMARY: 8
};
NodeGit.Enums.DIRECTION = {
FETCH: 0,
PUSH: 1
};
NodeGit.Error.ERROR = {
NONE: 0,
NOMEMORY: 1,
OS: 2,
INVALID: 3,
REFERENCE: 4,
ZLIB: 5,
REPOSITORY: 6,
CONFIG: 7,
REGEX: 8,
ODB: 9,
INDEX: 10,
OBJECT: 11,
NET: 12,
TAG: 13,
TREE: 14,
INDEXER: 15,
SSL: 16,
SUBMODULE: 17,
THREAD: 18,
STASH: 19,
CHECKOUT: 20,
FETCHHEAD: 21,
MERGE: 22,
SSH: 23,
FILTER: 24,
REVERT: 25,
CALLBACK: 26,
CHERRYPICK: 27,
DESCRIBE: 28,
REBASE: 29,
FILESYSTEM: 30,
PATCH: 31,
WORKTREE: 32,
SHA1: 33
};
NodeGit.Error.CODE = {
OK: 0,
ERROR: -1,
ENOTFOUND: -3,
EEXISTS: -4,
EAMBIGUOUS: -5,
EBUFS: -6,
EUSER: -7,
EBAREREPO: -8,
EUNBORNBRANCH: -9,
EUNMERGED: -10,
ENONFASTFORWARD: -11,
EINVALIDSPEC: -12,
ECONFLICT: -13,
ELOCKED: -14,
EMODIFIED: -15,
EAUTH: -16,
ECERTIFICATE: -17,
EAPPLIED: -18,
EPEEL: -19,
EEOF: -20,
EINVALID: -21,
EUNCOMMITTED: -22,
EDIRECTORY: -23,
EMERGECONFLICT: -24,
PASSTHROUGH: -30,
ITEROVER: -31,
RETRY: -32,
EMISMATCH: -33,
EINDEXDIRTY: -34,
EAPPLYFAIL: -35
};
NodeGit.Enums.FEATURE = {
THREADS: 1,
HTTPS: 2,
SSH: 4,
NSEC: 8
};
NodeGit.Fetch.PRUNE = {
GIT_FETCH_PRUNE_UNSPECIFIED: 0,
GIT_FETCH_PRUNE: 1,
GIT_FETCH_NO_PRUNE: 2
};
NodeGit.TreeEntry.FILEMODE = {
UNREADABLE: 0,
TREE: 16384,
BLOB: 33188,
EXECUTABLE: 33261,
LINK: 40960,
COMMIT: 57344
};
NodeGit.Filter.FLAG = {
DEFAULT: 0,
ALLOW_UNSAFE: 1,
NO_SYSTEM_ATTRIBUTES: 2,
ATTRIBUTES_FROM_HEAD: 4
};
NodeGit.Filter.MODE = {
TO_WORKTREE: 0,
SMUDGE: 0,
TO_ODB: 1,
CLEAN: 1
};
NodeGit.Hashsig.OPTION = {
NORMAL: 0,
IGNORE_WHITESPACE: 1,
SMART_WHITESPACE: 2,
ALLOW_SMALL_FILES: 4
};
NodeGit.Index.ADD_OPTION = {
ADD_DEFAULT: 0,
ADD_FORCE: 1,
ADD_DISABLE_PATHSPEC_MATCH: 2,
ADD_CHECK_PATHSPEC: 4
};
NodeGit.Index.CAPABILITY = {
IGNORE_CASE: 1,
NO_FILEMODE: 2,
NO_SYMLINKS: 4,
FROM_OWNER: -1
};
NodeGit.Index.ENTRY_EXTENDED_FLAG = {
ENTRY_INTENT_TO_ADD: 8192,
ENTRY_SKIP_WORKTREE: 16384,
S: 24576,
ENTRY_UPTODATE: 4
};
NodeGit.Index.ENTRY_FLAG = {
ENTRY_EXTENDED: 16384,
ENTRY_VALID: 32768
};
NodeGit.Index.STAGE = {
ANY: -1,
NORMAL: 0,
ANCESTOR: 1,
OURS: 2,
THEIRS: 3
};
NodeGit.Libgit2.OPT = {
GET_MWINDOW_SIZE: 0,
SET_MWINDOW_SIZE: 1,
GET_MWINDOW_MAPPED_LIMIT: 2,
SET_MWINDOW_MAPPED_LIMIT: 3,
GET_SEARCH_PATH: 4,
SET_SEARCH_PATH: 5,
SET_CACHE_OBJECT_LIMIT: 6,
SET_CACHE_MAX_SIZE: 7,
ENABLE_CACHING: 8,
GET_CACHED_MEMORY: 9,
GET_TEMPLATE_PATH: 10,
SET_TEMPLATE_PATH: 11,
SET_SSL_CERT_LOCATIONS: 12,
SET_USER_AGENT: 13,
ENABLE_STRICT_OBJECT_CREATION: 14,
ENABLE_STRICT_SYMBOLIC_REF_CREATION: 15,
SET_SSL_CIPHERS: 16,
GET_USER_AGENT: 17,
ENABLE_OFS_DELTA: 18,
ENABLE_FSYNC_GITDIR: 19,
GET_WINDOWS_SHAREMODE: 20,
SET_WINDOWS_SHAREMODE: 21,
ENABLE_STRICT_HASH_VERIFICATION: 22,
SET_ALLOCATOR: 23,
ENABLE_UNSAVED_INDEX_SAFETY: 24,
GET_PACK_MAX_OBJECTS: 25,
SET_PACK_MAX_OBJECTS: 26,
DISABLE_PACK_KEEP_FILE_CHECKS: 27
};
NodeGit.Merge.ANALYSIS = {
NONE: 0,
NORMAL: 1,
UP_TO_DATE: 2,
FASTFORWARD: 4,
UNBORN: 8
};
NodeGit.Merge.FILE_FAVOR = {
NORMAL: 0,
OURS: 1,
THEIRS: 2,
UNION: 3
};
NodeGit.Merge.FILE_FLAG = {
FILE_DEFAULT: 0,
FILE_STYLE_MERGE: 1,
FILE_STYLE_DIFF3: 2,
FILE_SIMPLIFY_ALNUM: 4,
FILE_IGNORE_WHITESPACE: 8,
FILE_IGNORE_WHITESPACE_CHANGE: 16,
FILE_IGNORE_WHITESPACE_EOL: 32,
FILE_DIFF_PATIENCE: 64,
FILE_DIFF_MINIMAL: 128
};
NodeGit.Merge.FLAG = {
FIND_RENAMES: 1,
FAIL_ON_CONFLICT: 2,
SKIP_REUC: 4,
NO_RECURSIVE: 8
};
NodeGit.Merge.PREFERENCE = {
NONE: 0,
NO_FASTFORWARD: 1,
FASTFORWARD_ONLY: 2
};
NodeGit.Object.TYPE = {
ANY: -2,
INVALID: -1,
COMMIT: 1,
TREE: 2,
BLOB: 3,
TAG: 4,
OFS_DELTA: 6,
REF_DELTA: 7
};
NodeGit.Odb.STREAM = {
RDONLY: 2,
WRONLY: 4,
RW: 6
};
NodeGit.Packbuilder.STAGE = {
ADDING_OBJECTS: 0,
DELTAFICATION: 1
};
NodeGit.Path.FS = {
GENERIC: 0,
NTFS: 1,
HFS: 2
};
NodeGit.Path.GITFILE = {
GITIGNORE: 0,
GITMODULES: 1,
GITATTRIBUTES: 1
};
NodeGit.Pathspec.FLAG = {
DEFAULT: 0,
IGNORE_CASE: 1,
USE_CASE: 2,
NO_GLOB: 4,
NO_MATCH_ERROR: 8,
FIND_FAILURES: 16,
FAILURES_ONLY: 32
};
NodeGit.Proxy.PROXY = {
NONE: 0,
AUTO: 1,
SPECIFIED: 2
};
NodeGit.RebaseOperation.REBASE_OPERATION = {
PICK: 0,
REWORD: 1,
EDIT: 2,
SQUASH: 3,
FIXUP: 4,
EXEC: 5
};
NodeGit.Reference.TYPE = {
INVALID: 0,
DIRECT: 1,
SYMBOLIC: 2,
ALL: 3
};
NodeGit.Reference.FORMAT = {
NORMAL: 0,
ALLOW_ONELEVEL: 1,
REFSPEC_PATTERN: 2,
REFSPEC_SHORTHAND: 4
};
NodeGit.Remote.AUTOTAG_OPTION = {
DOWNLOAD_TAGS_UNSPECIFIED: 0,
DOWNLOAD_TAGS_AUTO: 1,
DOWNLOAD_TAGS_NONE: 2,
DOWNLOAD_TAGS_ALL: 3
};
NodeGit.Remote.COMPLETION = {
DOWNLOAD: 0,
INDEXING: 1,
ERROR: 2
};
NodeGit.Remote.CREATE_FLAGS = {
CREATE_SKIP_INSTEADOF: 1,
CREATE_SKIP_DEFAULT_FETCHSPEC: 2
};
NodeGit.Repository.INIT_FLAG = {
BARE: 1,
NO_REINIT: 2,
NO_DOTGIT_DIR: 4,
MKDIR: 8,
MKPATH: 16,
EXTERNAL_TEMPLATE: 32,
RELATIVE_GITLINK: 64
};
NodeGit.Repository.INIT_MODE = {
INIT_SHARED_UMASK: 0,
INIT_SHARED_GROUP: 1533,
INIT_SHARED_ALL: 1535
};
NodeGit.Repository.ITEM = {
GITDIR: 0,
WORKDIR: 1,
COMMONDIR: 2,
INDEX: 3,
OBJECTS: 4,
REFS: 5,
PACKED_REFS: 6,
REMOTES: 7,
CONFIG: 8,
INFO: 9,
HOOKS: 10,
LOGS: 11,
MODULES: 12,
WORKTREES: 13,
_LAST: 14
};
NodeGit.Repository.OPEN_FLAG = {
OPEN_NO_SEARCH: 1,
OPEN_CROSS_FS: 2,
OPEN_BARE: 4,
OPEN_NO_DOTGIT: 8,
OPEN_FROM_ENV: 16
};
NodeGit.Repository.STATE = {
NONE: 0,
MERGE: 1,
REVERT: 2,
REVERT_SEQUENCE: 3,
CHERRYPICK: 4,
CHERRYPICK_SEQUENCE: 5,
BISECT: 6,
REBASE: 7,
REBASE_INTERACTIVE: 8,
REBASE_MERGE: 9,
APPLY_MAILBOX: 10,
APPLY_MAILBOX_OR_REBASE: 11
};
NodeGit.Reset.TYPE = {
SOFT: 1,
MIXED: 2,
HARD: 3
};
NodeGit.Revparse.MODE = {
SINGLE: 1,
RANGE: 2,
MERGE_BASE: 4
};
NodeGit.Enums.SMART_SERVICE = {
SERVICE_UPLOADPACK_LS: 1,
SERVICE_UPLOADPACK: 2,
SERVICE_RECEIVEPACK_LS: 3,
SERVICE_RECEIVEPACK: 4
};
NodeGit.Revwalk.SORT = {
NONE: 0,
TOPOLOGICAL: 1,
TIME: 2,
REVERSE: 4
};
NodeGit.Stash.APPLY_FLAGS = {
APPLY_DEFAULT: 0,
APPLY_REINSTATE_INDEX: 1
};
NodeGit.Stash.APPLY_PROGRESS = {
NONE: 0,
LOADING_STASH: 1,
ANALYZE_INDEX: 2,
ANALYZE_MODIFIED: 3,
ANALYZE_UNTRACKED: 4,
CHECKOUT_UNTRACKED: 5,
CHECKOUT_MODIFIED: 6,
DONE: 7
};
NodeGit.Stash.FLAGS = {
DEFAULT: 0,
KEEP_INDEX: 1,
INCLUDE_UNTRACKED: 2,
INCLUDE_IGNORED: 4
};
NodeGit.Status.STATUS = {
CURRENT: 0,
INDEX_NEW: 1,
INDEX_MODIFIED: 2,
INDEX_DELETED: 4,
INDEX_RENAMED: 8,
INDEX_TYPECHANGE: 16,
WT_NEW: 128,
WT_MODIFIED: 256,
WT_DELETED: 512,
WT_TYPECHANGE: 1024,
WT_RENAMED: 2048,
WT_UNREADABLE: 4096,
IGNORED: 16384,
CONFLICTED: 32768
};
NodeGit.Status.OPT = {
INCLUDE_UNTRACKED: 1,
INCLUDE_IGNORED: 2,
INCLUDE_UNMODIFIED: 4,
EXCLUDE_SUBMODULES: 8,
RECURSE_UNTRACKED_DIRS: 16,
DISABLE_PATHSPEC_MATCH: 32,
RECURSE_IGNORED_DIRS: 64,
RENAMES_HEAD_TO_INDEX: 128,
RENAMES_INDEX_TO_WORKDIR: 256,
SORT_CASE_SENSITIVELY: 512,
SORT_CASE_INSENSITIVELY: 1024,
RENAMES_FROM_REWRITES: 2048,
NO_REFRESH: 4096,
UPDATE_INDEX: 8192,
INCLUDE_UNREADABLE: 16384,
INCLUDE_UNREADABLE_AS_UNTRACKED: 32768
};
NodeGit.Status.SHOW = {
INDEX_AND_WORKDIR: 0,
INDEX_ONLY: 1,
WORKDIR_ONLY: 2
};
NodeGit.Submodule.IGNORE = {
UNSPECIFIED: -1,
NONE: 1,
UNTRACKED: 2,
DIRTY: 3,
ALL: 4
};
NodeGit.Submodule.RECURSE = {
NO: 0,
YES: 1,
ONDEMAND: 2
};
NodeGit.Submodule.STATUS = {
IN_HEAD: 1,
IN_INDEX: 2,
IN_CONFIG: 4,
IN_WD: 8,
INDEX_ADDED: 16,
INDEX_DELETED: 32,
INDEX_MODIFIED: 64,
WD_UNINITIALIZED: 128,
WD_ADDED: 256,
WD_DELETED: 512,
WD_MODIFIED: 1024,
WD_INDEX_MODIFIED: 2048,
WD_WD_MODIFIED: 4096,
WD_UNTRACKED: 8192
};
NodeGit.Submodule.UPDATE = {
CHECKOUT: 1,
REBASE: 2,
MERGE: 3,
NONE: 4,
DEFAULT: 0
};
NodeGit.Trace.LEVEL = {
NONE: 0,
FATAL: 1,
ERROR: 2,
WARN: 3,
INFO: 4,
DEBUG: 5,
TRACE: 6
};
NodeGit.Tree.UPDATE = {
UPSERT: 0,
REMOVE: 1
};
NodeGit.Tree.WALK_MODE = {
WALK_PRE: 0,
WALK_POST: 1
};
NodeGit.Worktree.PRUNE = {
GIT_WORKTREE_PRUNE_VALID: 1,
GIT_WORKTREE_PRUNE_LOCKED: 2,
GIT_WORKTREE_PRUNE_WORKING_TREE: 4
};
+17
View File
@@ -0,0 +1,17 @@
"use strict";
var util = require("util");
var NodeGit = require("../");
// Deprecated -----------------------------------------------------------------
// In 0.28.0 git_error was majorly refactored to have better naming in libgit2
// We will continue to support the old enum entries but with a deprecation
// warning as they will go away soon.
Object.keys(NodeGit.Error.CODE).forEach(function (key) {
Object.defineProperty(NodeGit.Error.CODE, "GITERR_" + key, {
get: util.deprecate(function () {
return NodeGit.Error.CODE[key];
}, "Use NodeGit.Error.CODE." + key + " instead of " + ("NodeGit.Error.CODE.GETERR_" + key + "."))
});
});
+25
View File
@@ -0,0 +1,25 @@
"use strict";
var NodeGit = require("../");
var normalizeOptions = NodeGit.Utils.normalizeOptions;
var FilterRegistry = NodeGit.FilterRegistry;
var _register = FilterRegistry.register;
// register should add filter by name to dict and return
// Override FilterRegistry.register to normalize Filter
FilterRegistry.register = function (name, filter, priority) {
// setting default value of attributes
if (filter.attributes === undefined) {
filter.attributes = "";
}
filter = normalizeOptions(filter, NodeGit.Filter);
if (!filter.check || !filter.apply) {
return Promise.reject(new Error("ERROR: please provide check and apply callbacks for filter"));
}
return _register(name, filter, priority);
};
+96
View File
@@ -0,0 +1,96 @@
"use strict";
var util = require("util");
var NodeGit = require("../");
var Index = NodeGit.Index;
var _addAll = Index.prototype.addAll;
var _removeAll = Index.prototype.removeAll;
var _updateAll = Index.prototype.updateAll;
Index.prototype.addAll = function (pathspec, flags, matchedCallback) {
return _addAll.call(this, pathspec || "*", flags, matchedCallback, null);
};
/**
* Return an array of the entries in this index.
* @return {Array<IndexEntry>} an array of IndexEntrys
*/
Index.prototype.entries = function () {
var size = this.entryCount();
var result = [];
for (var i = 0; i < size; i++) {
result.push(this.getByIndex(i));
}
return result;
};
Index.prototype.removeAll = function (pathspec, matchedCallback) {
return _removeAll.call(this, pathspec || "*", matchedCallback, null);
};
Index.prototype.updateAll = function (pathspec, matchedCallback) {
return _updateAll.call(this, pathspec || "*", matchedCallback, null);
};
// Deprecated -----------------------------------------------------------------
NodeGit.Index.CAP = {};
Object.keys(NodeGit.Index.CAPABILITY).forEach(function (key) {
Object.defineProperty(NodeGit.Index.CAP, key, {
get: util.deprecate(function () {
return NodeGit.Index.CAPABILITY[key];
}, "Use NodeGit.Index.CAPABILITY." + key + " instead of " + ("NodeGit.Index.CAP." + key + "."))
});
});
NodeGit.Enums.INDXENTRY_FLAG = {};
Object.defineProperty(NodeGit.Enums.INDXENTRY_FLAG, "IDXENTRY_EXTENDED", {
get: util.deprecate(function () {
return NodeGit.Index.ENTRY_FLAG.ENTRY_EXTENDED;
}, "Use NodeGit.Index.ENTRY_FLAG.ENTRY_EXTENDED instead of " + "NodeGit.Enums.INDXENTRY_FLAG.IDXENTRY_EXTENDED.")
});
Object.defineProperty(NodeGit.Enums.INDXENTRY_FLAG, "IDXENTRY_VALID", {
get: util.deprecate(function () {
return NodeGit.Index.ENTRY_FLAG.ENTRY_VALID;
}, "Use NodeGit.Index.ENTRY_FLAG.ENTRY_VALID instead of " + "NodeGit.Enums.INDXENTRY_FLAG.IDXENTRY_VALID.")
});
NodeGit.Enums.IDXENTRY_EXTENDED_FLAG = {};
var EXTENDED_FLAGS_MAP = {
IDXENTRY_INTENT_TO_ADD: "ENTRY_INTENT_TO_ADD",
IDXENTRY_SKIP_WORKTREE: "ENTRY_SKIP_WORKTREE",
S: "S",
IDXENTRY_UPTODATE: "ENTRY_UPTODATE"
};
Object.keys(EXTENDED_FLAGS_MAP).forEach(function (key) {
var newKey = EXTENDED_FLAGS_MAP[key];
Object.defineProperty(NodeGit.Enums.IDXENTRY_EXTENDED_FLAG, key, {
get: util.deprecate(function () {
return NodeGit.Index.ENTRY_EXTENDED_FLAG[newKey];
}, "Use NodeGit.Index.ENTRY_EXTENDED_FLAG." + newKey + " instead of " + ("NodeGit.Enums.IDXENTRY_EXTENDED_FLAG." + key + "."))
});
});
var DEPRECATED_EXTENDED_FLAGS = {
IDXENTRY_EXTENDED2: 32768,
IDXENTRY_UPDATE: 1,
IDXENTRY_REMOVE: 2,
IDXENTRY_ADDED: 8,
IDXENTRY_HASHED: 16,
IDXENTRY_UNHASHED: 32,
IDXENTRY_WT_REMOVE: 64,
IDXENTRY_CONFLICTED: 128,
IDXENTRY_UNPACKED: 256,
IDXENTRY_NEW_SKIP_WORKTREE: 512
};
Object.keys(DEPRECATED_EXTENDED_FLAGS).forEach(function (key) {
Object.defineProperty(NodeGit.Enums.IDXENTRY_EXTENDED_FLAG, key, {
get: util.deprecate(function () {
return DEPRECATED_EXTENDED_FLAGS[key];
}, "LibGit2 has removed this flag for public usage.")
});
});
+8
View File
@@ -0,0 +1,8 @@
"use strict";
var NodeGit = require("../");
var Libgit2 = NodeGit.Libgit2;
Libgit2.OPT.SET_WINDOWS_LONGPATHS = 28;
Libgit2.OPT.GET_WINDOWS_LONGPATHS = 29;
+45
View File
@@ -0,0 +1,45 @@
"use strict";
var NodeGit = require("../");
var normalizeOptions = NodeGit.Utils.normalizeOptions;
var Merge = NodeGit.Merge;
var _commits = Merge.commits;
var _merge = Merge.merge;
/**
* Merge 2 commits together and create an new index that can
* be used to create a merge commit.
*
* @param {Repository} repo Repository that contains the given commits
* @param {Commit} ourCommit The commit that reflects the destination tree
* @param {Commit} theirCommit The commit to merge into ourCommit
* @param {MergeOptions} [options] The merge tree options (null for default)
*/
Merge.commits = function (repo, ourCommit, theirCommit, options) {
options = normalizeOptions(options, NodeGit.MergeOptions);
return Promise.all([repo.getCommit(ourCommit), repo.getCommit(theirCommit)]).then(function (commits) {
return _commits.call(this, repo, commits[0], commits[1], options);
});
};
/**
* Merge a commit into HEAD and writes the results to the working directory.
*
* @param {Repository} repo Repository that contains the given commits
* @param {AnnotatedCommit} theirHead The annotated commit to merge into HEAD
* @param {MergeOptions} [mergeOpts] The merge tree options (null for default)
* @param {CheckoutOptions} [checkoutOpts] The checkout options
* (null for default)
*/
Merge.merge = function (repo, theirHead, mergeOpts, checkoutOpts) {
mergeOpts = normalizeOptions(mergeOpts || {}, NodeGit.MergeOptions);
checkoutOpts = normalizeOptions(checkoutOpts || {}, NodeGit.CheckoutOptions);
// Even though git_merge takes an array of annotated_commits, it expects
// exactly one to have been passed in or it will throw an error... ¯\_(ツ)_/¯
var theirHeads = [theirHead];
return _merge.call(this, repo, theirHeads, theirHeads.length, mergeOpts, checkoutOpts);
};
+1312
View File
File diff suppressed because it is too large Load Diff
+19
View File
@@ -0,0 +1,19 @@
"use strict";
var NodeGit = require("../");
var Note = NodeGit.Note;
var _foreach = Note.foreach;
// Override Note.foreach to eliminate the need to pass null payload
Note.foreach = function (repo, notesRef, callback) {
function wrapperCallback(blobId, objectId) {
// We need to copy the OID since libgit2 types are getting cleaned up
// incorrectly right now in callbacks
return callback(blobId.copy(), objectId.copy());
}
return _foreach(repo, notesRef, wrapperCallback, null);
};
+46
View File
@@ -0,0 +1,46 @@
"use strict";
var util = require("util");
var NodeGit = require("../");
var Obj = NodeGit.Object;
/**
* Is this object a blob?
* @return {Boolean}
*/
Obj.prototype.isBlob = function () {
return this.type() == Obj.TYPE.BLOB;
};
/**
* Is this object a commit?
* @return {Boolean}
*/
Obj.prototype.isCommit = function () {
return this.type() == Obj.TYPE.COMMIT;
};
/**
* Is this object a tag?
* @return {Boolean}
*/
Obj.prototype.isTag = function () {
return this.type() == Obj.TYPE.TAG;
};
/**
* Is this object a tree?
* @return {Boolean}
*/
Obj.prototype.isTree = function () {
return this.type() == Obj.TYPE.TREE;
};
// Deprecated -----------------------------------------------------------------
Object.defineProperty(Obj.TYPE, "BAD", {
get: util.deprecate(function () {
return Obj.TYPE.INVALID;
}, "Use NodeGit.Object.TYPE.INVALID instead of NodeGit.Object.TYPE.BAD.")
});
+11
View File
@@ -0,0 +1,11 @@
"use strict";
var NodeGit = require("../");
var OdbObject = NodeGit.OdbObject;
OdbObject.prototype.toString = function (size) {
size = size || this.size();
return this.data().toBuffer(size).toString();
};
+25
View File
@@ -0,0 +1,25 @@
"use strict";
var NodeGit = require("../");
var Oid = NodeGit.Oid;
// Backwards compatibility.
Object.defineProperties(Oid.prototype, {
"allocfmt": {
value: Oid.prototype.tostrS,
enumerable: false
},
"toString": {
value: Oid.prototype.tostrS,
enumerable: false
}
});
Oid.prototype.copy = function () {
return this.cpy(); // seriously???
};
Oid.prototype.inspect = function () {
return "[Oid " + this.allocfmt() + "]";
};
+130
View File
@@ -0,0 +1,130 @@
"use strict";
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) {
var checkoutOptions = void 0;
var mergeOptions = void 0;
if (options) {
options = shallowClone(options);
checkoutOptions = options.checkoutOptions;
mergeOptions = options.mergeOptions;
delete options.checkoutOptions;
delete options.mergeOptions;
if (options.signingCb) {
var signingCb = options.signingCb;
options.signingCb = function (signatureBuf, signatureFieldBuf, commitContent) {
try {
var signingCbResult = signingCb(commitContent);
return Promise.resolve(signingCbResult).then(function (_ref) {
var code = _ref.code,
field = _ref.field,
signedData = _ref.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.
var lockOptionsOnRebase = function lockOptionsOnRebase(options) {
return function (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);
};
+196
View File
@@ -0,0 +1,196 @@
"use strict";
var util = require("util");
var NodeGit = require("../");
var LookupWrapper = NodeGit.Utils.lookupWrapper;
var Reference = NodeGit.Reference;
var Branch = NodeGit.Branch;
/**
* Retrieves the reference by it's short name
* @async
* @param {Repository} repo The repo that the reference lives in
* @param {String|Reference} id The reference to lookup
* @param {Function} callback
* @return {Reference}
*/
Reference.dwim = LookupWrapper(Reference, Reference.dwim);
/**
* Retrieves the reference pointed to by the oid
* @async
* @param {Repository} repo The repo that the reference lives in
* @param {String|Reference} id The reference to lookup
* @param {Function} callback
* @return {Reference}
*/
Reference.lookup = LookupWrapper(Reference);
/**
* Returns true if this reference is not symbolic
* @return {Boolean}
*/
Reference.prototype.isConcrete = function () {
return this.type() == Reference.TYPE.DIRECT;
};
/**
* Returns if the ref is pointed at by HEAD
* @return {Boolean}
*/
Reference.prototype.isHead = function () {
return Branch.isHead(this);
};
/**
* Returns true if this reference is symbolic
* @return {Boolean}
*/
Reference.prototype.isSymbolic = function () {
return this.type() == Reference.TYPE.SYMBOLIC;
};
/**
* Returns true if this reference is valid
* @return {Boolean}
*/
Reference.prototype.isValid = function () {
return this.type() != Reference.TYPE.INVALID;
};
/**
* Returns the name of the reference.
* @return {String}
*/
Reference.prototype.toString = function () {
return this.name();
};
var getTerminal = function getTerminal(repo, refName) {
var depth = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 10;
var prevRef = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : null;
if (depth <= 0) {
return Promise.resolve({
error: NodeGit.Error.CODE.ENOTFOUND,
out: prevRef
});
}
return NodeGit.Reference.lookup(repo, refName).then(function (ref) {
if (ref.type() === NodeGit.Reference.TYPE.DIRECT) {
return {
error: NodeGit.Error.CODE.OK,
out: ref
};
} else {
return getTerminal(repo, ref.symbolicTarget(), depth - 1, ref).then(function (_ref) {
var error = _ref.error,
out = _ref.out;
if (error === NodeGit.Error.CODE.ENOTFOUND && !out) {
return { error: error, out: ref };
} else {
return { error: error, out: out };
}
});
}
}).catch(function (error) {
return {
error: error.errno,
out: null
};
});
};
var getSignatureForReflog = function getSignatureForReflog(repo) {
var _repo$ident = repo.ident(),
email = _repo$ident.email,
name = _repo$ident.name;
if (email && name) {
return Promise.resolve(NodeGit.Signature.now(name, email));
}
return NodeGit.Signature.default(repo).catch(function () {
return NodeGit.Signature.now("unknown", "unknown");
});
};
/**
* Given a reference name, follows symbolic links and updates the direct
* reference to point to a given OID. Updates the reflog with a given message.
*
* @async
* @param {Repository} repo The repo where the reference and objects live
* @param {String} refName The reference name to update
* @param {Oid} oid The target OID that the reference will point to
* @param {String} logMessage The reflog message to be writted
* @param {Signature} signature Optional signature to use for the reflog entry
*/
Reference.updateTerminal = function (repo, refName, oid, logMessage, signature) {
var signatureToUse = void 0;
var promiseChain = Promise.resolve();
if (!signature) {
promiseChain = promiseChain.then(function () {
return getSignatureForReflog(repo);
}).then(function (sig) {
signatureToUse = sig;
return Promise.resolve();
});
} else {
signatureToUse = signature;
}
return promiseChain.then(function () {
return getTerminal(repo, refName);
}).then(function (_ref2) {
var error = _ref2.error,
out = _ref2.out;
if (error === NodeGit.Error.CODE.ENOTFOUND && out) {
return NodeGit.Reference.create(repo, out.symbolicTarget(), oid, 0, logMessage);
} else if (error === NodeGit.Error.CODE.ENOTFOUND) {
return NodeGit.Reference.create(repo, refName, oid, 0, logMessage);
} else {
return NodeGit.Reference.createMatching(repo, out.name(), oid, 1, out.target(), logMessage);
}
}).then(function () {
return NodeGit.Reflog.read(repo, refName);
}).then(function (reflog) {
// Janky, but works. Ideally, we would want to generate the correct reflog
// entry in the first place, rather than drop the most recent entry and
// write the correct one.
// NOTE: There is a theoretical race condition that could happen here.
// We may want to consider some kind of transactional logic to make sure
// that the reflog on disk isn't modified before we can write back.
reflog.drop(0, 1);
reflog.append(oid, signatureToUse, logMessage);
return reflog.write();
});
};
// Deprecated -----------------------------------------------------------------
Object.defineProperty(NodeGit.Reference.TYPE, "OID", {
get: util.deprecate(function () {
return NodeGit.Reference.TYPE.DIRECT;
}, "Use NodeGit.Reference.TYPE.DIRECT instead of NodeGit.Reference.TYPE.OID.")
});
Object.defineProperty(NodeGit.Reference.TYPE, "LISTALL", {
get: util.deprecate(function () {
return NodeGit.Reference.TYPE.ALL;
}, "Use NodeGit.Reference.TYPE.ALL instead of NodeGit.Reference.TYPE.LISTALL.")
});
NodeGit.Reference.NORMALIZE = {};
Object.keys(NodeGit.Reference.FORMAT).forEach(function (key) {
Object.defineProperty(NodeGit.Reference.NORMALIZE, "REF_FORMAT_" + key, {
get: util.deprecate(function () {
return NodeGit.Reference.FORMAT[key];
}, "Use NodeGit.Reference.FORMAT." + key + " instead of " + ("NodeGit.Reference.NORMALIZE.REF_FORMAT_" + key + "."))
});
});
+249
View File
@@ -0,0 +1,249 @@
"use strict";
var util = require("util");
var NodeGit = require("../");
var normalizeFetchOptions = NodeGit.Utils.normalizeFetchOptions;
var normalizeOptions = NodeGit.Utils.normalizeOptions;
var lookupWrapper = NodeGit.Utils.lookupWrapper;
var shallowClone = NodeGit.Utils.shallowClone;
var Remote = NodeGit.Remote;
var _connect = Remote.prototype.connect;
var _createWithOpts = Remote.createWithOpts;
var _disconnect = Remote.prototype.disconnect;
var _download = Remote.prototype.download;
var _fetch = Remote.prototype.fetch;
var _push = Remote.prototype.push;
var _updateTips = Remote.prototype.updateTips;
var _upload = Remote.prototype.upload;
/**
* Retrieves the remote by name
* @async
* @param {Repository} repo The repo that the remote lives in
* @param {String|Remote} name The remote to lookup
* @param {Function} callback
* @return {Remote}
*/
Remote.lookup = lookupWrapper(Remote);
/**
* Connects to a remote
*
* @async
* @param {Enums.DIRECTION} direction The direction for the connection
* @param {RemoteCallbacks} callbacks The callback functions for the connection
* @param {ProxyOptions} proxyOpts Proxy settings
* @param {Array<string>} customHeaders extra HTTP headers to use
* @param {Function} callback
* @return {Number} error code
*/
Remote.prototype.connect = function (direction, callbacks, proxyOpts, customHeaders) {
var _this = this;
callbacks = normalizeOptions(callbacks || {}, NodeGit.RemoteCallbacks);
proxyOpts = normalizeOptions(proxyOpts || {}, NodeGit.ProxyOptions);
customHeaders = customHeaders || [];
return _connect.call(this, direction, callbacks, proxyOpts, customHeaders).then(function () {
// Save options on the remote object. If we don't do this,
// the options may be cleaned up and cause a segfault
// when Remote.prototype.connect is called.
Object.defineProperties(_this, {
callbacks: {
configurable: true,
value: callbacks,
writable: false
},
proxyOpts: {
configurable: true,
value: proxyOpts,
writable: false
},
customHeaders: {
configurable: true,
value: customHeaders,
writable: false
}
});
});
};
Remote.createWithOpts = function (url, options) {
return _createWithOpts(url, normalizeOptions(options, NodeGit.RemoteCreateOptions));
};
Remote.prototype.disconnect = function () {
var _this2 = this;
return _disconnect.call(this).then(function () {
// Release the options
Object.defineProperties(_this2, {
callbacks: {
configurable: true,
value: undefined,
writable: false
},
proxyOpts: {
configurable: true,
value: undefined,
writable: false
},
customHeaders: {
configurable: true,
value: undefined,
writable: false
}
});
});
};
/**
* Connects to a remote
*
* @async
* @param {Array} refSpecs The ref specs that should be pushed
* @param {FetchOptions} opts The fetch options for download, contains callbacks
* @param {Function} callback
* @return {Number} error code
*/
Remote.prototype.download = function (refspecs, opts) {
return _download.call(this, refspecs, normalizeFetchOptions(opts));
};
/**
* Connects to a remote
*
* @async
* @param {Array} refSpecs The ref specs that should be pushed
* @param {FetchOptions} opts The fetch options for download, contains callbacks
* @param {String} message The message to use for the update reflog messages
* @param {Function} callback
* @return {Number} error code
*/
Remote.prototype.fetch = function (refspecs, opts, reflog_message) {
return _fetch.call(this, refspecs, normalizeFetchOptions(opts), reflog_message);
};
/**
* Pushes to a remote
*
* @async
* @param {Array} refSpecs The ref specs that should be pushed
* @param {PushOptions} options Options for the checkout
* @param {Function} callback
* @return {Number} error code
*/
Remote.prototype.push = function (refSpecs, opts) {
var callbacks;
var proxyOpts;
if (opts) {
opts = shallowClone(opts);
callbacks = opts.callbacks;
proxyOpts = opts.proxyOpts;
delete opts.callbacks;
delete opts.proxyOpts;
} else {
opts = {};
}
opts = normalizeOptions(opts, NodeGit.PushOptions);
if (callbacks) {
opts.callbacks = normalizeOptions(callbacks, NodeGit.RemoteCallbacks);
}
if (proxyOpts) {
opts.proxyOpts = normalizeOptions(proxyOpts, NodeGit.ProxyOptions);
}
return _push.call(this, refSpecs, opts);
};
/**
* Lists advertised references from a remote. You must connect to the remote
* before using referenceList.
*
* @async
* @return {Promise<Array<RemoteHead>>} a list of the remote heads the remote
* had available at the last established
* connection.
*
*/
Remote.prototype.referenceList = Remote.prototype.referenceList;
/**
* Update the tips to the new state
* @param {RemoteCallbacks} callbacks The callback functions for the connection
* @param {boolean} updateFetchhead whether to write to FETCH_HEAD. Pass true
* to behave like git.
* @param {boolean} downloadTags what the behaviour for downloading tags is
* for this fetch. This is ignored for push.
* This must be the same value passed to
* Remote.prototype.download
* @param {string} reflogMessage The message to insert into the reflogs. If
* null and fetching, the default is "fetch ",
* where is the name of the remote (or its url,
* for in-memory remotes). This parameter is
* ignored when pushing.
*/
Remote.prototype.updateTips = function (callbacks, updateFetchhead, downloadTags, reflogMessage) {
if (callbacks) {
callbacks = normalizeOptions(callbacks, NodeGit.RemoteCallbacks);
}
return _updateTips.call(this, callbacks, updateFetchhead, downloadTags, reflogMessage);
};
/**
* Pushes to a remote
*
* @async
* @param {Array} refSpecs The ref specs that should be pushed
* @param {PushOptions} options Options for the checkout
* @param {Function} callback
* @return {Number} error code
*/
Remote.prototype.upload = function (refSpecs, opts) {
var callbacks;
var proxyOpts;
if (opts) {
opts = shallowClone(opts);
callbacks = opts.callbacks;
proxyOpts = opts.proxyOpts;
delete opts.callbacks;
delete opts.proxyOpts;
} else {
opts = {};
}
opts = normalizeOptions(opts, NodeGit.PushOptions);
if (callbacks) {
opts.callbacks = normalizeOptions(callbacks, NodeGit.RemoteCallbacks);
}
if (proxyOpts) {
opts.proxyOpts = normalizeOptions(proxyOpts, NodeGit.ProxyOptions);
}
return _upload.call(this, refSpecs, opts);
};
NodeGit.Remote.COMPLETION_TYPE = {};
var DEPRECATED_STATES = {
COMPLETION_DOWNLOAD: "DOWNLOAD",
COMPLETION_INDEXING: "INDEXING",
COMPLETION_ERROR: "ERROR"
};
Object.keys(DEPRECATED_STATES).forEach(function (key) {
var newKey = DEPRECATED_STATES[key];
Object.defineProperty(NodeGit.Remote.COMPLETION_TYPE, key, {
get: util.deprecate(function () {
return NodeGit.Remote.COMPLETION[newKey];
}, "Use NodeGit.Remote.COMPLETION." + newKey + " instead of " + ("NodeGit.Remote.COMPLETION_TYPE." + key + "."))
});
});
+1629
View File
File diff suppressed because it is too large Load Diff
+78
View File
@@ -0,0 +1,78 @@
"use strict";
var NodeGit = require("../");
var normalizeOptions = NodeGit.Utils.normalizeOptions;
var Reset = NodeGit.Reset;
var _default = Reset.default;
var _reset = Reset.reset;
var _fromAnnotated = Reset.fromAnnotated;
/**
* Look up a refs's commit.
*
* @async
* @param {Repository} repo Repository where to perform the reset operation.
* @param {Commit|Tag} target The committish which content will be used to reset
* the content of the index.
* @param {Strarray} pathspecs List of pathspecs to operate on.
*
* @return {Number} 0 on success or an error code
*/
Reset.default = function (repo, target, pathspecs) {
return _default.call(this, repo, target, pathspecs);
};
/**
* Reset a repository's current HEAD to the specified target.
*
* @async
* @param {Repository} repo Repository where to perform the reset operation.
*
* @param {Commit|Tag} target Committish to which the Head should be moved to.
* This object must belong to the given `repo` and can
* either be a git_commit or a git_tag. When a git_tag is
* being passed, it should be dereferencable to a
* git_commit which oid will be used as the target of the
* branch.
* @param {Number} resetType Kind of reset operation to perform.
*
* @param {CheckoutOptions} opts Checkout options to be used for a HARD reset.
* The checkout_strategy field will be overridden
* (based on reset_type). This parameter can be
* used to propagate notify and progress
* callbacks.
*
* @return {Number} 0 on success or an error code
*/
Reset.reset = function (repo, target, resetType, opts) {
opts = normalizeOptions(opts, NodeGit.CheckoutOptions);
if (repo !== target.repo) {
// this is the same that is performed on libgit2's side
// https://github.com/nodegit/libgit2/blob/8d89e409616831b7b30a5ca7b89354957137b65e/src/reset.c#L120-L124
throw new Error("Repository and target commit's repository does not match");
}
return _reset.call(this, repo, target, resetType, opts);
};
/**
* Sets the current head to the specified commit oid and optionally
* resets the index and working tree to match.
*
* This behaves like reset but takes an annotated commit, which lets
* you specify which extended sha syntax string was specified by a
* user, allowing for more exact reflog messages.
*
* See the documentation for reset.
*
* @async
* @param {Repository} repo
* @param {AnnotatedCommit} target
* @param {Number} resetType
* @param {CheckoutOptions} opts
*/
Reset.fromAnnotated = function (repo, target, resetType, opts) {
opts = normalizeOptions(opts, NodeGit.CheckoutOptions);
return _fromAnnotated.call(this, repo, target, resetType, opts);
};
+63
View File
@@ -0,0 +1,63 @@
"use strict";
var NodeGit = require("../");
var shallowClone = NodeGit.Utils.shallowClone;
var normalizeOptions = NodeGit.Utils.normalizeOptions;
var Revert = NodeGit.Revert;
var _commit = Revert.commit;
var _revert = Revert.revert;
/**
* Reverts the given commit against the given "our" commit, producing an index
* that reflects the result of the revert.
*
* @async
* @param {Repository} repo the repository that contains the given commits.
* @param {Commit} revert_commit the commit to revert
* @param {Commit} our_commit the commit to revert against (e.g. HEAD)
* @param {Number} mainline the parent of the revert commit, if it is a merge
* @param {MergeOptions} merge_options the merge options (or null for defaults)
*
* @return {Index} the index result
*/
Revert.commit = function (repo, revert_commit, our_commit, mainline, merge_options) {
merge_options = normalizeOptions(merge_options, NodeGit.MergeOptions);
return _commit.call(this, repo, revert_commit, our_commit, mainline, merge_options);
};
/**
* Reverts the given commit, producing changes in the index and
* working directory.
*
* @async
* @param {Repository} repo the repository to perform the revert in
* @param {Commit} commit the commit to revert
* @param {RevertOptions} revert_options the revert options
* (or null for defaults)
*/
Revert.revert = function (repo, commit, revertOpts) {
var mergeOpts;
var checkoutOpts;
if (revertOpts) {
revertOpts = shallowClone(revertOpts);
mergeOpts = revertOpts.mergeOpts;
checkoutOpts = revertOpts.checkoutOpts;
delete revertOpts.mergeOpts;
delete revertOpts.checkoutOpts;
}
revertOpts = normalizeOptions(revertOpts, NodeGit.RevertOptions);
if (mergeOpts) {
revertOpts.mergeOpts = normalizeOptions(mergeOpts, NodeGit.MergeOptions);
}
if (checkoutOpts) {
revertOpts.checkoutOpts = normalizeOptions(checkoutOpts, NodeGit.CheckoutOptions);
}
return _revert.call(this, repo, commit, revertOpts);
};
+146
View File
@@ -0,0 +1,146 @@
"use strict";
var NodeGit = require("../");
var Revwalk = NodeGit.Revwalk;
Object.defineProperty(Revwalk.prototype, "repo", {
get: function get() {
return this.repository();
},
configurable: true
});
var _sorting = Revwalk.prototype.sorting;
/**
* @typedef historyEntry
* @type {Object}
* @property {Commit} commit the commit for this entry
* @property {Number} status the status of the file in the commit
* @property {String} newName the new name that is provided when status is
* renamed
* @property {String} oldName the old name that is provided when status is
* renamed
*/
var fileHistoryWalk = Revwalk.prototype.fileHistoryWalk;
/**
* @param {String} filePath
* @param {Number} max_count
* @async
* @return {Array<historyEntry>}
*/
Revwalk.prototype.fileHistoryWalk = fileHistoryWalk;
/**
* Get a number of commits.
*
* @async
* @param {Number} count (default: 10)
* @return {Array<Commit>}
*/
Revwalk.prototype.getCommits = function (count) {
count = count || 10;
var promises = [];
var walker = this;
function walkCommitsCount(count) {
if (count === 0) {
return;
}
return walker.next().then(function (oid) {
promises.push(walker.repo.getCommit(oid));
return walkCommitsCount(count - 1);
}).catch(function (error) {
if (error.errno !== NodeGit.Error.CODE.ITEROVER) {
throw error;
}
});
}
return walkCommitsCount(count).then(function () {
return Promise.all(promises);
});
};
/**
* Walk the history grabbing commits until the checkFn called with the
* current commit returns false.
*
* @async
* @param {Function} checkFn function returns false to stop walking
* @return {Array}
*/
Revwalk.prototype.getCommitsUntil = function (checkFn) {
var commits = [];
var walker = this;
function walkCommitsCb() {
return walker.next().then(function (oid) {
return walker.repo.getCommit(oid).then(function (commit) {
commits.push(commit);
if (checkFn(commit)) {
return walkCommitsCb();
}
});
}).catch(function (error) {
if (error.errno !== NodeGit.Error.CODE.ITEROVER) {
throw error;
}
});
}
return walkCommitsCb().then(function () {
return commits;
});
};
/**
* Set the sort order for the revwalk. This function takes variable arguments
* like `revwalk.sorting(NodeGit.RevWalk.Topological, NodeGit.RevWalk.Reverse).`
*
* @param {Number} sort
*/
Revwalk.prototype.sorting = function () {
var sort = 0;
for (var i = 0; i < arguments.length; i++) {
sort |= arguments[i];
}
_sorting.call(this, sort);
};
/**
* Walk the history from the given oid. The callback is invoked for each commit;
* When the walk is over, the callback is invoked with `(null, null)`.
*
* @param {Oid} oid
* @param {Function} callback
*/
Revwalk.prototype.walk = function (oid, callback) {
var revwalk = this;
this.push(oid);
function walk() {
revwalk.next().then(function (oid) {
if (!oid) {
if (typeof callback === "function") {
return callback();
}
return;
}
revwalk.repo.getCommit(oid).then(function (commit) {
if (typeof callback === "function") {
callback(null, commit);
}
walk();
});
}, callback);
}
walk();
};
+40
View File
@@ -0,0 +1,40 @@
"use strict";
var NodeGit = require("../");
var Signature = NodeGit.Signature;
var toPaddedDoubleDigitString = function toPaddedDoubleDigitString(number) {
if (number < 10) {
return "0" + number;
}
return "" + number;
};
/**
* Standard string representation of an author.
* @param {Boolean} withTime Whether or not to include timestamp
* @return {String} Representation of the author.
*/
Signature.prototype.toString = function (withTime) {
var name = this.name().toString();
var email = this.email().toString();
var stringifiedSignature = name + " <" + email + ">";
if (!withTime) {
return stringifiedSignature;
}
var when = this.when();
var offset = when.offset();
var offsetMagnitude = Math.abs(offset);
var time = when.time();
var sign = offset < 0 || when.sign() === "-" ? "-" : "+";
var hours = toPaddedDoubleDigitString(Math.floor(offsetMagnitude / 60));
var minutes = toPaddedDoubleDigitString(offsetMagnitude % 60);
stringifiedSignature += " " + time + " " + sign + hours + minutes;
return stringifiedSignature;
};
+62
View File
@@ -0,0 +1,62 @@
"use strict";
var NodeGit = require("../");
var normalizeOptions = NodeGit.Utils.normalizeOptions;
var shallowClone = NodeGit.Utils.shallowClone;
var Stash = NodeGit.Stash;
var _apply = Stash.apply;
var _foreach = Stash.foreach;
var _pop = Stash.pop;
Stash.apply = function (repo, index, options) {
var checkoutOptions;
if (options) {
options = shallowClone(options);
checkoutOptions = options.checkoutOptions;
delete options.checkoutOptions;
} else {
options = {};
}
options = normalizeOptions(options, NodeGit.StashApplyOptions);
if (checkoutOptions) {
options.checkoutOptions = normalizeOptions(checkoutOptions, NodeGit.CheckoutOptions);
}
return _apply(repo, index, options);
};
// Override Stash.foreach to eliminate the need to pass null payload
Stash.foreach = function (repo, callback) {
function wrappedCallback(index, message, oid) {
// We need to copy the OID since libgit2 types are getting cleaned up
// incorrectly right now in callbacks
return callback(index, message, oid.copy());
}
return _foreach(repo, wrappedCallback, null);
};
Stash.pop = function (repo, index, options) {
var checkoutOptions;
if (options) {
options = shallowClone(options);
checkoutOptions = options.checkoutOptions;
delete options.checkoutOptions;
} else {
options = {};
}
options = normalizeOptions(options, NodeGit.StashApplyOptions);
if (checkoutOptions) {
options.checkoutOptions = normalizeOptions(checkoutOptions, NodeGit.CheckoutOptions);
}
return _pop(repo, index, options);
};
+20
View File
@@ -0,0 +1,20 @@
"use strict";
var NodeGit = require("../");
var normalizeOptions = NodeGit.Utils.normalizeOptions;
var Status = NodeGit.Status;
var _foreach = Status.foreach;
var _foreachExt = Status.foreachExt;
// Override Status.foreach to eliminate the need to pass null payload
Status.foreach = function (repo, callback) {
return _foreach(repo, callback, null);
};
// Override Status.foreachExt to normalize opts
Status.foreachExt = function (repo, opts, callback) {
opts = normalizeOptions(opts, NodeGit.StatusOptions);
return _foreachExt(repo, opts, callback, null);
};
+95
View File
@@ -0,0 +1,95 @@
"use strict";
var NodeGit = require("../");
var Status = NodeGit.Status;
var StatusFile = function StatusFile(args) {
var path = args.path;
var status = args.status;
var entry = args.entry;
if (entry) {
status = entry.status();
if (entry.indexToWorkdir()) {
path = entry.indexToWorkdir().newFile().path();
} else {
path = entry.headToIndex().newFile().path();
}
}
var codes = Status.STATUS;
var getStatus = function getStatus() {
var fileStatuses = [];
for (var key in Status.STATUS) {
if (status & Status.STATUS[key]) {
fileStatuses.push(key);
}
}
return fileStatuses;
};
var data = {
path: path,
entry: entry,
statusBit: status,
statuses: getStatus()
};
return {
headToIndex: function headToIndex() {
if (data.entry) {
return entry.headToIndex();
} else {
return undefined;
}
},
indexToWorkdir: function indexToWorkdir() {
if (data.entry) {
return entry.indexToWorkdir();
} else {
return undefined;
}
},
inIndex: function inIndex() {
return status & codes.INDEX_NEW || status & codes.INDEX_MODIFIED || status & codes.INDEX_DELETED || status & codes.INDEX_TYPECHANGE || status & codes.INDEX_RENAMED;
},
inWorkingTree: function inWorkingTree() {
return status & codes.WT_NEW || status & codes.WT_MODIFIED || status & codes.WT_DELETED || status & codes.WT_TYPECHANGE || status & codes.WT_RENAMED;
},
isConflicted: function isConflicted() {
return status & codes.CONFLICTED;
},
isDeleted: function isDeleted() {
return status & codes.WT_DELETED || status & codes.INDEX_DELETED;
},
isIgnored: function isIgnored() {
return status & codes.IGNORED;
},
isModified: function isModified() {
return status & codes.WT_MODIFIED || status & codes.INDEX_MODIFIED;
},
isNew: function isNew() {
return status & codes.WT_NEW || status & codes.INDEX_NEW;
},
isRenamed: function isRenamed() {
return status & codes.WT_RENAMED || status & codes.INDEX_RENAMED;
},
isTypechange: function isTypechange() {
return status & codes.WT_TYPECHANGE || status & codes.INDEX_TYPECHANGE;
},
path: function path() {
return data.path;
},
status: function status() {
return data.statuses;
},
statusBit: function statusBit() {
return data.statusBit;
}
};
};
NodeGit.StatusFile = StatusFile;
+14
View File
@@ -0,0 +1,14 @@
"use strict";
var NodeGit = require("../");
var normalizeOptions = NodeGit.Utils.normalizeOptions;
var StatusList = NodeGit.StatusList;
var _create = StatusList.create;
// Override StatusList.create to normalize opts
StatusList.create = function (repo, opts) {
opts = normalizeOptions(opts, NodeGit.StatusOptions);
return _create(repo, opts);
};
+50
View File
@@ -0,0 +1,50 @@
"use strict";
var NodeGit = require("../");
var normalizeFetchOptions = NodeGit.Utils.normalizeFetchOptions;
var normalizeOptions = NodeGit.Utils.normalizeOptions;
var shallowClone = NodeGit.Utils.shallowClone;
var Submodule = NodeGit.Submodule;
var _foreach = Submodule.foreach;
var _update = Submodule.prototype.update;
// Override Submodule.foreach to eliminate the need to pass null payload
Submodule.foreach = function (repo, callback) {
return _foreach(repo, callback, null);
};
/**
* Updates a submodule
*
* @async
* @param {Number} init Setting this to 1 will initialize submodule
* before updating
* @param {SubmoduleUpdateOptions} options Submodule update settings
* @return {Number} 0 on success, any non-zero return value from a callback
*/
Submodule.prototype.update = function (init, options) {
var fetchOpts;
var checkoutOpts;
if (options) {
options = shallowClone(options);
fetchOpts = options.fetchOpts;
checkoutOpts = options.checkoutOpts;
delete options.fetchOpts;
delete options.checkoutOpts;
}
options = normalizeOptions(options, NodeGit.SubmoduleUpdateOptions);
if (fetchOpts) {
options.fetchOpts = normalizeFetchOptions(fetchOpts);
}
if (checkoutOpts) {
options.checkoutOpts = normalizeOptions(checkoutOpts, NodeGit.CheckoutOptions);
}
return _update.call(this, init, options);
};
+134
View File
@@ -0,0 +1,134 @@
"use strict";
var NodeGit = require("../");
var LookupWrapper = NodeGit.Utils.lookupWrapper;
var Tag = NodeGit.Tag;
var signatureRegexesBySignatureType = {
gpgsig: [/-----BEGIN PGP SIGNATURE-----[\s\S]+?-----END PGP SIGNATURE-----/gm, /-----BEGIN PGP MESSAGE-----[\s\S]+?-----END PGP MESSAGE-----/gm],
x509: [/-----BEGIN SIGNED MESSAGE-----[\s\S]+?-----END SIGNED MESSAGE-----/gm]
};
/**
* Retrieves the tag pointed to by the oid
* @async
* @param {Repository} repo The repo that the tag lives in
* @param {String|Oid|Tag} id The tag to lookup
* @return {Tag}
*/
Tag.lookup = LookupWrapper(Tag);
/**
* @async
* @param {Repository} repo
* @param {String} tagName
* @param {Oid} target
* @param {Signature} tagger
* @return {String}
*/
Tag.createBuffer = function (repo, tagName, target, tagger, message) {
return NodeGit.Object.lookup(repo, target, NodeGit.Object.TYPE.ANY).then(function (object) {
if (!NodeGit.Object.typeisloose(object.type())) {
throw new Error("Object must be a loose type");
}
var id = object.id().toString();
var objectType = NodeGit.Object.type2String(object.type());
var lines = ["object " + id, "type " + objectType, "tag " + tagName, "tagger " + tagger.toString(true) + "\n", "" + message + (message.endsWith("\n") ? "" : "\n")];
return lines.join("\n");
});
};
/**
* @async
* @param {Repository} repo
* @param {String} tagName
* @param {Oid} target
* @param {Signature} tagger
* @param {String} message
* @param {Number} force
* @param {Function} signingCallback Takes a string and returns a string
* representing the signed message
* @return {Oid}
*/
Tag.createWithSignature = function (repo, tagName, target, tagger, message, force, signingCallback) {
var tagBuffer = void 0;
return Tag.createBuffer(repo, tagName, target, tagger, message).then(function (tagBufferResult) {
tagBuffer = tagBufferResult;
return signingCallback(tagBuffer);
}).then(function (_ref) {
var code = _ref.code,
signedData = _ref.signedData;
switch (code) {
case NodeGit.Error.CODE.OK:
{
var normalizedEnding = signedData.endsWith("\n") ? "" : "\n";
var signedTagString = tagBuffer + signedData + normalizedEnding;
return Tag.createFromBuffer(repo, signedTagString, force);
}
case NodeGit.Error.CODE.PASSTHROUGH:
return Tag.create(repo, tagName, target, tagger, message, force);
default:
{
var error = new Error("Tag.createWithSignature threw with error code " + code);
error.errno = code;
throw error;
}
}
});
};
/**
* Retrieves the signature of an annotated tag
* @async
* @param {String} signatureType
* @return {String|null}
*/
Tag.prototype.extractSignature = function () {
var signatureType = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : "gpgsig";
var id = this.id();
var repo = this.repo;
var signatureRegexes = signatureRegexesBySignatureType[signatureType];
if (!signatureRegexes) {
throw new Error("Unsupported signature type");
}
return repo.odb().then(function (odb) {
return odb.read(id);
}).then(function (odbObject) {
var odbData = odbObject.toString();
var _iteratorNormalCompletion = true;
var _didIteratorError = false;
var _iteratorError = undefined;
try {
for (var _iterator = signatureRegexes[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
var regex = _step.value;
var matchResult = odbData.match(regex);
if (matchResult !== null) {
return matchResult[0];
}
}
} catch (err) {
_didIteratorError = true;
_iteratorError = err;
} finally {
try {
if (!_iteratorNormalCompletion && _iterator.return) {
_iterator.return();
}
} finally {
if (_didIteratorError) {
throw _iteratorError;
}
}
}
throw new Error("this tag is not signed");
});
};
+178
View File
@@ -0,0 +1,178 @@
"use strict";
var path = require("path");
var events = require("events");
var NodeGit = require("../");
var Diff = NodeGit.Diff;
var LookupWrapper = NodeGit.Utils.lookupWrapper;
var Tree = NodeGit.Tree;
var Treebuilder = NodeGit.Treebuilder;
/**
* Retrieves the tree pointed to by the oid
* @async
* @param {Repository} repo The repo that the tree lives in
* @param {String|Oid|Tree} id The tree to lookup
* @return {Tree}
*/
Tree.lookup = LookupWrapper(Tree);
/**
* Make builder. This is helpful for modifying trees.
* @return {Treebuilder}
*/
Tree.prototype.builder = function () {
var builder = Treebuilder.create(this);
builder.root = builder;
builder.repo = this.repo;
return builder;
};
/**
* Diff two trees
* @async
* @param {Tree} tree to diff against
* @return {Diff}
*/
Tree.prototype.diff = function (tree) {
return this.diffWithOptions(tree, null);
};
/**
* Diff two trees with options
* @async
* @param {Tree} tree to diff against
* @param {Object} options
* @return {Diff}
*/
Tree.prototype.diffWithOptions = function (tree, options) {
return Diff.treeToTree(this.repo, tree, this, options);
};
/**
* Return an array of the entries in this tree (excluding its children).
* @return {Array<TreeEntry>} an array of TreeEntrys
*/
Tree.prototype.entries = function () {
var size = this.entryCount();
var result = [];
for (var i = 0; i < size; i++) {
result.push(this.entryByIndex(i));
}
return result;
};
/**
* Get an entry at the ith position.
*
* @param {Number} i
* @return {TreeEntry}
*/
Tree.prototype.entryByIndex = function (i) {
var entry = this._entryByIndex(i);
entry.parent = this;
return entry;
};
/**
* Get an entry by name; if the tree is a directory, the name is the filename.
*
* @param {String} name
* @return {TreeEntry}
*/
Tree.prototype.entryByName = function (name) {
var entry = this._entryByName(name);
entry.parent = this;
return entry;
};
/**
* Get an entry at a path. Unlike by name, this takes a fully
* qualified path, like `/foo/bar/baz.javascript`
* @async
* @param {String} filePath
* @return {TreeEntry}
*/
Tree.prototype.getEntry = function (filePath) {
var tree = this;
return this.entryByPath(filePath).then(function (entry) {
entry.parent = tree;
entry.dirtoparent = path.dirname(filePath);
return entry;
});
};
/**
* Return the path of this tree, like `/lib/foo/bar`
* @return {String}
*/
Tree.prototype.path = function (blobsOnly) {
return this.entry ? this.entry.path() : "";
};
/**
* Recursively walk the tree in breadth-first order. Fires an event for each
* entry.
*
* @fires EventEmitter#entry Tree
* @fires EventEmitter#end Array<Tree>
* @fires EventEmitter#error Error
*
* @param {Boolean} [blobsOnly = true] True to emit only blob & blob executable
* entries.
*
* @return {EventEmitter}
*/
Tree.prototype.walk = function (blobsOnly) {
blobsOnly = typeof blobsOnly === "boolean" ? blobsOnly : true;
var self = this;
var event = new events.EventEmitter();
var total = 1;
var entries = new Set();
var finalEntires = [];
// This looks like a DFS, but it is a BFS because of implicit queueing in
// the recursive call to `entry.getTree(bfs)`
function bfs(error, tree) {
total--;
if (error) {
return event.emit("error", error);
}
tree.entries().forEach(function (entry, entryIndex) {
if (!blobsOnly || entry.isFile() && !entries.has(entry)) {
event.emit("entry", entry);
entries.add(entry);
// Node 0.12 doesn't support either [v for (v of entries)] nor
// Array.from so we'll just maintain our own list.
finalEntires.push(entry);
}
if (entry.isTree()) {
total++;
entry.getTree().then(function (result) {
return bfs(null, result);
}, bfs);
}
});
if (total === 0) {
event.emit("end", finalEntires);
}
}
event.start = function () {
bfs(null, self);
};
return event;
};
+100
View File
@@ -0,0 +1,100 @@
"use strict";
var path = require("path").posix;
var NodeGit = require("../");
var TreeEntry = NodeGit.TreeEntry;
/**
* Retrieve the blob for this entry. Make sure to call `isBlob` first!
* @async
* @return {Blob}
*/
TreeEntry.prototype.getBlob = function () {
return this.parent.repo.getBlob(this.id());
};
/**
* Retrieve the tree for this entry. Make sure to call `isTree` first!
* @async
* @return {Tree}
*/
TreeEntry.prototype.getTree = function () {
var entry = this;
return this.parent.repo.getTree(this.id()).then(function (tree) {
tree.entry = entry;
return tree;
});
};
/**
* Is this TreeEntry a blob? Alias for `isFile`
* @return {Boolean}
*/
TreeEntry.prototype.isBlob = function () {
return this.isFile();
};
/**
* Is this TreeEntry a directory? Alias for `isTree`
* @return {Boolean}
*/
TreeEntry.prototype.isDirectory = function () {
return this.isTree();
};
/**
* Is this TreeEntry a blob? (i.e., a file)
* @return {Boolean}
*/
TreeEntry.prototype.isFile = function () {
return this.filemode() === TreeEntry.FILEMODE.BLOB || this.filemode() === TreeEntry.FILEMODE.EXECUTABLE;
};
/**
* Is this TreeEntry a submodule?
* @return {Boolean}
*/
TreeEntry.prototype.isSubmodule = function () {
return this.filemode() === TreeEntry.FILEMODE.COMMIT;
};
/**
* Is this TreeEntry a tree? (i.e., a directory)
* @return {Boolean}
*/
TreeEntry.prototype.isTree = function () {
return this.filemode() === TreeEntry.FILEMODE.TREE;
};
/**
* Retrieve the SHA for this TreeEntry. Alias for `sha`
* @return {String}
*/
TreeEntry.prototype.oid = function () {
return this.sha();
};
/**
* Returns the path for this entry.
* @return {String}
*/
TreeEntry.prototype.path = function () {
var dirtoparent = this.dirtoparent || "";
return path.join(this.parent.path(), dirtoparent, this.name());
};
/**
* Retrieve the SHA for this TreeEntry.
* @return {String}
*/
TreeEntry.prototype.sha = function () {
return this.id().toString();
};
/**
* Alias for `path`
*/
TreeEntry.prototype.toString = function () {
return this.path();
};
+41
View File
@@ -0,0 +1,41 @@
"use strict";
var NodeGit = require("../../");
/**
* Wraps a method so that you can pass in either a string, OID or the object
* itself and you will always get back a promise that resolves to the object.
* @param {Object} objectType The object type that you're expecting to receive.
* @param {Function} lookupFunction The function to do the lookup for the
* object. Defaults to `objectType.lookup`.
* @return {Function}
*/
function lookupWrapper(objectType, lookupFunction) {
lookupFunction = lookupFunction || objectType.lookup;
return function (repo, id, callback) {
if (id instanceof objectType) {
return Promise.resolve(id).then(function (obj) {
obj.repo = repo;
if (typeof callback === "function") {
callback(null, obj);
}
return obj;
}, callback);
}
return lookupFunction(repo, id).then(function (obj) {
obj.repo = repo;
if (typeof callback === "function") {
callback(null, obj);
}
return obj;
}, callback);
};
}
NodeGit.Utils.lookupWrapper = lookupWrapper;
+43
View File
@@ -0,0 +1,43 @@
"use strict";
var NodeGit = require("../../");
var normalizeOptions = NodeGit.Utils.normalizeOptions;
var shallowClone = NodeGit.Utils.shallowClone;
/**
* Normalize an object to match a struct.
*
* @param {String, Object} oid - The oid string or instance.
* @return {Object} An Oid instance.
*/
function normalizeFetchOptions(options) {
if (options instanceof NodeGit.FetchOptions) {
return options;
}
var callbacks;
var proxyOpts;
if (options) {
options = shallowClone(options);
callbacks = options.callbacks;
proxyOpts = options.proxyOpts;
delete options.callbacks;
delete options.proxyOpts;
} else {
options = {};
}
options = normalizeOptions(options, NodeGit.FetchOptions);
if (callbacks) {
options.callbacks = normalizeOptions(callbacks, NodeGit.RemoteCallbacks);
}
if (proxyOpts) {
options.proxyOpts = normalizeOptions(proxyOpts, NodeGit.ProxyOptions);
}
return options;
}
NodeGit.Utils.normalizeFetchOptions = normalizeFetchOptions;
+31
View File
@@ -0,0 +1,31 @@
"use strict";
var NodeGit = require("../../");
/**
* Normalize an object to match a struct.
*
* @param {String, Object} oid - The oid string or instance.
* @return {Object} An Oid instance.
*/
function normalizeOptions(options, Ctor) {
if (!options) {
return null;
}
if (options instanceof Ctor) {
return options;
}
var instance = new Ctor();
Object.keys(options).forEach(function (key) {
if (typeof options[key] !== "undefined") {
instance[key] = options[key];
}
});
return instance;
}
NodeGit.Utils.normalizeOptions = normalizeOptions;
+16
View File
@@ -0,0 +1,16 @@
"use strict";
var NodeGit = require("../../");
function shallowClone() {
var merges = Array.prototype.slice.call(arguments);
return merges.reduce(function (obj, merge) {
return Object.keys(merge).reduce(function (obj, key) {
obj[key] = merge[key];
return obj;
}, obj);
}, {});
}
NodeGit.Utils.shallowClone = shallowClone;