@swimlane/nodegit 1.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.dockerignore +2 -0
- package/.github/workflows/publish.yml +126 -0
- package/.github/workflows/tests.yml +85 -0
- package/LICENSE +19 -0
- package/README.md +193 -0
- package/lib/attr.js +20 -0
- package/lib/blob.js +51 -0
- package/lib/branch.js +19 -0
- package/lib/buf.js +43 -0
- package/lib/commit.js +437 -0
- package/lib/config.js +48 -0
- package/lib/convenient_hunks.js +61 -0
- package/lib/convenient_patch.js +131 -0
- package/lib/credential.js +33 -0
- package/lib/deprecated/structs/ApplyOptions.js +3 -0
- package/lib/deprecated/structs/BlameOptions.js +6 -0
- package/lib/deprecated/structs/BlobFilterOptions.js +3 -0
- package/lib/deprecated/structs/CheckoutOptions.js +8 -0
- package/lib/deprecated/structs/CherrypickOptions.js +5 -0
- package/lib/deprecated/structs/CloneOptions.js +6 -0
- package/lib/deprecated/structs/DescribeFormatOptions.js +4 -0
- package/lib/deprecated/structs/DescribeOptions.js +6 -0
- package/lib/deprecated/structs/DiffFindOptions.js +8 -0
- package/lib/deprecated/structs/DiffOptions.js +8 -0
- package/lib/deprecated/structs/FetchOptions.js +7 -0
- package/lib/deprecated/structs/MergeFileInput.js +4 -0
- package/lib/deprecated/structs/MergeFileOptions.js +5 -0
- package/lib/deprecated/structs/MergeOptions.js +8 -0
- package/lib/deprecated/structs/ProxyOptions.js +3 -0
- package/lib/deprecated/structs/PushOptions.js +5 -0
- package/lib/deprecated/structs/RebaseOptions.js +6 -0
- package/lib/deprecated/structs/RemoteCreateOptions.js +3 -0
- package/lib/deprecated/structs/RepositoryInitOptions.js +4 -0
- package/lib/deprecated/structs/RevertOptions.js +5 -0
- package/lib/deprecated/structs/StashApplyOptions.js +4 -0
- package/lib/deprecated/structs/StatusOptions.js +4 -0
- package/lib/deprecated/structs/SubmoduleUpdateOptions.js +5 -0
- package/lib/diff.js +67 -0
- package/lib/diff_file.js +38 -0
- package/lib/diff_line.js +32 -0
- package/lib/error.js +17 -0
- package/lib/filter_registry.js +22 -0
- package/lib/graph.js +15 -0
- package/lib/index.js +103 -0
- package/lib/merge.js +41 -0
- package/lib/note.js +17 -0
- package/lib/object.js +45 -0
- package/lib/odb_object.js +9 -0
- package/lib/oid.js +23 -0
- package/lib/rebase.js +86 -0
- package/lib/reference.js +213 -0
- package/lib/remote.js +45 -0
- package/lib/repository.js +1973 -0
- package/lib/reset.js +51 -0
- package/lib/revparse.js +18 -0
- package/lib/revwalk.js +142 -0
- package/lib/signature.js +38 -0
- package/lib/stash.js +16 -0
- package/lib/status.js +16 -0
- package/lib/status_file.js +106 -0
- package/lib/submodule.js +10 -0
- package/lib/tag.js +141 -0
- package/lib/tree.js +175 -0
- package/lib/tree_entry.js +99 -0
- package/lib/utils/lookup_wrapper.js +39 -0
- package/lib/utils/shallow_clone.js +14 -0
- package/lifecycleScripts/clean.js +5 -0
- package/lifecycleScripts/install.js +32 -0
- package/lifecycleScripts/postinstall.js +83 -0
- package/lifecycleScripts/preinstall.js +47 -0
- package/lifecycleScripts/submodules/getStatus.js +50 -0
- package/lifecycleScripts/submodules/index.js +84 -0
- package/package.json +83 -0
- package/prebuilds/darwin-arm64/@swimlane+nodegit.glibc.node +0 -0
- package/prebuilds/darwin-x64/@swimlane+nodegit.glibc.node +0 -0
- package/prebuilds/linux-arm64/@swimlane+nodegit.glibc.node +0 -0
- package/prebuilds/linux-x64/@swimlane+nodegit.glibc.node +0 -0
- package/prebuilds/linux-x64/@swimlane+nodegit.musl.node +0 -0
- package/scripts/Dockerfile.alpine +10 -0
- package/scripts/Dockerfile.debian +15 -0
- package/utils/acquireOpenSSL.js +436 -0
- package/utils/build-openssl.bat +13 -0
- package/utils/buildFlags.js +19 -0
- package/utils/configureLibssh2.js +54 -0
- package/utils/defaultCxxStandard.js +18 -0
- package/utils/execPromise.js +24 -0
- package/utils/getElectronOpenSSLRoot.js +10 -0
- package/utils/gitExecutableLocation.js +23 -0
- package/utils/isBuildingForElectron.js +30 -0
- package/utils/retry.js +51 -0
package/lib/reset.js
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
var NodeGit = require("../");
|
|
2
|
+
|
|
3
|
+
var Reset = NodeGit.Reset;
|
|
4
|
+
var _default = Reset.default;
|
|
5
|
+
var _reset = Reset.reset;
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Look up a refs's commit.
|
|
9
|
+
*
|
|
10
|
+
* @async
|
|
11
|
+
* @param {Repository} repo Repository where to perform the reset operation.
|
|
12
|
+
* @param {Commit|Tag} target The committish which content will be used to reset
|
|
13
|
+
* the content of the index.
|
|
14
|
+
* @param {Strarray} pathspecs List of pathspecs to operate on.
|
|
15
|
+
*
|
|
16
|
+
* @return {Number} 0 on success or an error code
|
|
17
|
+
*/
|
|
18
|
+
Reset.default = function(repo, target, pathspecs) {
|
|
19
|
+
return _default.call(this, repo, target, pathspecs);
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Reset a repository's current HEAD to the specified target.
|
|
24
|
+
*
|
|
25
|
+
* @async
|
|
26
|
+
* @param {Repository} repo Repository where to perform the reset operation.
|
|
27
|
+
*
|
|
28
|
+
* @param {Commit|Tag} target Committish to which the Head should be moved to.
|
|
29
|
+
* This object must belong to the given `repo` and can
|
|
30
|
+
* either be a git_commit or a git_tag. When a git_tag is
|
|
31
|
+
* being passed, it should be dereferencable to a
|
|
32
|
+
* git_commit which oid will be used as the target of the
|
|
33
|
+
* branch.
|
|
34
|
+
* @param {Number} resetType Kind of reset operation to perform.
|
|
35
|
+
*
|
|
36
|
+
* @param {CheckoutOptions} opts Checkout options to be used for a HARD reset.
|
|
37
|
+
* The checkout_strategy field will be overridden
|
|
38
|
+
* (based on reset_type). This parameter can be
|
|
39
|
+
* used to propagate notify and progress
|
|
40
|
+
* callbacks.
|
|
41
|
+
*
|
|
42
|
+
* @return {Number} 0 on success or an error code
|
|
43
|
+
*/
|
|
44
|
+
Reset.reset = function(repo, target, resetType, opts) {
|
|
45
|
+
if (repo !== target.repo) {
|
|
46
|
+
// this is the same that is performed on libgit2's side
|
|
47
|
+
// https://github.com/nodegit/libgit2/blob/8d89e409616831b7b30a5ca7b89354957137b65e/src/reset.c#L120-L124
|
|
48
|
+
throw new Error("Repository and target commit's repository does not match");
|
|
49
|
+
}
|
|
50
|
+
return _reset.call(this, repo, target, resetType, opts);
|
|
51
|
+
};
|
package/lib/revparse.js
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
var util = require("util");
|
|
2
|
+
var NodeGit = require("../");
|
|
3
|
+
|
|
4
|
+
const MODE = {
|
|
5
|
+
SINGLE: 1,
|
|
6
|
+
RANGE: 2,
|
|
7
|
+
MERGE_BASE: 4,
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
NodeGit.Revparse.MODE = {};
|
|
11
|
+
Object.keys(MODE).forEach((key) => {
|
|
12
|
+
Object.defineProperty(NodeGit.Revparse.MODE, key, {
|
|
13
|
+
get: util.deprecate(
|
|
14
|
+
() => MODE[key],
|
|
15
|
+
`Use NodeGit.Revspec.TYPE.${key} instead of NodeGit.Revparse.MODE.${key}.`
|
|
16
|
+
)
|
|
17
|
+
});
|
|
18
|
+
});
|
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
|
+
};
|
package/lib/signature.js
ADDED
|
@@ -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,16 @@
|
|
|
1
|
+
var NodeGit = require("../");
|
|
2
|
+
var Stash = NodeGit.Stash;
|
|
3
|
+
|
|
4
|
+
var _foreach = Stash.foreach;
|
|
5
|
+
|
|
6
|
+
// Override Stash.foreach to eliminate the need to pass null payload
|
|
7
|
+
Stash.foreach = function(repo, callback) {
|
|
8
|
+
function wrappedCallback(index, message, oid) {
|
|
9
|
+
// We need to copy the OID since libgit2 types are getting cleaned up
|
|
10
|
+
// incorrectly right now in callbacks
|
|
11
|
+
|
|
12
|
+
return callback(index, message, oid.copy());
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
return _foreach(repo, wrappedCallback, null);
|
|
16
|
+
};
|
package/lib/status.js
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
var NodeGit = require("../");
|
|
2
|
+
|
|
3
|
+
var Status = NodeGit.Status;
|
|
4
|
+
|
|
5
|
+
var _foreach = Status.foreach;
|
|
6
|
+
var _foreachExt = Status.foreachExt;
|
|
7
|
+
|
|
8
|
+
// Override Status.foreach to eliminate the need to pass null payload
|
|
9
|
+
Status.foreach = function(repo, callback) {
|
|
10
|
+
return _foreach(repo, callback, null);
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
// Override Status.foreachExt to eliminate the need to pass null payload
|
|
14
|
+
Status.foreachExt = function(repo, opts, callback) {
|
|
15
|
+
return _foreachExt(repo, opts, callback, null);
|
|
16
|
+
};
|
|
@@ -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;
|
package/lib/submodule.js
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
var NodeGit = require("../");
|
|
2
|
+
|
|
3
|
+
var Submodule = NodeGit.Submodule;
|
|
4
|
+
|
|
5
|
+
var _foreach = Submodule.foreach;
|
|
6
|
+
|
|
7
|
+
// Override Submodule.foreach to eliminate the need to pass null payload
|
|
8
|
+
Submodule.foreach = function(repo, callback) {
|
|
9
|
+
return _foreach(repo, callback, null);
|
|
10
|
+
};
|
package/lib/tag.js
ADDED
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
var util = require("util");
|
|
2
|
+
var NodeGit = require("../");
|
|
3
|
+
var LookupWrapper = NodeGit.Utils.lookupWrapper;
|
|
4
|
+
var Tag = NodeGit.Tag;
|
|
5
|
+
|
|
6
|
+
const signatureRegexesBySignatureType = {
|
|
7
|
+
gpgsig: [
|
|
8
|
+
/-----BEGIN PGP SIGNATURE-----[\s\S]+?-----END PGP SIGNATURE-----/gm,
|
|
9
|
+
/-----BEGIN PGP MESSAGE-----[\s\S]+?-----END PGP MESSAGE-----/gm,
|
|
10
|
+
],
|
|
11
|
+
x509: [
|
|
12
|
+
/-----BEGIN SIGNED MESSAGE-----[\s\S]+?-----END SIGNED MESSAGE-----/gm,
|
|
13
|
+
]
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Retrieves the tag pointed to by the oid
|
|
18
|
+
* @async
|
|
19
|
+
* @param {Repository} repo The repo that the tag lives in
|
|
20
|
+
* @param {String|Oid|Tag} id The tag to lookup
|
|
21
|
+
* @return {Tag}
|
|
22
|
+
*/
|
|
23
|
+
Tag.lookup = LookupWrapper(Tag);
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* @async
|
|
27
|
+
* @param {Repository} repo
|
|
28
|
+
* @param {String} tagName
|
|
29
|
+
* @param {Oid} target
|
|
30
|
+
* @param {Signature} tagger
|
|
31
|
+
* @return {String}
|
|
32
|
+
*/
|
|
33
|
+
Tag.createBuffer = function(repo, tagName, target, tagger, message) {
|
|
34
|
+
return NodeGit.Object.lookup(repo, target, NodeGit.Object.TYPE.ANY)
|
|
35
|
+
.then((object) => {
|
|
36
|
+
if (!NodeGit.Object.typeisloose(object.type())) {
|
|
37
|
+
throw new Error("Object must be a loose type");
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
const id = object.id().toString();
|
|
41
|
+
const objectType = NodeGit.Object.type2String(object.type());
|
|
42
|
+
const lines = [
|
|
43
|
+
`object ${id}`,
|
|
44
|
+
`type ${objectType}`,
|
|
45
|
+
`tag ${tagName}`,
|
|
46
|
+
`tagger ${tagger.toString(true)}\n`,
|
|
47
|
+
`${message}${message.endsWith("\n") ? "" : "\n"}`
|
|
48
|
+
];
|
|
49
|
+
return lines.join("\n");
|
|
50
|
+
});
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
const deprecatedCreateWithSignatureHelper = util.deprecate(function(repo, oidTarget) {
|
|
54
|
+
return repo.getCommit(oidTarget);
|
|
55
|
+
}, "Tag.createWithSignature target should be a Git Object, not Oid");
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* @async
|
|
59
|
+
* @param {Repository} repo
|
|
60
|
+
* @param {String} tagName
|
|
61
|
+
* @param {Object} target
|
|
62
|
+
* @param {Signature} tagger
|
|
63
|
+
* @param {String} message
|
|
64
|
+
* @param {Number} force
|
|
65
|
+
* @param {Function} signingCallback Takes a string and returns a string
|
|
66
|
+
* representing the signed message
|
|
67
|
+
* @return {Oid}
|
|
68
|
+
*/
|
|
69
|
+
Tag.createWithSignature = async (
|
|
70
|
+
repo,
|
|
71
|
+
tagName,
|
|
72
|
+
target,
|
|
73
|
+
tagger,
|
|
74
|
+
message,
|
|
75
|
+
force,
|
|
76
|
+
signingCallback
|
|
77
|
+
) => {
|
|
78
|
+
let targetOid;
|
|
79
|
+
if (!target.id) {
|
|
80
|
+
targetOid = await deprecatedCreateWithSignatureHelper(repo, target);
|
|
81
|
+
} else {
|
|
82
|
+
targetOid = target;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
const tagBuffer = await Tag.createBuffer(repo, tagName, targetOid.id(), tagger, message);
|
|
86
|
+
const { code, signedData } = await signingCallback(tagBuffer);
|
|
87
|
+
switch (code) {
|
|
88
|
+
case NodeGit.Error.CODE.OK: {
|
|
89
|
+
const normalizedEnding = signedData.endsWith("\n") ? "" : "\n";
|
|
90
|
+
const signedTagString = tagBuffer + signedData + normalizedEnding;
|
|
91
|
+
return Tag.createFromBuffer(repo, signedTagString, force);
|
|
92
|
+
}
|
|
93
|
+
case NodeGit.Error.CODE.PASSTHROUGH:
|
|
94
|
+
return Tag.create(
|
|
95
|
+
repo,
|
|
96
|
+
tagName,
|
|
97
|
+
targetOid,
|
|
98
|
+
tagger,
|
|
99
|
+
message,
|
|
100
|
+
force
|
|
101
|
+
);
|
|
102
|
+
default: {
|
|
103
|
+
const error = new Error(
|
|
104
|
+
`Tag.createWithSignature threw with error code ${code}`
|
|
105
|
+
);
|
|
106
|
+
error.errno = code;
|
|
107
|
+
throw error;
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
};
|
|
111
|
+
|
|
112
|
+
/**
|
|
113
|
+
* Retrieves the signature of an annotated tag
|
|
114
|
+
* @async
|
|
115
|
+
* @param {String} signatureType
|
|
116
|
+
* @return {String|null}
|
|
117
|
+
*/
|
|
118
|
+
Tag.prototype.extractSignature = function(signatureType = "gpgsig") {
|
|
119
|
+
const id = this.id();
|
|
120
|
+
const repo = this.repo;
|
|
121
|
+
const signatureRegexes = signatureRegexesBySignatureType[signatureType];
|
|
122
|
+
if (!signatureRegexes) {
|
|
123
|
+
throw new Error("Unsupported signature type");
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
return repo.odb().then((odb) => {
|
|
127
|
+
return odb.read(id);
|
|
128
|
+
}).then((odbObject) => {
|
|
129
|
+
const odbData = odbObject.toString();
|
|
130
|
+
|
|
131
|
+
for (const regex of signatureRegexes) {
|
|
132
|
+
const matchResult = odbData.match(regex);
|
|
133
|
+
|
|
134
|
+
if (matchResult !== null) {
|
|
135
|
+
return matchResult[0];
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
throw new Error("this tag is not signed");
|
|
140
|
+
});
|
|
141
|
+
};
|