isomorphic-git
Advanced tools
Comparing version 0.0.31 to 0.0.32
19
cli.js
@@ -10,23 +10,8 @@ #!/usr/bin/env node | ||
minimisted(async function ({ _: [command, ...args], ...opts }) { | ||
// Create the repo object | ||
const repo = new git.Git({ fs, dir: '.' }) | ||
// What's the command? | ||
let cmd = `git.${command}(repo, ${JSON.stringify(opts)})` | ||
// for (let key of Object.keys(opts)) { | ||
// // This is how you check for an array, right? | ||
// if (opts[key].length === undefined) { | ||
// repo[key](opts[key]) | ||
// cmd += `.${key}('${opts[key]}')` | ||
// } else { | ||
// repo[key](...opts[key]) | ||
// cmd += `.${key}(${opts[key].map(x => `'${x}'`).join(', ')})` | ||
// } | ||
// } | ||
// cmd += `.${command}(${args.map(x => `'${x}'`).join(', ')})` | ||
console.log(repo) | ||
let cmd = `git.${command}({fs, dir: '.', ${JSON.stringify(opts).slice(1)})` | ||
console.log(cmd) | ||
console.log(git) | ||
let result = await git[command](repo, opts) | ||
let result = await git[command](Object.assign({ fs, dir: '.' }, opts)) | ||
if (result === undefined) return | ||
console.log(JSON.stringify(result, null, 2)) | ||
}) |
@@ -12,2 +12,3 @@ 'use strict'; | ||
var _asyncToGenerator = _interopDefault(require('babel-runtime/helpers/asyncToGenerator')); | ||
var path = _interopDefault(require('path')); | ||
var buffer = require('buffer'); | ||
@@ -18,2 +19,3 @@ var stream = require('stream'); | ||
var crypto = _interopDefault(require('crypto')); | ||
var _objectWithoutProperties = _interopDefault(require('babel-runtime/helpers/objectWithoutProperties')); | ||
var models_js = require('./models.js'); | ||
@@ -33,4 +35,6 @@ var managers_js = require('./managers.js'); | ||
* Read and/or write to the git config file(s) | ||
* @param {GitRepo} repo - A {@link Git} object matching `{gitdir, fs}` | ||
* @param {Object} args - Arguments object | ||
* @param {FSModule} args.fs - The filesystem holding the git repo | ||
* @param {string} args.dir - The path to the [working tree](index.html#dir-vs-gitdir) directory | ||
* @param {string} [args.gitdir=path.join(dir, '.git')] - The path to the [git directory](index.html#dir-vs-gitdir) | ||
* @param {string} args.path - The key of the git config entry. | ||
@@ -44,6 +48,7 @@ * @param {string} [args.value] - A value to store at that path. | ||
* @example | ||
* let repo = new Git({fs, dir: '.'}) | ||
* let repo = {fs, dir: '.'} | ||
* | ||
* // Write config value | ||
* await config(repo, { | ||
* await config({ | ||
* ...repo, | ||
* path: 'user.name', | ||
@@ -54,3 +59,4 @@ * value: 'Mr. Test' | ||
* // Read config value | ||
* let value = await config(repo, { | ||
* let value = await config({ | ||
* ...repo, | ||
* path: 'user.name' | ||
@@ -60,7 +66,10 @@ * }) | ||
var config = function () { | ||
var _ref2 = _asyncToGenerator(_regeneratorRuntime.mark(function _callee(_ref, args) { | ||
var gitdir = _ref.gitdir, | ||
_fs = _ref.fs; | ||
var _ref2 = _asyncToGenerator(_regeneratorRuntime.mark(function _callee(_ref) { | ||
var dir = _ref.dir, | ||
_ref$gitdir = _ref.gitdir, | ||
gitdir = _ref$gitdir === undefined ? path.join(dir, '.git') : _ref$gitdir, | ||
_fs = _ref.fs, | ||
args = _objectWithoutProperties(_ref, ['dir', 'gitdir', 'fs']); | ||
var fs, path, value, config, _value; | ||
var fs, path$$1, value, config, _value; | ||
@@ -72,3 +81,3 @@ return _regeneratorRuntime.wrap(function _callee$(_context) { | ||
fs = new models_js.FileSystem(_fs); | ||
path = args.path, value = args.value; | ||
path$$1 = args.path, value = args.value; | ||
_context.next = 4; | ||
@@ -86,3 +95,3 @@ return managers_js.GitConfigManager.get({ fs: fs, gitdir: gitdir }); | ||
_context.next = 8; | ||
return config.get(path); | ||
return config.get(path$$1); | ||
@@ -95,3 +104,3 @@ case 8: | ||
_context.next = 14; | ||
return config.set(path, value); | ||
return config.set(path$$1, value); | ||
@@ -110,3 +119,3 @@ case 14: | ||
return function config(_x, _x2) { | ||
return function config(_x) { | ||
return _ref2.apply(this, arguments); | ||
@@ -125,15 +134,17 @@ }; | ||
* | ||
* @param {GitRepo} repo - A {@link Git} object matching `{gitdir, fs}` | ||
* @param {Object} args - Arguments object | ||
* @param {integer} [args.depth=0] - Determines how much of the git repository's history to retrieve. If not specified it defaults to 0 which means the entire repo history. | ||
* @param {string} [args.ref=undefined] - Which branch to push. By default this is the currently checked out branch of the repository. | ||
* @param {string} [args.authUsername=undefined] - The username to use with Basic Auth | ||
* @param {string} [args.authPassword=undefined] - The password to use with Basic Auth | ||
* @param {string} [args.url=undefined] - The URL of the remote git server. The default is the value set in the git config for that remote. | ||
* @param {FSModule} args.fs - The filesystem holding the git repo | ||
* @param {string} args.dir - The path to the [working tree](index.html#dir-vs-gitdir) directory | ||
* @param {string} [args.gitdir=path.join(dir, '.git')] - The path to the [git directory](index.html#dir-vs-gitdir) | ||
* @param {string} [args.ref] - Which branch to push. By default this is the currently checked out branch of the repository. | ||
* @param {string} [args.remote='origin'] - If URL is not specified, determines which remote to use. | ||
* @param {string} [args.url] - The URL of the remote git server. The default is the value set in the git config for that remote. | ||
* @param {string} [args.authUsername] - The username to use with Basic Auth | ||
* @param {string} [args.authPassword] - The password to use with Basic Auth | ||
* @returns {Promise<void>} - Resolves successfully when push completes | ||
* | ||
* @example | ||
* let repo = new Git({fs, dir: '.'}) | ||
* await push(repo, { | ||
* let repo = {fs, dir: '.'} | ||
* await push({ | ||
* ...repo, | ||
* remote: 'origin', | ||
@@ -146,10 +157,13 @@ * ref: 'master', | ||
};var push = function () { | ||
var _ref3 = _asyncToGenerator(_regeneratorRuntime.mark(function _callee(_ref, _ref2) { | ||
var gitdir = _ref.gitdir, | ||
_fs = _ref.fs; | ||
var ref = _ref2.ref, | ||
remote = _ref2.remote, | ||
url = _ref2.url, | ||
authUsername = _ref2.authUsername, | ||
authPassword = _ref2.authPassword; | ||
var _ref2 = _asyncToGenerator(_regeneratorRuntime.mark(function _callee(_ref) { | ||
var _fs = _ref.fs, | ||
dir = _ref.dir, | ||
_ref$gitdir = _ref.gitdir, | ||
gitdir = _ref$gitdir === undefined ? path.join(dir, '.git') : _ref$gitdir, | ||
ref = _ref.ref, | ||
_ref$remote = _ref.remote, | ||
remote = _ref$remote === undefined ? 'origin' : _ref$remote, | ||
url = _ref.url, | ||
authUsername = _ref.authUsername, | ||
authPassword = _ref.authPassword; | ||
var fs, fullRef, oid, httpRemote, commits, objects, packstream, oldoid, response; | ||
@@ -163,21 +177,19 @@ return _regeneratorRuntime.wrap(function _callee$(_context) { | ||
remote = remote || 'origin'; | ||
if (!(url === undefined)) { | ||
_context.next = 6; | ||
_context.next = 5; | ||
break; | ||
} | ||
_context.next = 5; | ||
return config({ fs: fs, gitdir: gitdir }, { path: 'remote.' + remote + '.url' }); | ||
_context.next = 4; | ||
return config({ fs: fs, gitdir: gitdir, path: 'remote.' + remote + '.url' }); | ||
case 5: | ||
case 4: | ||
url = _context.sent; | ||
case 6: | ||
case 5: | ||
fullRef = ref.startsWith('refs/') ? ref : 'refs/heads/' + ref; | ||
_context.next = 9; | ||
_context.next = 8; | ||
return managers_js.GitRefManager.resolve({ fs: fs, gitdir: gitdir, ref: ref }); | ||
case 9: | ||
case 8: | ||
oid = _context.sent; | ||
@@ -192,8 +204,10 @@ httpRemote = new managers_js.GitRemoteHTTP(url); | ||
} | ||
_context.next = 14; | ||
_context.next = 13; | ||
return httpRemote.preparePush(); | ||
case 14: | ||
_context.next = 16; | ||
return listCommits({ fs: fs, gitdir: gitdir }, { | ||
case 13: | ||
_context.next = 15; | ||
return listCommits({ | ||
fs: fs, | ||
gitdir: gitdir, | ||
start: [oid], | ||
@@ -203,8 +217,8 @@ finish: httpRemote.refs.values() | ||
case 16: | ||
case 15: | ||
commits = _context.sent; | ||
_context.next = 19; | ||
return listObjects({ fs: fs, gitdir: gitdir }, { oids: commits }); | ||
_context.next = 18; | ||
return listObjects({ fs: fs, gitdir: gitdir, oids: commits }); | ||
case 19: | ||
case 18: | ||
objects = _context.sent; | ||
@@ -216,14 +230,16 @@ packstream = new stream.PassThrough(); | ||
packstream.write(models_js.GitPktLine.flush()); | ||
pack({ fs: fs, gitdir: gitdir }, { | ||
pack({ | ||
fs: fs, | ||
gitdir: gitdir, | ||
oids: [].concat(_toConsumableArray(objects)), | ||
outputStream: packstream | ||
}); | ||
_context.next = 27; | ||
_context.next = 26; | ||
return httpRemote.push(packstream); | ||
case 27: | ||
case 26: | ||
response = _context.sent; | ||
return _context.abrupt('return', response); | ||
case 29: | ||
case 28: | ||
case 'end': | ||
@@ -236,4 +252,4 @@ return _context.stop(); | ||
return function push(_x, _x2) { | ||
return _ref3.apply(this, arguments); | ||
return function push(_x) { | ||
return _ref2.apply(this, arguments); | ||
}; | ||
@@ -246,5 +262,3 @@ }(); | ||
var listCommits = function () { | ||
var _ref6 = _asyncToGenerator(_regeneratorRuntime.mark(function _callee3(_ref4, _ref5) { | ||
var gitdir = _ref4.gitdir, | ||
_fs = _ref4.fs; | ||
var _ref4 = _asyncToGenerator(_regeneratorRuntime.mark(function _callee3(_ref3) { | ||
@@ -255,4 +269,4 @@ // Because git commits are named by their hash, there is no | ||
var walk = function () { | ||
var _ref8 = _asyncToGenerator(_regeneratorRuntime.mark(function _callee2(oid) { | ||
var _ref9, type, object, commit, parents, _iteratorNormalCompletion3, _didIteratorError3, _iteratorError3, _iterator3, _step3; | ||
var _ref6 = _asyncToGenerator(_regeneratorRuntime.mark(function _callee2(oid) { | ||
var _ref7, type, object, commit, parents, _iteratorNormalCompletion3, _didIteratorError3, _iteratorError3, _iterator3, _step3; | ||
@@ -268,5 +282,5 @@ return _regeneratorRuntime.wrap(function _callee2$(_context2) { | ||
case 3: | ||
_ref9 = _context2.sent; | ||
type = _ref9.type; | ||
object = _ref9.object; | ||
_ref7 = _context2.sent; | ||
type = _ref7.type; | ||
object = _ref7.object; | ||
@@ -352,4 +366,4 @@ if (!(type !== 'commit')) { | ||
return function walk(_x5) { | ||
return _ref8.apply(this, arguments); | ||
return function walk(_x3) { | ||
return _ref6.apply(this, arguments); | ||
}; | ||
@@ -361,6 +375,10 @@ }(); | ||
var start = _ref5.start, | ||
finish = _ref5.finish; | ||
var dir = _ref3.dir, | ||
_ref3$gitdir = _ref3.gitdir, | ||
gitdir = _ref3$gitdir === undefined ? path.join(dir, '.git') : _ref3$gitdir, | ||
_fs = _ref3.fs, | ||
start = _ref3.start, | ||
finish = _ref3.finish; | ||
var fs, startingSet, finishingSet, _iteratorNormalCompletion, _didIteratorError, _iteratorError, _iterator, _step, ref, _iteratorNormalCompletion2, _didIteratorError2, _iteratorError2, _iterator2, _step2, _ref7, _oid, visited, _iteratorNormalCompletion4, _didIteratorError4, _iteratorError4, _iterator4, _step4, oid; | ||
var fs, startingSet, finishingSet, _iteratorNormalCompletion, _didIteratorError, _iteratorError, _iterator, _step, ref, _iteratorNormalCompletion2, _didIteratorError2, _iteratorError2, _iterator2, _step2, _ref5, _oid, visited, _iteratorNormalCompletion4, _didIteratorError4, _iteratorError4, _iterator4, _step4, oid; | ||
@@ -448,6 +466,6 @@ return _regeneratorRuntime.wrap(function _callee3$(_context3) { | ||
_ref7 = _step2.value; | ||
_ref5 = _step2.value; | ||
_context3.prev = 39; | ||
_context3.next = 42; | ||
return managers_js.GitRefManager.resolve({ fs: fs, gitdir: gitdir, ref: _ref7 }); | ||
return managers_js.GitRefManager.resolve({ fs: fs, gitdir: gitdir, ref: _ref5 }); | ||
@@ -572,4 +590,4 @@ case 42: | ||
return function listCommits(_x3, _x4) { | ||
return _ref6.apply(this, arguments); | ||
return function listCommits(_x2) { | ||
return _ref4.apply(this, arguments); | ||
}; | ||
@@ -582,6 +600,3 @@ }(); | ||
var listObjects = function () { | ||
var _ref12 = _asyncToGenerator(_regeneratorRuntime.mark(function _callee5(_ref10, _ref11 /*: { oids: Set<string> } */ | ||
) { | ||
var gitdir = _ref10.gitdir, | ||
_fs = _ref10.fs; | ||
var _ref9 = _asyncToGenerator(_regeneratorRuntime.mark(function _callee5(_ref8) { | ||
@@ -592,4 +607,4 @@ // We don't do the purest simplest recursion, because we can | ||
var walk = function () { | ||
var _ref13 = _asyncToGenerator(_regeneratorRuntime.mark(function _callee4(oid) { | ||
var _ref14, type, object, commit, tree, _tree, _iteratorNormalCompletion5, _didIteratorError5, _iteratorError5, _iterator5, _step5, entry; | ||
var _ref10 = _asyncToGenerator(_regeneratorRuntime.mark(function _callee4(oid) { | ||
var _ref11, type, object, commit, tree, _tree, _iteratorNormalCompletion5, _didIteratorError5, _iteratorError5, _iterator5, _step5, entry; | ||
@@ -605,5 +620,5 @@ return _regeneratorRuntime.wrap(function _callee4$(_context4) { | ||
case 3: | ||
_ref14 = _context4.sent; | ||
type = _ref14.type; | ||
object = _ref14.object; | ||
_ref11 = _context4.sent; | ||
type = _ref11.type; | ||
object = _ref11.object; | ||
@@ -703,4 +718,4 @@ if (!(type === 'commit')) { | ||
return function walk(_x8) { | ||
return _ref13.apply(this, arguments); | ||
return function walk(_x5) { | ||
return _ref10.apply(this, arguments); | ||
}; | ||
@@ -712,3 +727,7 @@ }(); | ||
var oids = _ref11.oids; | ||
var dir = _ref8.dir, | ||
_ref8$gitdir = _ref8.gitdir, | ||
gitdir = _ref8$gitdir === undefined ? path.join(dir, '.git') : _ref8$gitdir, | ||
_fs = _ref8.fs, | ||
oids = _ref8.oids; | ||
@@ -789,4 +808,4 @@ var fs, visited, _iteratorNormalCompletion6, _didIteratorError6, _iteratorError6, _iterator6, _step6, oid; | ||
return function listObjects(_x6, _x7) { | ||
return _ref12.apply(this, arguments); | ||
return function listObjects(_x4) { | ||
return _ref9.apply(this, arguments); | ||
}; | ||
@@ -799,9 +818,11 @@ }(); | ||
var pack = function () { | ||
var _ref17 = _asyncToGenerator(_regeneratorRuntime.mark(function _callee6(_ref15, _ref16) { | ||
var gitdir = _ref15.gitdir, | ||
_fs = _ref15.fs; | ||
var oids = _ref16.oids, | ||
outputStream = _ref16.outputStream; | ||
var _ref13 = _asyncToGenerator(_regeneratorRuntime.mark(function _callee6(_ref12) { | ||
var dir = _ref12.dir, | ||
_ref12$gitdir = _ref12.gitdir, | ||
gitdir = _ref12$gitdir === undefined ? path.join(dir, '.git') : _ref12$gitdir, | ||
_fs = _ref12.fs, | ||
oids = _ref12.oids, | ||
outputStream = _ref12.outputStream; | ||
var fs, hash, write, writeObject, _iteratorNormalCompletion7, _didIteratorError7, _iteratorError7, _iterator7, _step7, oid, _ref19, type, object, digest; | ||
var fs, hash, write, writeObject, _iteratorNormalCompletion7, _didIteratorError7, _iteratorError7, _iterator7, _step7, oid, _ref15, type, object, digest; | ||
@@ -812,5 +833,5 @@ return _regeneratorRuntime.wrap(function _callee6$(_context6) { | ||
case 0: | ||
writeObject = function writeObject(_ref18) { | ||
var stype = _ref18.stype, | ||
object = _ref18.object; | ||
writeObject = function writeObject(_ref14) { | ||
var stype = _ref14.stype, | ||
object = _ref14.object; | ||
@@ -877,5 +898,5 @@ var lastFour = void 0, | ||
case 16: | ||
_ref19 = _context6.sent; | ||
type = _ref19.type; | ||
object = _ref19.object; | ||
_ref15 = _context6.sent; | ||
type = _ref15.type; | ||
object = _ref15.object; | ||
@@ -938,4 +959,4 @@ writeObject({ write: write, object: object, stype: type }); | ||
return function pack(_x9, _x10) { | ||
return _ref17.apply(this, arguments); | ||
return function pack(_x6) { | ||
return _ref13.apply(this, arguments); | ||
}; | ||
@@ -945,20 +966,20 @@ }(); | ||
var fetchPackfile = function () { | ||
var _ref6 = _asyncToGenerator(_regeneratorRuntime.mark(function _callee3(_ref4, _ref5) { | ||
var _ref4 = _asyncToGenerator(_regeneratorRuntime.mark(function _callee3(_ref3) { | ||
var _this = this; | ||
var gitdir = _ref4.gitdir, | ||
_fs = _ref4.fs; | ||
var ref = _ref5.ref, | ||
remote = _ref5.remote, | ||
url = _ref5.url, | ||
authUsername = _ref5.authUsername, | ||
authPassword = _ref5.authPassword, | ||
_ref5$depth = _ref5.depth, | ||
depth = _ref5$depth === undefined ? null : _ref5$depth, | ||
_ref5$since = _ref5.since, | ||
since = _ref5$since === undefined ? null : _ref5$since, | ||
_ref5$exclude = _ref5.exclude, | ||
exclude = _ref5$exclude === undefined ? [] : _ref5$exclude, | ||
_ref5$relative = _ref5.relative, | ||
relative = _ref5$relative === undefined ? false : _ref5$relative; | ||
var gitdir = _ref3.gitdir, | ||
_fs = _ref3.fs, | ||
ref = _ref3.ref, | ||
remote = _ref3.remote, | ||
url = _ref3.url, | ||
authUsername = _ref3.authUsername, | ||
authPassword = _ref3.authPassword, | ||
_ref3$depth = _ref3.depth, | ||
depth = _ref3$depth === undefined ? null : _ref3$depth, | ||
_ref3$since = _ref3.since, | ||
since = _ref3$since === undefined ? null : _ref3$since, | ||
_ref3$exclude = _ref3.exclude, | ||
exclude = _ref3$exclude === undefined ? [] : _ref3$exclude, | ||
_ref3$relative = _ref3.relative, | ||
relative = _ref3$relative === undefined ? false : _ref3$relative; | ||
@@ -997,3 +1018,5 @@ var fs, remoteHTTP, want, capabilities, packstream, oids, _iteratorNormalCompletion, _didIteratorError, _iteratorError, _iterator, _step, oid, _iteratorNormalCompletion2, _didIteratorError2, _iteratorError2, _iterator2, _step2, x, have, response; | ||
_context3.next = 9; | ||
return config({ fs: fs, gitdir: gitdir }, { | ||
return config({ | ||
fs: fs, | ||
gitdir: gitdir, | ||
path: 'remote.' + remote + '.url' | ||
@@ -1208,3 +1231,3 @@ }); | ||
response.packetlines.pipe(through2(function () { | ||
var _ref7 = _asyncToGenerator(_regeneratorRuntime.mark(function _callee2(data, enc, next) { | ||
var _ref5 = _asyncToGenerator(_regeneratorRuntime.mark(function _callee2(data, enc, next) { | ||
var line, _oid, _oid2; | ||
@@ -1272,4 +1295,4 @@ | ||
return function (_x5, _x6, _x7) { | ||
return _ref7.apply(this, arguments); | ||
return function (_x3, _x4, _x5) { | ||
return _ref5.apply(this, arguments); | ||
}; | ||
@@ -1287,4 +1310,4 @@ }())); | ||
return function fetchPackfile(_x3, _x4) { | ||
return _ref6.apply(this, arguments); | ||
return function fetchPackfile(_x2) { | ||
return _ref4.apply(this, arguments); | ||
}; | ||
@@ -1296,4 +1319,6 @@ }(); | ||
* | ||
* @param {GitRepo} repo - A {@link Git} object matching `{workdir, gitdir, fs}` | ||
* @param {Object} args - Arguments object | ||
* @param {FSModule} args.fs - The filesystem holding the git repo | ||
* @param {string} args.dir - The path to the [working tree](index.html#dir-vs-gitdir) directory | ||
* @param {string} [args.gitdir=path.join(dir, '.git')] - The path to the [git directory](index.html#dir-vs-gitdir) | ||
* @param {string} [args.url=undefined] - The URL of the remote git server. The default is the value set in the git config for that remote. | ||
@@ -1312,4 +1337,5 @@ * @param {string} [args.remote='origin'] - If `url` is not specified, determines which remote to use. | ||
* @example | ||
* let repo = new Git({fs, dir: '.'}) | ||
* await fetch(repo, { | ||
* let repo = {fs, dir: '.'} | ||
* await fetch({ | ||
* ...repo, | ||
* url: 'https://cors-buster-jfpactjnem.now.sh/github.com/wmhilton/isomorphic-git', | ||
@@ -1320,16 +1346,18 @@ * depth: 1 | ||
var fetch = function () { | ||
var _ref3 = _asyncToGenerator(_regeneratorRuntime.mark(function _callee(_ref, _ref2) { | ||
var gitdir = _ref.gitdir, | ||
fs = _ref.fs; | ||
var _ref2$ref = _ref2.ref, | ||
ref = _ref2$ref === undefined ? 'HEAD' : _ref2$ref, | ||
remote = _ref2.remote, | ||
url = _ref2.url, | ||
authUsername = _ref2.authUsername, | ||
authPassword = _ref2.authPassword, | ||
depth = _ref2.depth, | ||
since = _ref2.since, | ||
exclude = _ref2.exclude, | ||
relative = _ref2.relative, | ||
onprogress = _ref2.onprogress; | ||
var _ref2 = _asyncToGenerator(_regeneratorRuntime.mark(function _callee(_ref) { | ||
var dir = _ref.dir, | ||
_ref$gitdir = _ref.gitdir, | ||
gitdir = _ref$gitdir === undefined ? path.join(dir, '.git') : _ref$gitdir, | ||
fs = _ref.fs, | ||
_ref$ref = _ref.ref, | ||
ref = _ref$ref === undefined ? 'HEAD' : _ref$ref, | ||
remote = _ref.remote, | ||
url = _ref.url, | ||
authUsername = _ref.authUsername, | ||
authPassword = _ref.authPassword, | ||
depth = _ref.depth, | ||
since = _ref.since, | ||
exclude = _ref.exclude, | ||
relative = _ref.relative, | ||
onprogress = _ref.onprogress; | ||
var response; | ||
@@ -1343,4 +1371,3 @@ return _regeneratorRuntime.wrap(function _callee$(_context) { | ||
gitdir: gitdir, | ||
fs: fs | ||
}, { | ||
fs: fs, | ||
ref: ref, | ||
@@ -1360,3 +1387,3 @@ remote: remote, | ||
_context.next = 5; | ||
return unpack({ fs: fs, gitdir: gitdir }, { inputStream: response.packfile, onprogress: onprogress }); | ||
return unpack({ fs: fs, gitdir: gitdir, inputStream: response.packfile, onprogress: onprogress }); | ||
@@ -1371,4 +1398,4 @@ case 5: | ||
return function fetch(_x, _x2) { | ||
return _ref3.apply(this, arguments); | ||
return function fetch(_x) { | ||
return _ref2.apply(this, arguments); | ||
}; | ||
@@ -1400,4 +1427,6 @@ }(); | ||
* @ignore | ||
* @param {GitRepo} repo - A {@link Git} object matching `{gitdir, fs}` | ||
* @param {Object} args - Arguments object | ||
* @param {FSModule} args.fs - The filesystem holding the git repo | ||
* @param {string} args.dir - The path to the [working tree](index.html#dir-vs-gitdir) directory | ||
* @param {string} [args.gitdir=path.join(dir, '.git')] - The path to the [git directory](index.html#dir-vs-gitdir) | ||
* @param {ReadableStream} args.inputStream | ||
@@ -1407,7 +1436,9 @@ * @param {Function} args.onprogress | ||
var unpack = function () { | ||
var _ref10 = _asyncToGenerator(_regeneratorRuntime.mark(function _callee5(_ref8, _ref9) { | ||
var gitdir = _ref8.gitdir, | ||
_fs = _ref8.fs; | ||
var inputStream = _ref9.inputStream, | ||
onprogress = _ref9.onprogress; | ||
var _ref7 = _asyncToGenerator(_regeneratorRuntime.mark(function _callee5(_ref6) { | ||
var dir = _ref6.dir, | ||
_ref6$gitdir = _ref6.gitdir, | ||
gitdir = _ref6$gitdir === undefined ? path.join(dir, '.git') : _ref6$gitdir, | ||
_fs = _ref6.fs, | ||
inputStream = _ref6.inputStream, | ||
onprogress = _ref6.onprogress; | ||
var fs; | ||
@@ -1446,10 +1477,10 @@ return _regeneratorRuntime.wrap(function _callee5$(_context5) { | ||
inputStream.pipe(listpack()).pipe(through2.obj(function () { | ||
var _ref12 = _asyncToGenerator(_regeneratorRuntime.mark(function _callee4(_ref11, enc, next) { | ||
var data = _ref11.data, | ||
type = _ref11.type, | ||
reference = _ref11.reference, | ||
offset = _ref11.offset, | ||
num = _ref11.num; | ||
var _ref9 = _asyncToGenerator(_regeneratorRuntime.mark(function _callee4(_ref8, enc, next) { | ||
var data = _ref8.data, | ||
type = _ref8.type, | ||
reference = _ref8.reference, | ||
offset = _ref8.offset, | ||
num = _ref8.num; | ||
var oid, _ref13, object, _type, result, newoid, absoluteOffset, referenceOid, _ref14, _type2, _object, _result, _oid3, _oid4, perfentry; | ||
var oid, _ref10, object, _type, result, newoid, absoluteOffset, referenceOid, _ref11, _type2, _object, _result, _oid3, _oid4, perfentry; | ||
@@ -1480,5 +1511,5 @@ return _regeneratorRuntime.wrap(function _callee4$(_context4) { | ||
case 8: | ||
_ref13 = _context4.sent; | ||
object = _ref13.object; | ||
_type = _ref13.type; | ||
_ref10 = _context4.sent; | ||
object = _ref10.object; | ||
_type = _ref10.type; | ||
@@ -1540,5 +1571,5 @@ totalReadFileTime += marky.stop('readFile').duration; | ||
case 33: | ||
_ref14 = _context4.sent; | ||
_type2 = _ref14.type; | ||
_object = _ref14.object; | ||
_ref11 = _context4.sent; | ||
_type2 = _ref11.type; | ||
_object = _ref11.object; | ||
_result = applyDelta(data, _object); | ||
@@ -1612,4 +1643,4 @@ _context4.next = 39; | ||
return function (_x10, _x11, _x12) { | ||
return _ref12.apply(this, arguments); | ||
return function (_x7, _x8, _x9) { | ||
return _ref9.apply(this, arguments); | ||
}; | ||
@@ -1628,4 +1659,4 @@ }())).on('error', reject).on('finish', resolve); | ||
return function unpack(_x8, _x9) { | ||
return _ref10.apply(this, arguments); | ||
return function unpack(_x6) { | ||
return _ref7.apply(this, arguments); | ||
}; | ||
@@ -1632,0 +1663,0 @@ }(); |
@@ -28,2 +28,3 @@ 'use strict'; | ||
// @flow | ||
/** @ignore */ | ||
var GitConfigManager = function () { | ||
@@ -112,2 +113,4 @@ function GitConfigManager() { | ||
// TODO: Add file locks. | ||
/** @ignore */ | ||
var GitShallowManager = function () { | ||
@@ -255,2 +258,3 @@ function GitShallowManager() { | ||
/** @ignore */ | ||
var GitIndexManager = function () { | ||
@@ -360,2 +364,3 @@ function GitIndexManager() { | ||
/** @ignore */ | ||
var GitIgnoreManager = function () { | ||
@@ -371,7 +376,8 @@ function GitIgnoreManager() { | ||
var _fs = _ref.fs, | ||
gitdir = _ref.gitdir, | ||
workdir = _ref.workdir, | ||
dir = _ref.dir, | ||
_ref$gitdir = _ref.gitdir, | ||
gitdir = _ref$gitdir === undefined ? path.join(dir, '.git') : _ref$gitdir, | ||
filepath = _ref.filepath; | ||
var fs, pairs, pieces, i, dir, file, ignoredStatus, _iteratorNormalCompletion, _didIteratorError, _iteratorError, _iterator, _step, p, _file, ign, unign, parentdir; | ||
var fs, pairs, pieces, i, folder, file, ignoredStatus, _iteratorNormalCompletion, _didIteratorError, _iteratorError, _iterator, _step, p, _file, ign, unign, parentdir; | ||
@@ -384,3 +390,3 @@ return _regeneratorRuntime.wrap(function _callee$(_context) { | ||
pairs = [{ | ||
gitignore: path.join(workdir, '.gitignore'), | ||
gitignore: path.join(dir, '.gitignore'), | ||
filepath: filepath | ||
@@ -391,7 +397,7 @@ }]; | ||
for (i = 1; i < pieces.length; i++) { | ||
dir = pieces.slice(0, i).join('/'); | ||
folder = pieces.slice(0, i).join('/'); | ||
file = pieces.slice(i).join('/'); | ||
pairs.push({ | ||
gitignore: path.join(workdir, dir, '.gitignore'), | ||
gitignore: path.join(dir, folder, '.gitignore'), | ||
filepath: file | ||
@@ -520,2 +526,3 @@ }); | ||
/** @ignore */ | ||
var GitObjectManager = function () { | ||
@@ -673,2 +680,3 @@ function GitObjectManager() { | ||
// This is a convenience wrapper for reading and writing files in the 'refs' directory. | ||
/** @ignore */ | ||
var GitRefManager = function () { | ||
@@ -1133,2 +1141,4 @@ function GitRefManager() { | ||
/** @ignore */ | ||
var GitRemoteHTTP = function () { | ||
@@ -1135,0 +1145,0 @@ /*:: |
@@ -30,2 +30,3 @@ 'use strict'; | ||
var _set = _interopDefault(require('lodash/set')); | ||
var unset = _interopDefault(require('lodash/unset')); | ||
var pako = _interopDefault(require('pako')); | ||
@@ -44,2 +45,3 @@ var shasum = _interopDefault(require('shasum')); | ||
/** | ||
* @ignore | ||
* This is just a collection of helper functions really. At least that's how it started. | ||
@@ -590,2 +592,3 @@ */ | ||
/** @ignore */ | ||
var GitCommit = function () { | ||
@@ -826,2 +829,3 @@ /*:: | ||
/** @ignore */ | ||
var SignedGitCommit = function (_GitCommit) { | ||
@@ -970,2 +974,3 @@ _inherits(SignedGitCommit, _GitCommit); | ||
// have subsections, [include] directives, etc. | ||
/** @ignore */ | ||
var GitConfig = function () { | ||
@@ -1042,3 +1047,7 @@ function GitConfig(text) { | ||
case 0: | ||
return _context2.abrupt('return', _set(this.ini, path$$1, value)); | ||
if (value === undefined) { | ||
unset(this.ini, path$$1); | ||
} else { | ||
_set(this.ini, path$$1, value); | ||
} | ||
@@ -1130,2 +1139,3 @@ case 1: | ||
/** @ignore */ | ||
var GitObject = function () { | ||
@@ -1235,2 +1245,4 @@ function GitObject() { | ||
// There's not a lot of "state" in a pkt-line | ||
/** @ignore */ | ||
var GitPktLine = function () { | ||
@@ -1385,2 +1397,3 @@ function GitPktLine() { | ||
/** @ignore */ | ||
var GitPackfile = function () { | ||
@@ -1596,2 +1609,3 @@ function GitPackfile(_ref) { | ||
/** @ignore */ | ||
var GitIndex = function () { | ||
@@ -1863,2 +1877,3 @@ /*:: | ||
/** @ignore */ | ||
var GitTree = function () { | ||
@@ -1865,0 +1880,0 @@ /*:: |
@@ -26,2 +26,3 @@ 'use strict'; | ||
/** @ignore */ | ||
function flatFileListToDirectoryStructure(files /*: Array<{path: string}> */ | ||
@@ -94,2 +95,3 @@ ) /*: Node|void */{ | ||
/** @ignore */ | ||
var sleep = function () { | ||
@@ -199,7 +201,4 @@ var _ref = _asyncToGenerator(_regeneratorRuntime.mark(function _callee(ms) { | ||
/** | ||
* @param {string} company | ||
* @param {string} token | ||
* @returns {username, password} | ||
* | ||
* Use with {@link #gitpush .push} and {@link #gitpull .pull} to set Basic Authentication headers. | ||
* Use with {@link push} and {@link fetch} to set Basic Authentication headers. | ||
* This for is for *actual* OAuth2 tokens (not "personal access tokens"). | ||
@@ -214,2 +213,7 @@ * Unfortunately, all the major git hosting companies have chosen different conventions! | ||
* I will gladly accept pull requests for more companies' conventions. | ||
* | ||
* @param {string} company | ||
* @param {string} token | ||
* @returns {username, password} | ||
* | ||
*/ | ||
@@ -240,3 +244,3 @@ function oauth2(company, token) { | ||
* | ||
* Use with {@link #gitpush .push} and {@link #gitpull .pull} to set Basic Authentication headers. | ||
* Use with {@link push} and {@link fetch} to set Basic Authentication headers. | ||
* This works for basic username / password auth, or the newer username / token auth | ||
@@ -243,0 +247,0 @@ * that is often required if 2FA is enabled. |
@@ -18,6 +18,12 @@ import path from 'path'; | ||
/** | ||
* @external {FSModule} http://ghub.io/browserfs | ||
*/ | ||
/** | ||
* Add a file to the git index (aka staging area) | ||
* | ||
* @param {GitRepo} repo - A {@link Git} object matching `{workdir, gitdir, fs}` | ||
* @param {Object} args - Arguments object | ||
* @param {FSModule} args.fs - The filesystem holding the git repo | ||
* @param {string} args.dir - The path to the [working tree](index.html#dir-vs-gitdir) directory | ||
* @param {string} [args.gitdir=path.join(dir, '.git')] - The path to the [git directory](index.html#dir-vs-gitdir) | ||
* @param {string} args.filepath - The path to the file to add to the index. | ||
@@ -27,13 +33,18 @@ * @returns {Promise<void>} - Resolves successfully once the git index has been updated. | ||
* @example | ||
* let repo = new Git({fs, dir: '.'}) | ||
* await add(repo, {filepath: 'README.md'}) | ||
* let repo = {fs, dir: '.'} | ||
* await add({...repo, filepath: 'README.md'}) | ||
*/ | ||
async function add({ gitdir, workdir, fs: _fs }, { filepath }) { | ||
async function add({ | ||
dir, | ||
gitdir = path.join(dir, '.git'), | ||
fs: _fs, | ||
filepath | ||
}) { | ||
const fs = new FileSystem(_fs); | ||
const type = 'blob'; | ||
const object = await fs.read(path.join(workdir, filepath)); | ||
const object = await fs.read(path.join(dir, filepath)); | ||
if (object === null) throw new Error(`Could not read file '${filepath}'`); | ||
const oid = await GitObjectManager.write({ fs, gitdir, type, object }); | ||
await GitIndexManager.acquire({ fs, filepath: `${gitdir}/index` }, async function (index) { | ||
let stats = await fs._lstat(path.join(workdir, filepath)); | ||
let stats = await fs._lstat(path.join(dir, filepath)); | ||
index.insert({ filepath, stats, oid }); | ||
@@ -47,10 +58,13 @@ }); | ||
* | ||
* @param {GitRepo} repo - A {@link Git} object matching `{gitdir, fs}` | ||
* @param {Object} args - Arguments object | ||
* @param {FSModule} args.fs - The filesystem holding the git repo | ||
* @param {string} args.dir - The path to the [working tree](index.html#dir-vs-gitdir) directory | ||
* @param {string} [args.gitdir=path.join(dir, '.git')] - The path to the [git directory](index.html#dir-vs-gitdir) | ||
* @returns {Promise<void>} - Resolves successfully when filesystem operations are complete. | ||
* | ||
* @example | ||
* let repo = new Git({fs, dir: '.'}) | ||
* let repo = {fs, dir: '.'} | ||
* await init(repo) | ||
*/ | ||
async function init({ gitdir, fs: _fs }) { | ||
async function init({ dir, gitdir = path.join(dir, '.git'), fs: _fs }) { | ||
const fs = new FileSystem(_fs); | ||
@@ -66,6 +80,10 @@ let folders = ['hooks', 'info', 'objects/info', 'objects/pack', 'refs/heads', 'refs/tags']; | ||
function _objectWithoutProperties(obj, keys) { var target = {}; for (var i in obj) { if (keys.indexOf(i) >= 0) continue; if (!Object.prototype.hasOwnProperty.call(obj, i)) continue; target[i] = obj[i]; } return target; } | ||
/** | ||
* Read and/or write to the git config file(s) | ||
* @param {GitRepo} repo - A {@link Git} object matching `{gitdir, fs}` | ||
* @param {Object} args - Arguments object | ||
* @param {FSModule} args.fs - The filesystem holding the git repo | ||
* @param {string} args.dir - The path to the [working tree](index.html#dir-vs-gitdir) directory | ||
* @param {string} [args.gitdir=path.join(dir, '.git')] - The path to the [git directory](index.html#dir-vs-gitdir) | ||
* @param {string} args.path - The key of the git config entry. | ||
@@ -79,6 +97,7 @@ * @param {string} [args.value] - A value to store at that path. | ||
* @example | ||
* let repo = new Git({fs, dir: '.'}) | ||
* let repo = {fs, dir: '.'} | ||
* | ||
* // Write config value | ||
* await config(repo, { | ||
* await config({ | ||
* ...repo, | ||
* path: 'user.name', | ||
@@ -89,7 +108,15 @@ * value: 'Mr. Test' | ||
* // Read config value | ||
* let value = await config(repo, { | ||
* let value = await config({ | ||
* ...repo, | ||
* path: 'user.name' | ||
* }) | ||
*/ | ||
async function config({ gitdir, fs: _fs }, args) { | ||
async function config(_ref) { | ||
let { | ||
dir, | ||
gitdir = path.join(dir, '.git'), | ||
fs: _fs | ||
} = _ref, | ||
args = _objectWithoutProperties(_ref, ['dir', 'gitdir', 'fs']); | ||
const fs = new FileSystem(_fs); | ||
@@ -114,4 +141,6 @@ let { path: path$$1, value } = args; | ||
* | ||
* @param {GitRepo} repo - A {@link Git} object matching `{workdir, gitdir, fs}` | ||
* @param {Object} args - Arguments object | ||
* @param {FSModule} args.fs - The filesystem holding the git repo | ||
* @param {string} args.dir - The path to the [working tree](index.html#dir-vs-gitdir) directory | ||
* @param {string} [args.gitdir=path.join(dir, '.git')] - The path to the [git directory](index.html#dir-vs-gitdir) | ||
* @param {string} [args.url=undefined] - The URL of the remote git server. The default is the value set in the git config for that remote. | ||
@@ -130,4 +159,5 @@ * @param {string} [args.remote='origin'] - If `url` is not specified, determines which remote to use. | ||
* @example | ||
* let repo = new Git({fs, dir: '.'}) | ||
* await fetch(repo, { | ||
* let repo = {fs, dir: '.'} | ||
* await fetch({ | ||
* ...repo, | ||
* url: 'https://cors-buster-jfpactjnem.now.sh/github.com/wmhilton/isomorphic-git', | ||
@@ -137,3 +167,6 @@ * depth: 1 | ||
*/ | ||
async function fetch({ gitdir, fs }, { | ||
async function fetch({ | ||
dir, | ||
gitdir = path.join(dir, '.git'), | ||
fs, | ||
ref = 'HEAD', | ||
@@ -152,4 +185,3 @@ remote, | ||
gitdir, | ||
fs | ||
}, { | ||
fs, | ||
ref, | ||
@@ -165,6 +197,8 @@ remote, | ||
}); | ||
await unpack({ fs, gitdir }, { inputStream: response.packfile, onprogress }); | ||
await unpack({ fs, gitdir, inputStream: response.packfile, onprogress }); | ||
} | ||
async function fetchPackfile({ gitdir, fs: _fs }, { | ||
async function fetchPackfile({ | ||
gitdir, | ||
fs: _fs, | ||
ref, | ||
@@ -189,3 +223,5 @@ remote, | ||
if (url === undefined) { | ||
url = await config({ fs, gitdir }, { | ||
url = await config({ | ||
fs, | ||
gitdir, | ||
path: `remote.${remote}.url` | ||
@@ -303,8 +339,16 @@ }); | ||
* @ignore | ||
* @param {GitRepo} repo - A {@link Git} object matching `{gitdir, fs}` | ||
* @param {Object} args - Arguments object | ||
* @param {FSModule} args.fs - The filesystem holding the git repo | ||
* @param {string} args.dir - The path to the [working tree](index.html#dir-vs-gitdir) directory | ||
* @param {string} [args.gitdir=path.join(dir, '.git')] - The path to the [git directory](index.html#dir-vs-gitdir) | ||
* @param {ReadableStream} args.inputStream | ||
* @param {Function} args.onprogress | ||
*/ | ||
async function unpack({ gitdir, fs: _fs }, { inputStream, onprogress }) { | ||
async function unpack({ | ||
dir, | ||
gitdir = path.join(dir, '.git'), | ||
fs: _fs, | ||
inputStream, | ||
onprogress | ||
}) { | ||
const fs = new FileSystem(_fs); | ||
@@ -421,3 +465,3 @@ return new Promise(function (resolve, reject) { | ||
async function writeTreeToDisk({ gitdir, workdir, index, prefix, tree, fs }) { | ||
async function writeTreeToDisk({ gitdir, dir, index, prefix, tree, fs }) { | ||
for (let entry of tree) { | ||
@@ -430,3 +474,3 @@ let { type, object } = await GitObjectManager.read({ | ||
let entrypath = prefix === '' ? entry.path : `${prefix}/${entry.path}`; | ||
let filepath = path.join(workdir, prefix, entry.path); | ||
let filepath = path.join(dir, prefix, entry.path); | ||
switch (type) { | ||
@@ -446,3 +490,3 @@ case 'blob': | ||
gitdir, | ||
workdir, | ||
dir, | ||
index, | ||
@@ -462,4 +506,6 @@ prefix: entrypath, | ||
* Checkout a branch | ||
* @param {GitRepo} repo - A {@link Git} object matching `{workdir, gitdir, fs}` | ||
* @param {Object} args - Arguments object | ||
* @param {FSModule} args.fs - The filesystem holding the git repo | ||
* @param {string} args.dir - The path to the [working tree](index.html#dir-vs-gitdir) directory | ||
* @param {string} [args.gitdir=path.join(dir, '.git')] - The path to the [git directory](index.html#dir-vs-gitdir) | ||
* @param {string} [args.remote='origin'] - What to name the remote that is created. The default is 'origin'. | ||
@@ -470,6 +516,12 @@ * @param {string} [args.ref=undefined] - Which branch to clone. By default this is the designated "main branch" of the repository. | ||
* @example | ||
* let repo = new Git({fs, dir: '.'}) | ||
* await checkout(repo, {ref: 'master'}) | ||
* let repo = {fs, dir: '.'} | ||
* await checkout({...repo, ref: 'master'}) | ||
*/ | ||
async function checkout({ workdir, gitdir, fs: _fs }, { remote, ref }) { | ||
async function checkout({ | ||
dir, | ||
gitdir = path.join(dir, '.git'), | ||
fs: _fs, | ||
remote, | ||
ref | ||
}) { | ||
const fs = new FileSystem(_fs); | ||
@@ -518,3 +570,3 @@ // Get tree oid | ||
try { | ||
await fs.rm(path.join(workdir, entry.path)); | ||
await fs.rm(path.join(dir, entry.path)); | ||
} catch (err) {} | ||
@@ -524,3 +576,3 @@ } | ||
// Write files. TODO: Write them atomically | ||
await writeTreeToDisk({ fs, gitdir, workdir, index, prefix: '', tree }); | ||
await writeTreeToDisk({ fs, gitdir, dir, index, prefix: '', tree }); | ||
// Update HEAD TODO: Handle non-branch cases | ||
@@ -534,4 +586,6 @@ fs.write(`${gitdir}/HEAD`, `ref: refs/heads/${ref}`); | ||
* | ||
* @param {GitRepo} repo - A {@link Git} object matching `{workdir, gitdir, fs}` | ||
* @param {Object} args - Arguments object | ||
* @param {FSModule} args.fs - The filesystem holding the git repo | ||
* @param {string} args.dir - The path to the [working tree](index.html#dir-vs-gitdir) directory | ||
* @param {string} [args.gitdir=path.join(dir, '.git')] - The path to the [git directory](index.html#dir-vs-gitdir) | ||
* @param {string} args.url - The URL of the remote repository. | ||
@@ -550,4 +604,5 @@ * @param {string} [args.remote='origin'] - What to name the remote that is created. The default is 'origin'. | ||
* @example | ||
* let repo = new Git({fs, dir: '.'}) | ||
* await clone(repo, { | ||
* let repo = {fs, dir: '.'} | ||
* await clone({ | ||
* ...repo, | ||
* url: 'https://cors-buster-jfpactjnem.now.sh/github.com/wmhilton/isomorphic-git', | ||
@@ -557,3 +612,6 @@ * depth: 1 | ||
*/ | ||
async function clone({ workdir, gitdir, fs: _fs }, { | ||
async function clone({ | ||
dir, | ||
gitdir = path.join(dir, '.git'), | ||
fs: _fs, | ||
url, | ||
@@ -576,4 +634,3 @@ remote, | ||
gitdir, | ||
fs | ||
}, { | ||
fs, | ||
path: `remote.${remote}.url`, | ||
@@ -585,4 +642,3 @@ value: url | ||
gitdir, | ||
fs | ||
}, { | ||
fs, | ||
ref, | ||
@@ -600,6 +656,5 @@ remote, | ||
await checkout({ | ||
workdir, | ||
dir, | ||
gitdir, | ||
fs | ||
}, { | ||
fs, | ||
ref, | ||
@@ -637,4 +692,6 @@ remote | ||
* Create a new commit | ||
* @param {GitRepo} repo - A {@link Git} object matching `{gitdir, fs}` | ||
* @param {Object} args - Arguments object | ||
* @param {FSModule} args.fs - The filesystem holding the git repo | ||
* @param {string} args.dir - The path to the [working tree](index.html#dir-vs-gitdir) directory | ||
* @param {string} [args.gitdir=path.join(dir, '.git')] - The path to the [git directory](index.html#dir-vs-gitdir) | ||
* @param {string} args.message - The commit message to use. | ||
@@ -652,4 +709,5 @@ * @param {Object} [args.author] - The details about the commit author. | ||
* @example | ||
* let repo = new Git({fs, dir: '.'}) | ||
* let sha = await commit(repo, { | ||
* let repo = {fs, dir: '.'} | ||
* let sha = await commit({ | ||
* ...repo, | ||
* author: { | ||
@@ -663,3 +721,11 @@ * name: 'Mr. Test', | ||
*/ | ||
async function commit({ gitdir, fs: _fs }, { message, author, committer, privateKeys }) { | ||
async function commit({ | ||
dir, | ||
gitdir = path.join(dir, '.git'), | ||
fs: _fs, | ||
message, | ||
author, | ||
committer, | ||
privateKeys | ||
}) { | ||
const fs = new FileSystem(_fs); | ||
@@ -730,10 +796,17 @@ // Fill in missing arguments with default values | ||
* | ||
* @param {GitRepo} repo - A {@link Git} object matching `{gitdir, fs}` | ||
* @param {Object} args - Arguments object | ||
* @param {FSModule} args.fs - The filesystem holding the git repo | ||
* @param {string} args.dir - The path to the [working tree](index.html#dir-vs-gitdir) directory | ||
* @param {string} [args.gitdir=path.join(dir, '.git')] - The path to the [git directory](index.html#dir-vs-gitdir) | ||
* @returns {Promise<string[]>} - Resolves successfully with an array of file paths. | ||
* | ||
* @example | ||
* let repo = new Git({fs, dir: '.'}) | ||
* let repo = {fs, dir: '.'} | ||
* let files = await listFiles(repo) | ||
*/ | ||
async function listFiles({ gitdir, fs: _fs }) { | ||
async function listFiles({ | ||
dir, | ||
gitdir = path.join(dir, '.git'), | ||
fs: _fs | ||
}) { | ||
const fs = new FileSystem(_fs); | ||
@@ -750,10 +823,17 @@ let filenames; | ||
* | ||
* @param {GitRepo} repo - A {@link Git} object matching `{gitdir, fs}` | ||
* @param {Object} args - Arguments object | ||
* @param {FSModule} args.fs - The filesystem holding the git repo | ||
* @param {string} args.dir - The path to the [working tree](index.html#dir-vs-gitdir) directory | ||
* @param {string} [args.gitdir=path.join(dir, '.git')] - The path to the [git directory](index.html#dir-vs-gitdir) | ||
* @returns {Promise<string[]>} - Resolves successfully with an array of branch names. | ||
* | ||
* @example | ||
* let repo = new Git({fs, dir: '.'}) | ||
* let repo = {fs, dir: '.'} | ||
* let branches = await listBranches(repo) | ||
*/ | ||
async function listBranches({ gitdir, fs: _fs }) { | ||
async function listBranches({ | ||
dir, | ||
gitdir = path.join(dir, '.git'), | ||
fs: _fs | ||
}) { | ||
const fs = new FileSystem(_fs); | ||
@@ -772,3 +852,2 @@ let files = await fs.readdirDeep(`${gitdir}/refs/heads`); | ||
// @flow | ||
/** | ||
@@ -796,4 +875,6 @@ * @typedef {Object} CommitDescription | ||
* | ||
* @param {GitRepo} repo - A {@link Git} object matching `{gitdir, fs}` | ||
* @param {Object} args - Arguments object | ||
* @param {FSModule} args.fs - The filesystem holding the git repo | ||
* @param {string} args.dir - The path to the [working tree](index.html#dir-vs-gitdir) directory | ||
* @param {string} [args.gitdir=path.join(dir, '.git')] - The path to the [git directory](index.html#dir-vs-gitdir) | ||
* @param {number} [args.depth=undefined] - Limit the number of commits returned. No limit by default. | ||
@@ -805,7 +886,10 @@ * @param {Date} [args.since=undefined] - Return history newer than the given date. Can be combined with `depth` to get whichever is shorter. | ||
* @example | ||
* let repo = new Git({fs, dir: '.'}) | ||
* let commits = await log(repo, {depth: 5, ref: 'master'}) | ||
* let repo = {fs, dir: '.'} | ||
* let commits = await log({...repo, depth: 5, ref: 'master'}) | ||
* console.log(commits) | ||
*/ | ||
async function log({ gitdir, fs: _fs }, { | ||
async function log({ | ||
dir, | ||
gitdir = path.join(dir, '.git'), | ||
fs: _fs, | ||
ref = 'HEAD', | ||
@@ -867,15 +951,17 @@ depth, | ||
* | ||
* @param {GitRepo} repo - A {@link Git} object matching `{gitdir, fs}` | ||
* @param {Object} args - Arguments object | ||
* @param {integer} [args.depth=0] - Determines how much of the git repository's history to retrieve. If not specified it defaults to 0 which means the entire repo history. | ||
* @param {string} [args.ref=undefined] - Which branch to push. By default this is the currently checked out branch of the repository. | ||
* @param {string} [args.authUsername=undefined] - The username to use with Basic Auth | ||
* @param {string} [args.authPassword=undefined] - The password to use with Basic Auth | ||
* @param {string} [args.url=undefined] - The URL of the remote git server. The default is the value set in the git config for that remote. | ||
* @param {FSModule} args.fs - The filesystem holding the git repo | ||
* @param {string} args.dir - The path to the [working tree](index.html#dir-vs-gitdir) directory | ||
* @param {string} [args.gitdir=path.join(dir, '.git')] - The path to the [git directory](index.html#dir-vs-gitdir) | ||
* @param {string} [args.ref] - Which branch to push. By default this is the currently checked out branch of the repository. | ||
* @param {string} [args.remote='origin'] - If URL is not specified, determines which remote to use. | ||
* @param {string} [args.url] - The URL of the remote git server. The default is the value set in the git config for that remote. | ||
* @param {string} [args.authUsername] - The username to use with Basic Auth | ||
* @param {string} [args.authPassword] - The password to use with Basic Auth | ||
* @returns {Promise<void>} - Resolves successfully when push completes | ||
* | ||
* @example | ||
* let repo = new Git({fs, dir: '.'}) | ||
* await push(repo, { | ||
* let repo = {fs, dir: '.'} | ||
* await push({ | ||
* ...repo, | ||
* remote: 'origin', | ||
@@ -887,8 +973,16 @@ * ref: 'master', | ||
*/ | ||
};async function push({ gitdir, fs: _fs }, { ref, remote, url, authUsername, authPassword }) { | ||
};async function push({ | ||
fs: _fs, | ||
dir, | ||
gitdir = path.join(dir, '.git'), | ||
ref, | ||
remote = 'origin', | ||
url, | ||
authUsername, | ||
authPassword | ||
}) { | ||
const fs = new FileSystem(_fs); | ||
// TODO: Figure out how pushing tags works. (This only works for branches.) | ||
remote = remote || 'origin'; | ||
if (url === undefined) { | ||
url = await config({ fs, gitdir }, { path: `remote.${remote}.url` }); | ||
url = await config({ fs, gitdir, path: `remote.${remote}.url` }); | ||
} | ||
@@ -905,7 +999,9 @@ let fullRef = ref.startsWith('refs/') ? ref : `refs/heads/${ref}`; | ||
await httpRemote.preparePush(); | ||
let commits = await listCommits({ fs, gitdir }, { | ||
let commits = await listCommits({ | ||
fs, | ||
gitdir, | ||
start: [oid], | ||
finish: httpRemote.refs.values() | ||
}); | ||
let objects = await listObjects({ fs, gitdir }, { oids: commits }); | ||
let objects = await listObjects({ fs, gitdir, oids: commits }); | ||
let packstream = new PassThrough(); | ||
@@ -915,3 +1011,5 @@ let oldoid = httpRemote.refs.get(fullRef) || '0000000000000000000000000000000000000000'; | ||
packstream.write(GitPktLine.flush()); | ||
pack({ fs, gitdir }, { | ||
pack({ | ||
fs, | ||
gitdir, | ||
oids: [...objects], | ||
@@ -927,3 +1025,9 @@ outputStream: packstream | ||
*/ | ||
async function listCommits({ gitdir, fs: _fs }, { start, finish }) { | ||
async function listCommits({ | ||
dir, | ||
gitdir = path.join(dir, '.git'), | ||
fs: _fs, | ||
start, | ||
finish | ||
}) { | ||
const fs = new FileSystem(_fs); | ||
@@ -972,3 +1076,7 @@ let startingSet = new Set(); | ||
*/ | ||
async function listObjects({ gitdir, fs: _fs }, { oids /*: { oids: Set<string> } */ | ||
async function listObjects({ | ||
dir, | ||
gitdir = path.join(dir, '.git'), | ||
fs: _fs, | ||
oids | ||
}) { | ||
@@ -1010,3 +1118,9 @@ const fs = new FileSystem(_fs); | ||
*/ | ||
async function pack({ gitdir, fs: _fs }, { oids, outputStream }) { | ||
async function pack({ | ||
dir, | ||
gitdir = path.join(dir, '.git'), | ||
fs: _fs, | ||
oids, | ||
outputStream | ||
}) { | ||
const fs = new FileSystem(_fs); | ||
@@ -1066,4 +1180,6 @@ let hash = crypto.createHash('sha1'); | ||
* | ||
* @param {GitRepo} repo - A {@link Git} object matching `{gitdir, fs}` | ||
* @param {Object} args - Arguments object | ||
* @param {FSModule} args.fs - The filesystem holding the git repo | ||
* @param {string} args.dir - The path to the [working tree](index.html#dir-vs-gitdir) directory | ||
* @param {string} [args.gitdir=path.join(dir, '.git')] - The path to the [git directory](index.html#dir-vs-gitdir) | ||
* @param {string} args.filepath - The path to the file to remove to the index. | ||
@@ -1073,6 +1189,11 @@ * @returns {Promise<void>} - Resolves successfully once the git index has been updated. | ||
* @example | ||
* let repo = new Git({fs, dir: '.'}) | ||
* await remove(repo, {filepath: 'README.md'}) | ||
* let repo = {fs, dir: '.'} | ||
* await remove({...repo, filepath: 'README.md'}) | ||
*/ | ||
async function remove({ gitdir, fs: _fs }, { filepath }) { | ||
async function remove({ | ||
dir, | ||
gitdir = path.join(dir, '.git'), | ||
fs: _fs, | ||
filepath | ||
}) { | ||
const fs = new FileSystem(_fs); | ||
@@ -1088,3 +1209,9 @@ await GitIndexManager.acquire({ fs, filepath: `${gitdir}/index` }, async function (index) { | ||
/** @ignore */ | ||
async function verify({ gitdir, fs: _fs }, { ref, publicKeys }) { | ||
async function verify({ | ||
dir, | ||
gitdir = path.join(dir, '.git'), | ||
fs: _fs, | ||
ref, | ||
publicKeys | ||
}) { | ||
const fs = new FileSystem(_fs); | ||
@@ -1108,3 +1235,2 @@ const oid = await GitRefManager.resolve({ fs, gitdir, ref }); | ||
// @flow | ||
/*:: | ||
@@ -1181,4 +1307,6 @@ import type { Stats } from 'fs' | ||
* | ||
* @param {GitRepo} repo - A {@link Git} object matching `{workdir, gitdir, fs}` | ||
* @param {Object} args - Arguments object | ||
* @param {FSModule} args.fs - The filesystem holding the git repo | ||
* @param {string} args.dir - The path to the [working tree](index.html#dir-vs-gitdir) directory | ||
* @param {string} [args.gitdir=path.join(dir, '.git')] - The path to the [git directory](index.html#dir-vs-gitdir) | ||
* @param {string} args.filepath - The path to the file to query. | ||
@@ -1188,11 +1316,16 @@ * @returns {Promise<string>} - Resolves successfully with the file's git status. | ||
* @example | ||
* let repo = new Git({fs, dir: '.'}) | ||
* let gitstatus = await status(repo, {filepath: 'README.md'}) | ||
* let repo = {fs, dir: '.'} | ||
* let gitstatus = await status({...repo, filepath: 'README.md'}) | ||
* console.log(gitstatus) | ||
*/ | ||
async function status({ workdir, gitdir, fs: _fs }, { filepath }) { | ||
async function status({ | ||
dir, | ||
gitdir = path.join(dir, '.git'), | ||
fs: _fs, | ||
filepath | ||
}) { | ||
const fs = new FileSystem(_fs); | ||
let ignored = await GitIgnoreManager.isIgnored({ | ||
gitdir, | ||
workdir, | ||
dir, | ||
filepath, | ||
@@ -1223,3 +1356,3 @@ fs | ||
try { | ||
stats = await fs._lstat(path.join(workdir, filepath)); | ||
stats = await fs._lstat(path.join(dir, filepath)); | ||
} catch (err) { | ||
@@ -1239,3 +1372,3 @@ if (err.code !== 'ENOENT') { | ||
} else { | ||
let object = await fs.read(path.join(workdir, filepath)); | ||
let object = await fs.read(path.join(dir, filepath)); | ||
let workdirOid = await GitObjectManager.hash({ | ||
@@ -1293,4 +1426,4 @@ gitdir, | ||
* Find the root git directory | ||
* @param {GitRepo} repo - A {@link Git} object matching `{fs}` | ||
* @param {Object} args - Arguments object | ||
* @param {FSModule} args.fs - The filesystem holding the git repo | ||
* @param {string} args.filepath - The file directory to start searching in. | ||
@@ -1303,4 +1436,4 @@ * @returns {Promise<string>} - a directory name | ||
* @example | ||
* let repo = new Git({fs, dir: '.'}) | ||
* let gitroot = await findRoot(repo, { | ||
* let gitroot = await findRoot( { | ||
* fs, | ||
* filepath: '/path/to/some/gitrepo/path/to/some/file.txt' | ||
@@ -1310,3 +1443,3 @@ * }) | ||
*/ | ||
async function findRoot({ fs: _fs }, { filepath }) { | ||
async function findRoot({ fs: _fs, filepath }) { | ||
const fs = new FileSystem(_fs); | ||
@@ -1341,88 +1474,2 @@ return _findRoot(fs, filepath); | ||
/** | ||
* @external {FSModule} http://ghub.io/browserfs | ||
*/ | ||
/** | ||
* @typedef {Object} GitRepo | ||
* @property {FSModule} fs | ||
* @property {string} workdir | ||
* @property {string} gitdir | ||
*/ | ||
/** | ||
* | ||
* The "state" of a git repo is pretty darn simple. It consists of three things: | ||
* | ||
* - `fs` - the filesystem the repo lives in | ||
* - `workdir` - the directory path where files are checked out | ||
* - `gitdir` - the directory path where the git object database lives | ||
* | ||
* However most of the time, the relationship between `workdir` and `gitdir` is simply `gitdir = path.join(workdir, '.git')`. | ||
* So as a shorthand, you can use the `Git` constructor with `{fs, dir}`. | ||
* | ||
* If you are working with bare repositories, that relationship between the gitdir and workdir does not hold. | ||
* In this case, you need to specify the directories explicitly. | ||
* | ||
* @implements {GitRepo} | ||
* @prop {string} gitdir | ||
* @prop {string} workdir | ||
* | ||
* @example | ||
* import fs from 'fs' | ||
* import { Git } from 'isomorphic-git' | ||
* // shorthand | ||
* let repo = new Git({fs, dir: './path/to/repo'}) | ||
* // second way | ||
* let repo2 = new Git({fs, gitdir: './my-bare-repo', workdir: '/var/www/website'}) | ||
*/ | ||
class Git { | ||
/** | ||
* @constructor | ||
* @param {Object} args | ||
* @param {FSModule} args.fs - The filesystem holding the git repo | ||
* @param {string} args.dir | ||
* @param {string} [args.gitdir=dir] | ||
* @param {string} [args.workdir=path.join(dir, '.git')] | ||
*/ | ||
constructor({ fs, dir, workdir, gitdir }) { | ||
if (fs) { | ||
/** | ||
* @type {FSModule} | ||
*/ | ||
this.fs = fs; | ||
} | ||
if (dir) { | ||
/** | ||
* The directory where your files are checked out. | ||
* Usually this is the parent directory of ".git" but it doesn't have to be. | ||
* | ||
* @type {string} | ||
*/ | ||
this.workdir = dir; | ||
/** | ||
* The directory where your git repository history is stored. | ||
* Usually this is a directory called ".git" inside your working directory. | ||
* | ||
* @type {string} | ||
*/ | ||
this.gitdir = path.join(dir, '.git'); | ||
} | ||
if (workdir) this.workdir = workdir; | ||
if (gitdir) this.gitdir = gitdir; | ||
if (!this.fs) { | ||
throw new Error("Missing required argument 'fs' in Git constructor."); | ||
} | ||
if (!this.gitdir) { | ||
throw new Error("Missing required argument 'gitdir' in Git constructor."); | ||
} | ||
} | ||
/** | ||
* @returns {string} - The version of `isomorphic-git` (taken from `package.json` at publish time) | ||
*/ | ||
static version() { | ||
return pkg.version; | ||
} | ||
} | ||
export { add, clone, checkout, commit, fetch, init, listFiles, listBranches, log, push, remove, config, verify, status, findRoot, version, Git }; | ||
export { add, clone, checkout, commit, fetch, init, listFiles, listBranches, log, push, remove, config, verify, status, findRoot, version }; |
@@ -0,1 +1,2 @@ | ||
import path from 'path'; | ||
import { Buffer } from 'buffer'; | ||
@@ -17,4 +18,6 @@ import 'stream'; | ||
* Read and/or write to the git config file(s) | ||
* @param {GitRepo} repo - A {@link Git} object matching `{gitdir, fs}` | ||
* @param {Object} args - Arguments object | ||
* @param {FSModule} args.fs - The filesystem holding the git repo | ||
* @param {string} args.dir - The path to the [working tree](index.html#dir-vs-gitdir) directory | ||
* @param {string} [args.gitdir=path.join(dir, '.git')] - The path to the [git directory](index.html#dir-vs-gitdir) | ||
* @param {string} args.path - The key of the git config entry. | ||
@@ -28,6 +31,7 @@ * @param {string} [args.value] - A value to store at that path. | ||
* @example | ||
* let repo = new Git({fs, dir: '.'}) | ||
* let repo = {fs, dir: '.'} | ||
* | ||
* // Write config value | ||
* await config(repo, { | ||
* await config({ | ||
* ...repo, | ||
* path: 'user.name', | ||
@@ -38,3 +42,4 @@ * value: 'Mr. Test' | ||
* // Read config value | ||
* let value = await config(repo, { | ||
* let value = await config({ | ||
* ...repo, | ||
* path: 'user.name' | ||
@@ -53,15 +58,17 @@ * }) | ||
* | ||
* @param {GitRepo} repo - A {@link Git} object matching `{gitdir, fs}` | ||
* @param {Object} args - Arguments object | ||
* @param {integer} [args.depth=0] - Determines how much of the git repository's history to retrieve. If not specified it defaults to 0 which means the entire repo history. | ||
* @param {string} [args.ref=undefined] - Which branch to push. By default this is the currently checked out branch of the repository. | ||
* @param {string} [args.authUsername=undefined] - The username to use with Basic Auth | ||
* @param {string} [args.authPassword=undefined] - The password to use with Basic Auth | ||
* @param {string} [args.url=undefined] - The URL of the remote git server. The default is the value set in the git config for that remote. | ||
* @param {FSModule} args.fs - The filesystem holding the git repo | ||
* @param {string} args.dir - The path to the [working tree](index.html#dir-vs-gitdir) directory | ||
* @param {string} [args.gitdir=path.join(dir, '.git')] - The path to the [git directory](index.html#dir-vs-gitdir) | ||
* @param {string} [args.ref] - Which branch to push. By default this is the currently checked out branch of the repository. | ||
* @param {string} [args.remote='origin'] - If URL is not specified, determines which remote to use. | ||
* @param {string} [args.url] - The URL of the remote git server. The default is the value set in the git config for that remote. | ||
* @param {string} [args.authUsername] - The username to use with Basic Auth | ||
* @param {string} [args.authPassword] - The password to use with Basic Auth | ||
* @returns {Promise<void>} - Resolves successfully when push completes | ||
* | ||
* @example | ||
* let repo = new Git({fs, dir: '.'}) | ||
* await push(repo, { | ||
* let repo = {fs, dir: '.'} | ||
* await push({ | ||
* ...repo, | ||
* remote: 'origin', | ||
@@ -78,3 +85,9 @@ * ref: 'master', | ||
*/ | ||
async function listCommits({ gitdir, fs: _fs }, { start, finish }) { | ||
async function listCommits({ | ||
dir, | ||
gitdir = path.join(dir, '.git'), | ||
fs: _fs, | ||
start, | ||
finish | ||
}) { | ||
const fs = new FileSystem(_fs); | ||
@@ -123,3 +136,7 @@ let startingSet = new Set(); | ||
*/ | ||
async function listObjects({ gitdir, fs: _fs }, { oids /*: { oids: Set<string> } */ | ||
async function listObjects({ | ||
dir, | ||
gitdir = path.join(dir, '.git'), | ||
fs: _fs, | ||
oids | ||
}) { | ||
@@ -161,3 +178,9 @@ const fs = new FileSystem(_fs); | ||
*/ | ||
async function pack({ gitdir, fs: _fs }, { oids, outputStream }) { | ||
async function pack({ | ||
dir, | ||
gitdir = path.join(dir, '.git'), | ||
fs: _fs, | ||
oids, | ||
outputStream | ||
}) { | ||
const fs = new FileSystem(_fs); | ||
@@ -215,4 +238,6 @@ let hash = crypto.createHash('sha1'); | ||
* | ||
* @param {GitRepo} repo - A {@link Git} object matching `{workdir, gitdir, fs}` | ||
* @param {Object} args - Arguments object | ||
* @param {FSModule} args.fs - The filesystem holding the git repo | ||
* @param {string} args.dir - The path to the [working tree](index.html#dir-vs-gitdir) directory | ||
* @param {string} [args.gitdir=path.join(dir, '.git')] - The path to the [git directory](index.html#dir-vs-gitdir) | ||
* @param {string} [args.url=undefined] - The URL of the remote git server. The default is the value set in the git config for that remote. | ||
@@ -231,4 +256,5 @@ * @param {string} [args.remote='origin'] - If `url` is not specified, determines which remote to use. | ||
* @example | ||
* let repo = new Git({fs, dir: '.'}) | ||
* await fetch(repo, { | ||
* let repo = {fs, dir: '.'} | ||
* await fetch({ | ||
* ...repo, | ||
* url: 'https://cors-buster-jfpactjnem.now.sh/github.com/wmhilton/isomorphic-git', | ||
@@ -263,8 +289,16 @@ * depth: 1 | ||
* @ignore | ||
* @param {GitRepo} repo - A {@link Git} object matching `{gitdir, fs}` | ||
* @param {Object} args - Arguments object | ||
* @param {FSModule} args.fs - The filesystem holding the git repo | ||
* @param {string} args.dir - The path to the [working tree](index.html#dir-vs-gitdir) directory | ||
* @param {string} [args.gitdir=path.join(dir, '.git')] - The path to the [git directory](index.html#dir-vs-gitdir) | ||
* @param {ReadableStream} args.inputStream | ||
* @param {Function} args.onprogress | ||
*/ | ||
async function unpack({ gitdir, fs: _fs }, { inputStream, onprogress }) { | ||
async function unpack({ | ||
dir, | ||
gitdir = path.join(dir, '.git'), | ||
fs: _fs, | ||
inputStream, | ||
onprogress | ||
}) { | ||
const fs = new FileSystem(_fs); | ||
@@ -271,0 +305,0 @@ return new Promise(function (resolve, reject) { |
@@ -14,2 +14,3 @@ import { FileSystem, GitConfig, GitIndex, GitObject, GitPktLine } from './models.js'; | ||
// @flow | ||
/** @ignore */ | ||
class GitConfigManager { | ||
@@ -35,2 +36,4 @@ static async get({ fs: _fs, gitdir }) { | ||
// TODO: Add file locks. | ||
/** @ignore */ | ||
class GitShallowManager { | ||
@@ -64,2 +67,3 @@ static async read({ fs, gitdir }) { | ||
/** @ignore */ | ||
class GitIndexManager { | ||
@@ -107,7 +111,8 @@ static async acquire({ fs: _fs, filepath }, closure) { | ||
/** @ignore */ | ||
class GitIgnoreManager { | ||
static async isIgnored({ | ||
fs: _fs, | ||
gitdir, | ||
workdir, | ||
dir, | ||
gitdir = path.join(dir, '.git'), | ||
filepath | ||
@@ -117,3 +122,3 @@ }) /*: Promise<boolean> */{ | ||
let pairs = [{ | ||
gitignore: path.join(workdir, '.gitignore'), | ||
gitignore: path.join(dir, '.gitignore'), | ||
filepath | ||
@@ -123,6 +128,6 @@ }]; | ||
for (let i = 1; i < pieces.length; i++) { | ||
let dir = pieces.slice(0, i).join('/'); | ||
let folder = pieces.slice(0, i).join('/'); | ||
let file = pieces.slice(i).join('/'); | ||
pairs.push({ | ||
gitignore: path.join(workdir, dir, '.gitignore'), | ||
gitignore: path.join(dir, folder, '.gitignore'), | ||
filepath: file | ||
@@ -157,2 +162,3 @@ }); | ||
/** @ignore */ | ||
class GitObjectManager { | ||
@@ -194,2 +200,3 @@ static async read({ fs: _fs, gitdir, oid }) { | ||
// This is a convenience wrapper for reading and writing files in the 'refs' directory. | ||
/** @ignore */ | ||
class GitRefManager { | ||
@@ -296,2 +303,3 @@ /* :: | ||
/** @ignore */ | ||
class GitRemoteHTTP { | ||
@@ -298,0 +306,0 @@ /*:: |
@@ -9,2 +9,3 @@ import path from 'path'; | ||
import set from 'lodash/set'; | ||
import unset from 'lodash/unset'; | ||
import pako from 'pako'; | ||
@@ -19,2 +20,3 @@ import shasum from 'shasum'; | ||
/** | ||
* @ignore | ||
* This is just a collection of helper functions really. At least that's how it started. | ||
@@ -209,2 +211,3 @@ */ | ||
/** @ignore */ | ||
class GitCommit { | ||
@@ -350,2 +353,3 @@ /*:: | ||
/** @ignore */ | ||
class SignedGitCommit extends GitCommit { | ||
@@ -395,2 +399,3 @@ static from(commit) { | ||
// have subsections, [include] directives, etc. | ||
/** @ignore */ | ||
class GitConfig { | ||
@@ -418,3 +423,7 @@ constructor(text) { | ||
async set(path$$1, value) { | ||
return set(this.ini, path$$1, value); | ||
if (value === undefined) { | ||
unset(this.ini, path$$1); | ||
} else { | ||
set(this.ini, path$$1, value); | ||
} | ||
} | ||
@@ -438,2 +447,3 @@ toString() { | ||
/** @ignore */ | ||
class GitObject { | ||
@@ -526,2 +536,4 @@ static wrap({ type, object /*: {type: string, object: Buffer} */ }) { | ||
// There's not a lot of "state" in a pkt-line | ||
/** @ignore */ | ||
class GitPktLine { | ||
@@ -623,2 +635,3 @@ static flush() { | ||
/** @ignore */ | ||
class GitPackfile { | ||
@@ -763,2 +776,3 @@ constructor({ size, fanout, hashes, crcs, packfileSha, slices, pack }) { | ||
/** @ignore */ | ||
class GitIndex { | ||
@@ -919,2 +933,3 @@ /*:: | ||
/** @ignore */ | ||
class GitTree { | ||
@@ -921,0 +936,0 @@ /*:: |
@@ -15,2 +15,3 @@ import path from 'path'; | ||
/** @ignore */ | ||
function flatFileListToDirectoryStructure(files /*: Array<{path: string}> */ | ||
@@ -61,2 +62,3 @@ ) /*: Node|void */{ | ||
/** @ignore */ | ||
async function sleep(ms) { | ||
@@ -147,7 +149,4 @@ return new Promise((resolve, reject) => setTimeout(resolve, ms)); | ||
/** | ||
* @param {string} company | ||
* @param {string} token | ||
* @returns {username, password} | ||
* | ||
* Use with {@link #gitpush .push} and {@link #gitpull .pull} to set Basic Authentication headers. | ||
* Use with {@link push} and {@link fetch} to set Basic Authentication headers. | ||
* This for is for *actual* OAuth2 tokens (not "personal access tokens"). | ||
@@ -162,2 +161,7 @@ * Unfortunately, all the major git hosting companies have chosen different conventions! | ||
* I will gladly accept pull requests for more companies' conventions. | ||
* | ||
* @param {string} company | ||
* @param {string} token | ||
* @returns {username, password} | ||
* | ||
*/ | ||
@@ -188,3 +192,3 @@ function oauth2(company, token) { | ||
* | ||
* Use with {@link #gitpush .push} and {@link #gitpull .pull} to set Basic Authentication headers. | ||
* Use with {@link push} and {@link fetch} to set Basic Authentication headers. | ||
* This works for basic username / password auth, or the newer username / token auth | ||
@@ -191,0 +195,0 @@ * that is often required if 2FA is enabled. |
@@ -24,6 +24,12 @@ 'use strict'; | ||
/** | ||
* @external {FSModule} http://ghub.io/browserfs | ||
*/ | ||
/** | ||
* Add a file to the git index (aka staging area) | ||
* | ||
* @param {GitRepo} repo - A {@link Git} object matching `{workdir, gitdir, fs}` | ||
* @param {Object} args - Arguments object | ||
* @param {FSModule} args.fs - The filesystem holding the git repo | ||
* @param {string} args.dir - The path to the [working tree](index.html#dir-vs-gitdir) directory | ||
* @param {string} [args.gitdir=path.join(dir, '.git')] - The path to the [git directory](index.html#dir-vs-gitdir) | ||
* @param {string} args.filepath - The path to the file to add to the index. | ||
@@ -33,13 +39,18 @@ * @returns {Promise<void>} - Resolves successfully once the git index has been updated. | ||
* @example | ||
* let repo = new Git({fs, dir: '.'}) | ||
* await add(repo, {filepath: 'README.md'}) | ||
* let repo = {fs, dir: '.'} | ||
* await add({...repo, filepath: 'README.md'}) | ||
*/ | ||
async function add({ gitdir, workdir, fs: _fs }, { filepath }) { | ||
async function add({ | ||
dir, | ||
gitdir = path.join(dir, '.git'), | ||
fs: _fs, | ||
filepath | ||
}) { | ||
const fs = new models_js.FileSystem(_fs); | ||
const type = 'blob'; | ||
const object = await fs.read(path.join(workdir, filepath)); | ||
const object = await fs.read(path.join(dir, filepath)); | ||
if (object === null) throw new Error(`Could not read file '${filepath}'`); | ||
const oid = await managers_js.GitObjectManager.write({ fs, gitdir, type, object }); | ||
await managers_js.GitIndexManager.acquire({ fs, filepath: `${gitdir}/index` }, async function (index) { | ||
let stats = await fs._lstat(path.join(workdir, filepath)); | ||
let stats = await fs._lstat(path.join(dir, filepath)); | ||
index.insert({ filepath, stats, oid }); | ||
@@ -53,10 +64,13 @@ }); | ||
* | ||
* @param {GitRepo} repo - A {@link Git} object matching `{gitdir, fs}` | ||
* @param {Object} args - Arguments object | ||
* @param {FSModule} args.fs - The filesystem holding the git repo | ||
* @param {string} args.dir - The path to the [working tree](index.html#dir-vs-gitdir) directory | ||
* @param {string} [args.gitdir=path.join(dir, '.git')] - The path to the [git directory](index.html#dir-vs-gitdir) | ||
* @returns {Promise<void>} - Resolves successfully when filesystem operations are complete. | ||
* | ||
* @example | ||
* let repo = new Git({fs, dir: '.'}) | ||
* let repo = {fs, dir: '.'} | ||
* await init(repo) | ||
*/ | ||
async function init({ gitdir, fs: _fs }) { | ||
async function init({ dir, gitdir = path.join(dir, '.git'), fs: _fs }) { | ||
const fs = new models_js.FileSystem(_fs); | ||
@@ -72,6 +86,10 @@ let folders = ['hooks', 'info', 'objects/info', 'objects/pack', 'refs/heads', 'refs/tags']; | ||
function _objectWithoutProperties(obj, keys) { var target = {}; for (var i in obj) { if (keys.indexOf(i) >= 0) continue; if (!Object.prototype.hasOwnProperty.call(obj, i)) continue; target[i] = obj[i]; } return target; } | ||
/** | ||
* Read and/or write to the git config file(s) | ||
* @param {GitRepo} repo - A {@link Git} object matching `{gitdir, fs}` | ||
* @param {Object} args - Arguments object | ||
* @param {FSModule} args.fs - The filesystem holding the git repo | ||
* @param {string} args.dir - The path to the [working tree](index.html#dir-vs-gitdir) directory | ||
* @param {string} [args.gitdir=path.join(dir, '.git')] - The path to the [git directory](index.html#dir-vs-gitdir) | ||
* @param {string} args.path - The key of the git config entry. | ||
@@ -85,6 +103,7 @@ * @param {string} [args.value] - A value to store at that path. | ||
* @example | ||
* let repo = new Git({fs, dir: '.'}) | ||
* let repo = {fs, dir: '.'} | ||
* | ||
* // Write config value | ||
* await config(repo, { | ||
* await config({ | ||
* ...repo, | ||
* path: 'user.name', | ||
@@ -95,7 +114,15 @@ * value: 'Mr. Test' | ||
* // Read config value | ||
* let value = await config(repo, { | ||
* let value = await config({ | ||
* ...repo, | ||
* path: 'user.name' | ||
* }) | ||
*/ | ||
async function config({ gitdir, fs: _fs }, args) { | ||
async function config(_ref) { | ||
let { | ||
dir, | ||
gitdir = path.join(dir, '.git'), | ||
fs: _fs | ||
} = _ref, | ||
args = _objectWithoutProperties(_ref, ['dir', 'gitdir', 'fs']); | ||
const fs = new models_js.FileSystem(_fs); | ||
@@ -120,4 +147,6 @@ let { path: path$$1, value } = args; | ||
* | ||
* @param {GitRepo} repo - A {@link Git} object matching `{workdir, gitdir, fs}` | ||
* @param {Object} args - Arguments object | ||
* @param {FSModule} args.fs - The filesystem holding the git repo | ||
* @param {string} args.dir - The path to the [working tree](index.html#dir-vs-gitdir) directory | ||
* @param {string} [args.gitdir=path.join(dir, '.git')] - The path to the [git directory](index.html#dir-vs-gitdir) | ||
* @param {string} [args.url=undefined] - The URL of the remote git server. The default is the value set in the git config for that remote. | ||
@@ -136,4 +165,5 @@ * @param {string} [args.remote='origin'] - If `url` is not specified, determines which remote to use. | ||
* @example | ||
* let repo = new Git({fs, dir: '.'}) | ||
* await fetch(repo, { | ||
* let repo = {fs, dir: '.'} | ||
* await fetch({ | ||
* ...repo, | ||
* url: 'https://cors-buster-jfpactjnem.now.sh/github.com/wmhilton/isomorphic-git', | ||
@@ -143,3 +173,6 @@ * depth: 1 | ||
*/ | ||
async function fetch({ gitdir, fs }, { | ||
async function fetch({ | ||
dir, | ||
gitdir = path.join(dir, '.git'), | ||
fs, | ||
ref = 'HEAD', | ||
@@ -158,4 +191,3 @@ remote, | ||
gitdir, | ||
fs | ||
}, { | ||
fs, | ||
ref, | ||
@@ -171,6 +203,8 @@ remote, | ||
}); | ||
await unpack({ fs, gitdir }, { inputStream: response.packfile, onprogress }); | ||
await unpack({ fs, gitdir, inputStream: response.packfile, onprogress }); | ||
} | ||
async function fetchPackfile({ gitdir, fs: _fs }, { | ||
async function fetchPackfile({ | ||
gitdir, | ||
fs: _fs, | ||
ref, | ||
@@ -195,3 +229,5 @@ remote, | ||
if (url === undefined) { | ||
url = await config({ fs, gitdir }, { | ||
url = await config({ | ||
fs, | ||
gitdir, | ||
path: `remote.${remote}.url` | ||
@@ -309,8 +345,16 @@ }); | ||
* @ignore | ||
* @param {GitRepo} repo - A {@link Git} object matching `{gitdir, fs}` | ||
* @param {Object} args - Arguments object | ||
* @param {FSModule} args.fs - The filesystem holding the git repo | ||
* @param {string} args.dir - The path to the [working tree](index.html#dir-vs-gitdir) directory | ||
* @param {string} [args.gitdir=path.join(dir, '.git')] - The path to the [git directory](index.html#dir-vs-gitdir) | ||
* @param {ReadableStream} args.inputStream | ||
* @param {Function} args.onprogress | ||
*/ | ||
async function unpack({ gitdir, fs: _fs }, { inputStream, onprogress }) { | ||
async function unpack({ | ||
dir, | ||
gitdir = path.join(dir, '.git'), | ||
fs: _fs, | ||
inputStream, | ||
onprogress | ||
}) { | ||
const fs = new models_js.FileSystem(_fs); | ||
@@ -427,3 +471,3 @@ return new Promise(function (resolve, reject) { | ||
async function writeTreeToDisk({ gitdir, workdir, index, prefix, tree, fs }) { | ||
async function writeTreeToDisk({ gitdir, dir, index, prefix, tree, fs }) { | ||
for (let entry of tree) { | ||
@@ -436,3 +480,3 @@ let { type, object } = await managers_js.GitObjectManager.read({ | ||
let entrypath = prefix === '' ? entry.path : `${prefix}/${entry.path}`; | ||
let filepath = path.join(workdir, prefix, entry.path); | ||
let filepath = path.join(dir, prefix, entry.path); | ||
switch (type) { | ||
@@ -452,3 +496,3 @@ case 'blob': | ||
gitdir, | ||
workdir, | ||
dir, | ||
index, | ||
@@ -468,4 +512,6 @@ prefix: entrypath, | ||
* Checkout a branch | ||
* @param {GitRepo} repo - A {@link Git} object matching `{workdir, gitdir, fs}` | ||
* @param {Object} args - Arguments object | ||
* @param {FSModule} args.fs - The filesystem holding the git repo | ||
* @param {string} args.dir - The path to the [working tree](index.html#dir-vs-gitdir) directory | ||
* @param {string} [args.gitdir=path.join(dir, '.git')] - The path to the [git directory](index.html#dir-vs-gitdir) | ||
* @param {string} [args.remote='origin'] - What to name the remote that is created. The default is 'origin'. | ||
@@ -476,6 +522,12 @@ * @param {string} [args.ref=undefined] - Which branch to clone. By default this is the designated "main branch" of the repository. | ||
* @example | ||
* let repo = new Git({fs, dir: '.'}) | ||
* await checkout(repo, {ref: 'master'}) | ||
* let repo = {fs, dir: '.'} | ||
* await checkout({...repo, ref: 'master'}) | ||
*/ | ||
async function checkout({ workdir, gitdir, fs: _fs }, { remote, ref }) { | ||
async function checkout({ | ||
dir, | ||
gitdir = path.join(dir, '.git'), | ||
fs: _fs, | ||
remote, | ||
ref | ||
}) { | ||
const fs = new models_js.FileSystem(_fs); | ||
@@ -524,3 +576,3 @@ // Get tree oid | ||
try { | ||
await fs.rm(path.join(workdir, entry.path)); | ||
await fs.rm(path.join(dir, entry.path)); | ||
} catch (err) {} | ||
@@ -530,3 +582,3 @@ } | ||
// Write files. TODO: Write them atomically | ||
await writeTreeToDisk({ fs, gitdir, workdir, index, prefix: '', tree }); | ||
await writeTreeToDisk({ fs, gitdir, dir, index, prefix: '', tree }); | ||
// Update HEAD TODO: Handle non-branch cases | ||
@@ -540,4 +592,6 @@ fs.write(`${gitdir}/HEAD`, `ref: refs/heads/${ref}`); | ||
* | ||
* @param {GitRepo} repo - A {@link Git} object matching `{workdir, gitdir, fs}` | ||
* @param {Object} args - Arguments object | ||
* @param {FSModule} args.fs - The filesystem holding the git repo | ||
* @param {string} args.dir - The path to the [working tree](index.html#dir-vs-gitdir) directory | ||
* @param {string} [args.gitdir=path.join(dir, '.git')] - The path to the [git directory](index.html#dir-vs-gitdir) | ||
* @param {string} args.url - The URL of the remote repository. | ||
@@ -556,4 +610,5 @@ * @param {string} [args.remote='origin'] - What to name the remote that is created. The default is 'origin'. | ||
* @example | ||
* let repo = new Git({fs, dir: '.'}) | ||
* await clone(repo, { | ||
* let repo = {fs, dir: '.'} | ||
* await clone({ | ||
* ...repo, | ||
* url: 'https://cors-buster-jfpactjnem.now.sh/github.com/wmhilton/isomorphic-git', | ||
@@ -563,3 +618,6 @@ * depth: 1 | ||
*/ | ||
async function clone({ workdir, gitdir, fs: _fs }, { | ||
async function clone({ | ||
dir, | ||
gitdir = path.join(dir, '.git'), | ||
fs: _fs, | ||
url, | ||
@@ -582,4 +640,3 @@ remote, | ||
gitdir, | ||
fs | ||
}, { | ||
fs, | ||
path: `remote.${remote}.url`, | ||
@@ -591,4 +648,3 @@ value: url | ||
gitdir, | ||
fs | ||
}, { | ||
fs, | ||
ref, | ||
@@ -606,6 +662,5 @@ remote, | ||
await checkout({ | ||
workdir, | ||
dir, | ||
gitdir, | ||
fs | ||
}, { | ||
fs, | ||
ref, | ||
@@ -643,4 +698,6 @@ remote | ||
* Create a new commit | ||
* @param {GitRepo} repo - A {@link Git} object matching `{gitdir, fs}` | ||
* @param {Object} args - Arguments object | ||
* @param {FSModule} args.fs - The filesystem holding the git repo | ||
* @param {string} args.dir - The path to the [working tree](index.html#dir-vs-gitdir) directory | ||
* @param {string} [args.gitdir=path.join(dir, '.git')] - The path to the [git directory](index.html#dir-vs-gitdir) | ||
* @param {string} args.message - The commit message to use. | ||
@@ -658,4 +715,5 @@ * @param {Object} [args.author] - The details about the commit author. | ||
* @example | ||
* let repo = new Git({fs, dir: '.'}) | ||
* let sha = await commit(repo, { | ||
* let repo = {fs, dir: '.'} | ||
* let sha = await commit({ | ||
* ...repo, | ||
* author: { | ||
@@ -669,3 +727,11 @@ * name: 'Mr. Test', | ||
*/ | ||
async function commit({ gitdir, fs: _fs }, { message, author, committer, privateKeys }) { | ||
async function commit({ | ||
dir, | ||
gitdir = path.join(dir, '.git'), | ||
fs: _fs, | ||
message, | ||
author, | ||
committer, | ||
privateKeys | ||
}) { | ||
const fs = new models_js.FileSystem(_fs); | ||
@@ -736,10 +802,17 @@ // Fill in missing arguments with default values | ||
* | ||
* @param {GitRepo} repo - A {@link Git} object matching `{gitdir, fs}` | ||
* @param {Object} args - Arguments object | ||
* @param {FSModule} args.fs - The filesystem holding the git repo | ||
* @param {string} args.dir - The path to the [working tree](index.html#dir-vs-gitdir) directory | ||
* @param {string} [args.gitdir=path.join(dir, '.git')] - The path to the [git directory](index.html#dir-vs-gitdir) | ||
* @returns {Promise<string[]>} - Resolves successfully with an array of file paths. | ||
* | ||
* @example | ||
* let repo = new Git({fs, dir: '.'}) | ||
* let repo = {fs, dir: '.'} | ||
* let files = await listFiles(repo) | ||
*/ | ||
async function listFiles({ gitdir, fs: _fs }) { | ||
async function listFiles({ | ||
dir, | ||
gitdir = path.join(dir, '.git'), | ||
fs: _fs | ||
}) { | ||
const fs = new models_js.FileSystem(_fs); | ||
@@ -756,10 +829,17 @@ let filenames; | ||
* | ||
* @param {GitRepo} repo - A {@link Git} object matching `{gitdir, fs}` | ||
* @param {Object} args - Arguments object | ||
* @param {FSModule} args.fs - The filesystem holding the git repo | ||
* @param {string} args.dir - The path to the [working tree](index.html#dir-vs-gitdir) directory | ||
* @param {string} [args.gitdir=path.join(dir, '.git')] - The path to the [git directory](index.html#dir-vs-gitdir) | ||
* @returns {Promise<string[]>} - Resolves successfully with an array of branch names. | ||
* | ||
* @example | ||
* let repo = new Git({fs, dir: '.'}) | ||
* let repo = {fs, dir: '.'} | ||
* let branches = await listBranches(repo) | ||
*/ | ||
async function listBranches({ gitdir, fs: _fs }) { | ||
async function listBranches({ | ||
dir, | ||
gitdir = path.join(dir, '.git'), | ||
fs: _fs | ||
}) { | ||
const fs = new models_js.FileSystem(_fs); | ||
@@ -778,3 +858,2 @@ let files = await fs.readdirDeep(`${gitdir}/refs/heads`); | ||
// @flow | ||
/** | ||
@@ -802,4 +881,6 @@ * @typedef {Object} CommitDescription | ||
* | ||
* @param {GitRepo} repo - A {@link Git} object matching `{gitdir, fs}` | ||
* @param {Object} args - Arguments object | ||
* @param {FSModule} args.fs - The filesystem holding the git repo | ||
* @param {string} args.dir - The path to the [working tree](index.html#dir-vs-gitdir) directory | ||
* @param {string} [args.gitdir=path.join(dir, '.git')] - The path to the [git directory](index.html#dir-vs-gitdir) | ||
* @param {number} [args.depth=undefined] - Limit the number of commits returned. No limit by default. | ||
@@ -811,7 +892,10 @@ * @param {Date} [args.since=undefined] - Return history newer than the given date. Can be combined with `depth` to get whichever is shorter. | ||
* @example | ||
* let repo = new Git({fs, dir: '.'}) | ||
* let commits = await log(repo, {depth: 5, ref: 'master'}) | ||
* let repo = {fs, dir: '.'} | ||
* let commits = await log({...repo, depth: 5, ref: 'master'}) | ||
* console.log(commits) | ||
*/ | ||
async function log({ gitdir, fs: _fs }, { | ||
async function log({ | ||
dir, | ||
gitdir = path.join(dir, '.git'), | ||
fs: _fs, | ||
ref = 'HEAD', | ||
@@ -873,15 +957,17 @@ depth, | ||
* | ||
* @param {GitRepo} repo - A {@link Git} object matching `{gitdir, fs}` | ||
* @param {Object} args - Arguments object | ||
* @param {integer} [args.depth=0] - Determines how much of the git repository's history to retrieve. If not specified it defaults to 0 which means the entire repo history. | ||
* @param {string} [args.ref=undefined] - Which branch to push. By default this is the currently checked out branch of the repository. | ||
* @param {string} [args.authUsername=undefined] - The username to use with Basic Auth | ||
* @param {string} [args.authPassword=undefined] - The password to use with Basic Auth | ||
* @param {string} [args.url=undefined] - The URL of the remote git server. The default is the value set in the git config for that remote. | ||
* @param {FSModule} args.fs - The filesystem holding the git repo | ||
* @param {string} args.dir - The path to the [working tree](index.html#dir-vs-gitdir) directory | ||
* @param {string} [args.gitdir=path.join(dir, '.git')] - The path to the [git directory](index.html#dir-vs-gitdir) | ||
* @param {string} [args.ref] - Which branch to push. By default this is the currently checked out branch of the repository. | ||
* @param {string} [args.remote='origin'] - If URL is not specified, determines which remote to use. | ||
* @param {string} [args.url] - The URL of the remote git server. The default is the value set in the git config for that remote. | ||
* @param {string} [args.authUsername] - The username to use with Basic Auth | ||
* @param {string} [args.authPassword] - The password to use with Basic Auth | ||
* @returns {Promise<void>} - Resolves successfully when push completes | ||
* | ||
* @example | ||
* let repo = new Git({fs, dir: '.'}) | ||
* await push(repo, { | ||
* let repo = {fs, dir: '.'} | ||
* await push({ | ||
* ...repo, | ||
* remote: 'origin', | ||
@@ -893,8 +979,16 @@ * ref: 'master', | ||
*/ | ||
};async function push({ gitdir, fs: _fs }, { ref, remote, url, authUsername, authPassword }) { | ||
};async function push({ | ||
fs: _fs, | ||
dir, | ||
gitdir = path.join(dir, '.git'), | ||
ref, | ||
remote = 'origin', | ||
url, | ||
authUsername, | ||
authPassword | ||
}) { | ||
const fs = new models_js.FileSystem(_fs); | ||
// TODO: Figure out how pushing tags works. (This only works for branches.) | ||
remote = remote || 'origin'; | ||
if (url === undefined) { | ||
url = await config({ fs, gitdir }, { path: `remote.${remote}.url` }); | ||
url = await config({ fs, gitdir, path: `remote.${remote}.url` }); | ||
} | ||
@@ -911,7 +1005,9 @@ let fullRef = ref.startsWith('refs/') ? ref : `refs/heads/${ref}`; | ||
await httpRemote.preparePush(); | ||
let commits = await listCommits({ fs, gitdir }, { | ||
let commits = await listCommits({ | ||
fs, | ||
gitdir, | ||
start: [oid], | ||
finish: httpRemote.refs.values() | ||
}); | ||
let objects = await listObjects({ fs, gitdir }, { oids: commits }); | ||
let objects = await listObjects({ fs, gitdir, oids: commits }); | ||
let packstream = new stream.PassThrough(); | ||
@@ -921,3 +1017,5 @@ let oldoid = httpRemote.refs.get(fullRef) || '0000000000000000000000000000000000000000'; | ||
packstream.write(models_js.GitPktLine.flush()); | ||
pack({ fs, gitdir }, { | ||
pack({ | ||
fs, | ||
gitdir, | ||
oids: [...objects], | ||
@@ -933,3 +1031,9 @@ outputStream: packstream | ||
*/ | ||
async function listCommits({ gitdir, fs: _fs }, { start, finish }) { | ||
async function listCommits({ | ||
dir, | ||
gitdir = path.join(dir, '.git'), | ||
fs: _fs, | ||
start, | ||
finish | ||
}) { | ||
const fs = new models_js.FileSystem(_fs); | ||
@@ -978,3 +1082,7 @@ let startingSet = new Set(); | ||
*/ | ||
async function listObjects({ gitdir, fs: _fs }, { oids /*: { oids: Set<string> } */ | ||
async function listObjects({ | ||
dir, | ||
gitdir = path.join(dir, '.git'), | ||
fs: _fs, | ||
oids | ||
}) { | ||
@@ -1016,3 +1124,9 @@ const fs = new models_js.FileSystem(_fs); | ||
*/ | ||
async function pack({ gitdir, fs: _fs }, { oids, outputStream }) { | ||
async function pack({ | ||
dir, | ||
gitdir = path.join(dir, '.git'), | ||
fs: _fs, | ||
oids, | ||
outputStream | ||
}) { | ||
const fs = new models_js.FileSystem(_fs); | ||
@@ -1072,4 +1186,6 @@ let hash = crypto.createHash('sha1'); | ||
* | ||
* @param {GitRepo} repo - A {@link Git} object matching `{gitdir, fs}` | ||
* @param {Object} args - Arguments object | ||
* @param {FSModule} args.fs - The filesystem holding the git repo | ||
* @param {string} args.dir - The path to the [working tree](index.html#dir-vs-gitdir) directory | ||
* @param {string} [args.gitdir=path.join(dir, '.git')] - The path to the [git directory](index.html#dir-vs-gitdir) | ||
* @param {string} args.filepath - The path to the file to remove to the index. | ||
@@ -1079,6 +1195,11 @@ * @returns {Promise<void>} - Resolves successfully once the git index has been updated. | ||
* @example | ||
* let repo = new Git({fs, dir: '.'}) | ||
* await remove(repo, {filepath: 'README.md'}) | ||
* let repo = {fs, dir: '.'} | ||
* await remove({...repo, filepath: 'README.md'}) | ||
*/ | ||
async function remove({ gitdir, fs: _fs }, { filepath }) { | ||
async function remove({ | ||
dir, | ||
gitdir = path.join(dir, '.git'), | ||
fs: _fs, | ||
filepath | ||
}) { | ||
const fs = new models_js.FileSystem(_fs); | ||
@@ -1094,3 +1215,9 @@ await managers_js.GitIndexManager.acquire({ fs, filepath: `${gitdir}/index` }, async function (index) { | ||
/** @ignore */ | ||
async function verify({ gitdir, fs: _fs }, { ref, publicKeys }) { | ||
async function verify({ | ||
dir, | ||
gitdir = path.join(dir, '.git'), | ||
fs: _fs, | ||
ref, | ||
publicKeys | ||
}) { | ||
const fs = new models_js.FileSystem(_fs); | ||
@@ -1114,3 +1241,2 @@ const oid = await managers_js.GitRefManager.resolve({ fs, gitdir, ref }); | ||
// @flow | ||
/*:: | ||
@@ -1187,4 +1313,6 @@ import type { Stats } from 'fs' | ||
* | ||
* @param {GitRepo} repo - A {@link Git} object matching `{workdir, gitdir, fs}` | ||
* @param {Object} args - Arguments object | ||
* @param {FSModule} args.fs - The filesystem holding the git repo | ||
* @param {string} args.dir - The path to the [working tree](index.html#dir-vs-gitdir) directory | ||
* @param {string} [args.gitdir=path.join(dir, '.git')] - The path to the [git directory](index.html#dir-vs-gitdir) | ||
* @param {string} args.filepath - The path to the file to query. | ||
@@ -1194,11 +1322,16 @@ * @returns {Promise<string>} - Resolves successfully with the file's git status. | ||
* @example | ||
* let repo = new Git({fs, dir: '.'}) | ||
* let gitstatus = await status(repo, {filepath: 'README.md'}) | ||
* let repo = {fs, dir: '.'} | ||
* let gitstatus = await status({...repo, filepath: 'README.md'}) | ||
* console.log(gitstatus) | ||
*/ | ||
async function status({ workdir, gitdir, fs: _fs }, { filepath }) { | ||
async function status({ | ||
dir, | ||
gitdir = path.join(dir, '.git'), | ||
fs: _fs, | ||
filepath | ||
}) { | ||
const fs = new models_js.FileSystem(_fs); | ||
let ignored = await managers_js.GitIgnoreManager.isIgnored({ | ||
gitdir, | ||
workdir, | ||
dir, | ||
filepath, | ||
@@ -1229,3 +1362,3 @@ fs | ||
try { | ||
stats = await fs._lstat(path.join(workdir, filepath)); | ||
stats = await fs._lstat(path.join(dir, filepath)); | ||
} catch (err) { | ||
@@ -1245,3 +1378,3 @@ if (err.code !== 'ENOENT') { | ||
} else { | ||
let object = await fs.read(path.join(workdir, filepath)); | ||
let object = await fs.read(path.join(dir, filepath)); | ||
let workdirOid = await managers_js.GitObjectManager.hash({ | ||
@@ -1299,4 +1432,4 @@ gitdir, | ||
* Find the root git directory | ||
* @param {GitRepo} repo - A {@link Git} object matching `{fs}` | ||
* @param {Object} args - Arguments object | ||
* @param {FSModule} args.fs - The filesystem holding the git repo | ||
* @param {string} args.filepath - The file directory to start searching in. | ||
@@ -1309,4 +1442,4 @@ * @returns {Promise<string>} - a directory name | ||
* @example | ||
* let repo = new Git({fs, dir: '.'}) | ||
* let gitroot = await findRoot(repo, { | ||
* let gitroot = await findRoot( { | ||
* fs, | ||
* filepath: '/path/to/some/gitrepo/path/to/some/file.txt' | ||
@@ -1316,3 +1449,3 @@ * }) | ||
*/ | ||
async function findRoot({ fs: _fs }, { filepath }) { | ||
async function findRoot({ fs: _fs, filepath }) { | ||
const fs = new models_js.FileSystem(_fs); | ||
@@ -1347,88 +1480,2 @@ return _findRoot(fs, filepath); | ||
/** | ||
* @external {FSModule} http://ghub.io/browserfs | ||
*/ | ||
/** | ||
* @typedef {Object} GitRepo | ||
* @property {FSModule} fs | ||
* @property {string} workdir | ||
* @property {string} gitdir | ||
*/ | ||
/** | ||
* | ||
* The "state" of a git repo is pretty darn simple. It consists of three things: | ||
* | ||
* - `fs` - the filesystem the repo lives in | ||
* - `workdir` - the directory path where files are checked out | ||
* - `gitdir` - the directory path where the git object database lives | ||
* | ||
* However most of the time, the relationship between `workdir` and `gitdir` is simply `gitdir = path.join(workdir, '.git')`. | ||
* So as a shorthand, you can use the `Git` constructor with `{fs, dir}`. | ||
* | ||
* If you are working with bare repositories, that relationship between the gitdir and workdir does not hold. | ||
* In this case, you need to specify the directories explicitly. | ||
* | ||
* @implements {GitRepo} | ||
* @prop {string} gitdir | ||
* @prop {string} workdir | ||
* | ||
* @example | ||
* import fs from 'fs' | ||
* import { Git } from 'isomorphic-git' | ||
* // shorthand | ||
* let repo = new Git({fs, dir: './path/to/repo'}) | ||
* // second way | ||
* let repo2 = new Git({fs, gitdir: './my-bare-repo', workdir: '/var/www/website'}) | ||
*/ | ||
class Git { | ||
/** | ||
* @constructor | ||
* @param {Object} args | ||
* @param {FSModule} args.fs - The filesystem holding the git repo | ||
* @param {string} args.dir | ||
* @param {string} [args.gitdir=dir] | ||
* @param {string} [args.workdir=path.join(dir, '.git')] | ||
*/ | ||
constructor({ fs, dir, workdir, gitdir }) { | ||
if (fs) { | ||
/** | ||
* @type {FSModule} | ||
*/ | ||
this.fs = fs; | ||
} | ||
if (dir) { | ||
/** | ||
* The directory where your files are checked out. | ||
* Usually this is the parent directory of ".git" but it doesn't have to be. | ||
* | ||
* @type {string} | ||
*/ | ||
this.workdir = dir; | ||
/** | ||
* The directory where your git repository history is stored. | ||
* Usually this is a directory called ".git" inside your working directory. | ||
* | ||
* @type {string} | ||
*/ | ||
this.gitdir = path.join(dir, '.git'); | ||
} | ||
if (workdir) this.workdir = workdir; | ||
if (gitdir) this.gitdir = gitdir; | ||
if (!this.fs) { | ||
throw new Error("Missing required argument 'fs' in Git constructor."); | ||
} | ||
if (!this.gitdir) { | ||
throw new Error("Missing required argument 'gitdir' in Git constructor."); | ||
} | ||
} | ||
/** | ||
* @returns {string} - The version of `isomorphic-git` (taken from `package.json` at publish time) | ||
*/ | ||
static version() { | ||
return utils_js.pkg.version; | ||
} | ||
} | ||
exports.add = add; | ||
@@ -1450,2 +1497,1 @@ exports.clone = clone; | ||
exports.version = version; | ||
exports.Git = Git; |
@@ -7,2 +7,3 @@ 'use strict'; | ||
var path = _interopDefault(require('path')); | ||
var buffer = require('buffer'); | ||
@@ -24,4 +25,6 @@ require('stream'); | ||
* Read and/or write to the git config file(s) | ||
* @param {GitRepo} repo - A {@link Git} object matching `{gitdir, fs}` | ||
* @param {Object} args - Arguments object | ||
* @param {FSModule} args.fs - The filesystem holding the git repo | ||
* @param {string} args.dir - The path to the [working tree](index.html#dir-vs-gitdir) directory | ||
* @param {string} [args.gitdir=path.join(dir, '.git')] - The path to the [git directory](index.html#dir-vs-gitdir) | ||
* @param {string} args.path - The key of the git config entry. | ||
@@ -35,6 +38,7 @@ * @param {string} [args.value] - A value to store at that path. | ||
* @example | ||
* let repo = new Git({fs, dir: '.'}) | ||
* let repo = {fs, dir: '.'} | ||
* | ||
* // Write config value | ||
* await config(repo, { | ||
* await config({ | ||
* ...repo, | ||
* path: 'user.name', | ||
@@ -45,3 +49,4 @@ * value: 'Mr. Test' | ||
* // Read config value | ||
* let value = await config(repo, { | ||
* let value = await config({ | ||
* ...repo, | ||
* path: 'user.name' | ||
@@ -60,15 +65,17 @@ * }) | ||
* | ||
* @param {GitRepo} repo - A {@link Git} object matching `{gitdir, fs}` | ||
* @param {Object} args - Arguments object | ||
* @param {integer} [args.depth=0] - Determines how much of the git repository's history to retrieve. If not specified it defaults to 0 which means the entire repo history. | ||
* @param {string} [args.ref=undefined] - Which branch to push. By default this is the currently checked out branch of the repository. | ||
* @param {string} [args.authUsername=undefined] - The username to use with Basic Auth | ||
* @param {string} [args.authPassword=undefined] - The password to use with Basic Auth | ||
* @param {string} [args.url=undefined] - The URL of the remote git server. The default is the value set in the git config for that remote. | ||
* @param {FSModule} args.fs - The filesystem holding the git repo | ||
* @param {string} args.dir - The path to the [working tree](index.html#dir-vs-gitdir) directory | ||
* @param {string} [args.gitdir=path.join(dir, '.git')] - The path to the [git directory](index.html#dir-vs-gitdir) | ||
* @param {string} [args.ref] - Which branch to push. By default this is the currently checked out branch of the repository. | ||
* @param {string} [args.remote='origin'] - If URL is not specified, determines which remote to use. | ||
* @param {string} [args.url] - The URL of the remote git server. The default is the value set in the git config for that remote. | ||
* @param {string} [args.authUsername] - The username to use with Basic Auth | ||
* @param {string} [args.authPassword] - The password to use with Basic Auth | ||
* @returns {Promise<void>} - Resolves successfully when push completes | ||
* | ||
* @example | ||
* let repo = new Git({fs, dir: '.'}) | ||
* await push(repo, { | ||
* let repo = {fs, dir: '.'} | ||
* await push({ | ||
* ...repo, | ||
* remote: 'origin', | ||
@@ -85,3 +92,9 @@ * ref: 'master', | ||
*/ | ||
async function listCommits({ gitdir, fs: _fs }, { start, finish }) { | ||
async function listCommits({ | ||
dir, | ||
gitdir = path.join(dir, '.git'), | ||
fs: _fs, | ||
start, | ||
finish | ||
}) { | ||
const fs = new models_js.FileSystem(_fs); | ||
@@ -130,3 +143,7 @@ let startingSet = new Set(); | ||
*/ | ||
async function listObjects({ gitdir, fs: _fs }, { oids /*: { oids: Set<string> } */ | ||
async function listObjects({ | ||
dir, | ||
gitdir = path.join(dir, '.git'), | ||
fs: _fs, | ||
oids | ||
}) { | ||
@@ -168,3 +185,9 @@ const fs = new models_js.FileSystem(_fs); | ||
*/ | ||
async function pack({ gitdir, fs: _fs }, { oids, outputStream }) { | ||
async function pack({ | ||
dir, | ||
gitdir = path.join(dir, '.git'), | ||
fs: _fs, | ||
oids, | ||
outputStream | ||
}) { | ||
const fs = new models_js.FileSystem(_fs); | ||
@@ -222,4 +245,6 @@ let hash = crypto.createHash('sha1'); | ||
* | ||
* @param {GitRepo} repo - A {@link Git} object matching `{workdir, gitdir, fs}` | ||
* @param {Object} args - Arguments object | ||
* @param {FSModule} args.fs - The filesystem holding the git repo | ||
* @param {string} args.dir - The path to the [working tree](index.html#dir-vs-gitdir) directory | ||
* @param {string} [args.gitdir=path.join(dir, '.git')] - The path to the [git directory](index.html#dir-vs-gitdir) | ||
* @param {string} [args.url=undefined] - The URL of the remote git server. The default is the value set in the git config for that remote. | ||
@@ -238,4 +263,5 @@ * @param {string} [args.remote='origin'] - If `url` is not specified, determines which remote to use. | ||
* @example | ||
* let repo = new Git({fs, dir: '.'}) | ||
* await fetch(repo, { | ||
* let repo = {fs, dir: '.'} | ||
* await fetch({ | ||
* ...repo, | ||
* url: 'https://cors-buster-jfpactjnem.now.sh/github.com/wmhilton/isomorphic-git', | ||
@@ -270,8 +296,16 @@ * depth: 1 | ||
* @ignore | ||
* @param {GitRepo} repo - A {@link Git} object matching `{gitdir, fs}` | ||
* @param {Object} args - Arguments object | ||
* @param {FSModule} args.fs - The filesystem holding the git repo | ||
* @param {string} args.dir - The path to the [working tree](index.html#dir-vs-gitdir) directory | ||
* @param {string} [args.gitdir=path.join(dir, '.git')] - The path to the [git directory](index.html#dir-vs-gitdir) | ||
* @param {ReadableStream} args.inputStream | ||
* @param {Function} args.onprogress | ||
*/ | ||
async function unpack({ gitdir, fs: _fs }, { inputStream, onprogress }) { | ||
async function unpack({ | ||
dir, | ||
gitdir = path.join(dir, '.git'), | ||
fs: _fs, | ||
inputStream, | ||
onprogress | ||
}) { | ||
const fs = new models_js.FileSystem(_fs); | ||
@@ -278,0 +312,0 @@ return new Promise(function (resolve, reject) { |
@@ -20,2 +20,3 @@ 'use strict'; | ||
// @flow | ||
/** @ignore */ | ||
class GitConfigManager { | ||
@@ -41,2 +42,4 @@ static async get({ fs: _fs, gitdir }) { | ||
// TODO: Add file locks. | ||
/** @ignore */ | ||
class GitShallowManager { | ||
@@ -70,2 +73,3 @@ static async read({ fs, gitdir }) { | ||
/** @ignore */ | ||
class GitIndexManager { | ||
@@ -113,7 +117,8 @@ static async acquire({ fs: _fs, filepath }, closure) { | ||
/** @ignore */ | ||
class GitIgnoreManager { | ||
static async isIgnored({ | ||
fs: _fs, | ||
gitdir, | ||
workdir, | ||
dir, | ||
gitdir = path.join(dir, '.git'), | ||
filepath | ||
@@ -123,3 +128,3 @@ }) /*: Promise<boolean> */{ | ||
let pairs = [{ | ||
gitignore: path.join(workdir, '.gitignore'), | ||
gitignore: path.join(dir, '.gitignore'), | ||
filepath | ||
@@ -129,6 +134,6 @@ }]; | ||
for (let i = 1; i < pieces.length; i++) { | ||
let dir = pieces.slice(0, i).join('/'); | ||
let folder = pieces.slice(0, i).join('/'); | ||
let file = pieces.slice(i).join('/'); | ||
pairs.push({ | ||
gitignore: path.join(workdir, dir, '.gitignore'), | ||
gitignore: path.join(dir, folder, '.gitignore'), | ||
filepath: file | ||
@@ -163,2 +168,3 @@ }); | ||
/** @ignore */ | ||
class GitObjectManager { | ||
@@ -200,2 +206,3 @@ static async read({ fs: _fs, gitdir, oid }) { | ||
// This is a convenience wrapper for reading and writing files in the 'refs' directory. | ||
/** @ignore */ | ||
class GitRefManager { | ||
@@ -302,2 +309,3 @@ /* :: | ||
/** @ignore */ | ||
class GitRemoteHTTP { | ||
@@ -304,0 +312,0 @@ /*:: |
@@ -15,2 +15,3 @@ 'use strict'; | ||
var set = _interopDefault(require('lodash/set')); | ||
var unset = _interopDefault(require('lodash/unset')); | ||
var pako = _interopDefault(require('pako')); | ||
@@ -25,2 +26,3 @@ var shasum = _interopDefault(require('shasum')); | ||
/** | ||
* @ignore | ||
* This is just a collection of helper functions really. At least that's how it started. | ||
@@ -215,2 +217,3 @@ */ | ||
/** @ignore */ | ||
class GitCommit { | ||
@@ -356,2 +359,3 @@ /*:: | ||
/** @ignore */ | ||
class SignedGitCommit extends GitCommit { | ||
@@ -401,2 +405,3 @@ static from(commit) { | ||
// have subsections, [include] directives, etc. | ||
/** @ignore */ | ||
class GitConfig { | ||
@@ -424,3 +429,7 @@ constructor(text) { | ||
async set(path$$1, value) { | ||
return set(this.ini, path$$1, value); | ||
if (value === undefined) { | ||
unset(this.ini, path$$1); | ||
} else { | ||
set(this.ini, path$$1, value); | ||
} | ||
} | ||
@@ -444,2 +453,3 @@ toString() { | ||
/** @ignore */ | ||
class GitObject { | ||
@@ -532,2 +542,4 @@ static wrap({ type, object /*: {type: string, object: Buffer} */ }) { | ||
// There's not a lot of "state" in a pkt-line | ||
/** @ignore */ | ||
class GitPktLine { | ||
@@ -629,2 +641,3 @@ static flush() { | ||
/** @ignore */ | ||
class GitPackfile { | ||
@@ -769,2 +782,3 @@ constructor({ size, fanout, hashes, crcs, packfileSha, slices, pack }) { | ||
/** @ignore */ | ||
class GitIndex { | ||
@@ -925,2 +939,3 @@ /*:: | ||
/** @ignore */ | ||
class GitTree { | ||
@@ -927,0 +942,0 @@ /*:: |
@@ -21,2 +21,3 @@ 'use strict'; | ||
/** @ignore */ | ||
function flatFileListToDirectoryStructure(files /*: Array<{path: string}> */ | ||
@@ -67,2 +68,3 @@ ) /*: Node|void */{ | ||
/** @ignore */ | ||
async function sleep(ms) { | ||
@@ -153,7 +155,4 @@ return new Promise((resolve, reject) => setTimeout(resolve, ms)); | ||
/** | ||
* @param {string} company | ||
* @param {string} token | ||
* @returns {username, password} | ||
* | ||
* Use with {@link #gitpush .push} and {@link #gitpull .pull} to set Basic Authentication headers. | ||
* Use with {@link push} and {@link fetch} to set Basic Authentication headers. | ||
* This for is for *actual* OAuth2 tokens (not "personal access tokens"). | ||
@@ -168,2 +167,7 @@ * Unfortunately, all the major git hosting companies have chosen different conventions! | ||
* I will gladly accept pull requests for more companies' conventions. | ||
* | ||
* @param {string} company | ||
* @param {string} token | ||
* @returns {username, password} | ||
* | ||
*/ | ||
@@ -194,3 +198,3 @@ function oauth2(company, token) { | ||
* | ||
* Use with {@link #gitpush .push} and {@link #gitpull .pull} to set Basic Authentication headers. | ||
* Use with {@link push} and {@link fetch} to set Basic Authentication headers. | ||
* This works for basic username / password auth, or the newer username / token auth | ||
@@ -197,0 +201,0 @@ * that is often required if 2FA is enabled. |
@@ -1,1 +0,1 @@ | ||
{"name":"isomorphic-git","version":"0.0.31","description":"A pure JavaScript implementation of git for node and browsers!","typings":"./src/index.d.ts","main":"dist/for-node/","browser":"dist/for-browserify/","module":"dist/for-future/","unpkg":"dist/bundle.umd.min.js","bin":{"isogit":"./cli.js"},"engines":{"node":">=7.6.0"},"scripts":{"start":"nps","test":"nps test","precommit":"nps format toc","semantic-release":"semantic-release pre && npm publish && semantic-release post"},"repository":{"type":"git","url":"https://github.com/wmhilton/isomorphic-git.git"},"keywords":["git"],"author":"William Hilton <wmhilton@gmail.com>","license":"Unlicense","bugs":{"url":"https://github.com/wmhilton/isomorphic-git/issues"},"homepage":"https://github.com/wmhilton/isomorphic-git#readme","files":["dist","cli.js"],"dependencies":{"async-lock":"^1.0.0","await-stream-ready":"^1.0.1","babel-runtime":"^6.26.0","buffer":"^5.0.7","buffer-peek-stream":"^1.0.1","buffercursor":"0.0.12","gartal":"^1.1.2","git-apply-delta":"0.0.7","git-list-pack":"0.0.10","ignore":"^3.3.6","ini":"^1.3.4","marky":"^1.2.0","minimisted":"^2.0.0","openpgp":"^2.5.10","pad":"^2.0.1","pako":"^1.0.5","pify":"^3.0.0","shasum":"^1.0.2","simple-concat":"^1.0.0","simple-get":"^2.7.0","through2":"^2.0.3"},"devDependencies":{"babel-plugin-external-helpers":"^6.22.0","babel-plugin-transform-es2015-modules-commonjs":"^6.24.1","babel-plugin-transform-object-rest-spread":"^6.23.0","babel-plugin-transform-runtime":"^6.23.0","babel-preset-env":"^1.6.0","babel-preset-flow":"^6.23.0","ban-sensitive-files":"^1.9.0","browserfs":"^1.4.3","browserify":"^14.4.0","browserify-shim":"^3.8.14","codecov":"^3.0.0","doctoc":"^1.3.0","esdoc":"^1.0.4","esdoc-ecmascript-proposal-plugin":"^1.0.0","esdoc-importpath-plugin":"^1.0.1","esdoc-standard-plugin":"^1.0.0","husky":"^0.14.3","jest":"^21.2.1","jest-fixtures":"^0.6.0","jsonfile":"^4.0.0","karma":"^1.7.1","karma-browserify":"^5.1.1","karma-chrome-launcher":"^2.2.0","karma-firefox-launcher":"^1.0.1","karma-sauce-launcher":"^1.2.0","karma-tap":"^3.1.1","lodash":"^4.17.4","nock":"^9.0.17","npm-run-all":"^4.1.1","nps":"^5.7.1","nps-utils":"^1.4.0","parse-header-stream":"^1.1.1","prettier-standard":"^7.0.3","rollup":"^0.51.6","rollup-plugin-babel":"^3.0.2","rollup-plugin-json":"^2.3.0","standard":"^10.0.3","stream-equal":"^1.0.1","tape":"^4.8.0","uglify-es":"^3.1.2","watch":"^1.0.2","watchify":"^3.9.0","semantic-release":"^8.2.0"},"ava":{"source":["dist/for-node/*"]},"browserify":{"transform":["browserify-shim"]},"browserify-shim":{"fs":"global:fs"},"testling":{"files":"testling/basic-test.js","browsers":["chrome/latest","firefox/latest","ie/latest"]},"jest":{"testPathIgnorePatterns":["__helpers__"],"testEnvironment":"node"}} | ||
{"name":"isomorphic-git","version":"0.0.32","description":"A pure JavaScript implementation of git for node and browsers!","typings":"./src/index.d.ts","main":"dist/for-node/","browser":"dist/for-browserify/","module":"dist/for-future/","unpkg":"dist/bundle.umd.min.js","bin":{"isogit":"./cli.js"},"engines":{"node":">=7.6.0"},"scripts":{"start":"nps","test":"nps test","precommit":"nps format toc","semantic-release":"semantic-release pre && npm publish && semantic-release post"},"repository":{"type":"git","url":"https://github.com/wmhilton/isomorphic-git.git"},"keywords":["git"],"author":"William Hilton <wmhilton@gmail.com>","license":"Unlicense","bugs":{"url":"https://github.com/wmhilton/isomorphic-git/issues"},"homepage":"https://github.com/wmhilton/isomorphic-git#readme","files":["dist","cli.js"],"dependencies":{"async-lock":"^1.0.0","await-stream-ready":"^1.0.1","babel-runtime":"^6.26.0","buffer":"^5.0.7","buffer-peek-stream":"^1.0.1","buffercursor":"0.0.12","gartal":"^1.1.2","git-apply-delta":"0.0.7","git-list-pack":"0.0.10","ignore":"^3.3.6","ini":"^1.3.4","marky":"^1.2.0","minimisted":"^2.0.0","openpgp":"^2.5.10","pad":"^2.0.1","pako":"^1.0.5","pify":"^3.0.0","shasum":"^1.0.2","simple-concat":"^1.0.0","simple-get":"^2.7.0","through2":"^2.0.3"},"devDependencies":{"babel-plugin-external-helpers":"^6.22.0","babel-plugin-transform-es2015-modules-commonjs":"^6.24.1","babel-plugin-transform-object-rest-spread":"^6.23.0","babel-plugin-transform-runtime":"^6.23.0","babel-preset-env":"^1.6.0","babel-preset-flow":"^6.23.0","ban-sensitive-files":"^1.9.0","browserfs":"^1.4.3","browserify":"^14.4.0","browserify-shim":"^3.8.14","codecov":"^3.0.0","doctoc":"^1.3.0","esdoc":"^1.0.4","esdoc-ecmascript-proposal-plugin":"^1.0.0","esdoc-importpath-plugin":"^1.0.1","esdoc-standard-plugin":"^1.0.0","husky":"^0.14.3","jest":"^21.2.1","jest-fixtures":"^0.6.0","jsonfile":"^4.0.0","karma":"^1.7.1","karma-browserify":"^5.1.1","karma-chrome-launcher":"^2.2.0","karma-firefox-launcher":"^1.0.1","karma-sauce-launcher":"^1.2.0","karma-tap":"^3.1.1","lodash":"^4.17.4","nock":"^9.0.17","npm-run-all":"^4.1.1","nps":"^5.7.1","nps-utils":"^1.4.0","parse-header-stream":"^1.1.1","prettier-standard":"^7.0.3","rollup":"^0.51.6","rollup-plugin-babel":"^3.0.2","rollup-plugin-json":"^2.3.0","standard":"^10.0.3","stream-equal":"^1.0.1","tape":"^4.8.0","uglify-es":"^3.1.2","watch":"^1.0.2","watchify":"^3.9.0","semantic-release":"^8.2.0"},"ava":{"source":["dist/for-node/*"]},"browserify":{"transform":["browserify-shim"]},"browserify-shim":{"fs":"global:fs"},"testling":{"files":"testling/basic-test.js","browsers":["chrome/latest","firefox/latest","ie/latest"]},"jest":{"testPathIgnorePatterns":["__helpers__"],"testEnvironment":"node"}} |
@@ -23,10 +23,5 @@ # isomorphic-git ![node version](https://img.shields.io/node/v/isomorphic-git.svg) [![Build Status](https://travis-ci.org/wmhilton/isomorphic-git.svg?branch=master)](https://travis-ci.org/wmhilton/isomorphic-git) [![codecov](https://codecov.io/gh/wmhilton/isomorphic-git/branch/master/graph/badge.svg)](https://codecov.io/gh/wmhilton/isomorphic-git) [![dependencies](https://david-dm.org/wmhilton/isomorphic-git/status.svg)](https://david-dm.org/wmhilton/isomorphic-git) [![Known Vulnerabilities](https://snyk.io/test/github/wmhilton/isomorphic-git/badge.svg)](https://snyk.io/test/github/wmhilton/isomorphic-git) | ||
- [Getting Started](#getting-started) | ||
- [Using as an npm module](#using-as-an-npm-module) | ||
- [`isogit` CLI](#isogit-cli) | ||
- [API - New website for docs!](#api---new-website-for-docs) | ||
- [Supported Git commands](#supported-git-commands) | ||
- [Internal code architecture](#internal-code-architecture) | ||
- [Commands](#commands) | ||
- [Managers](#managers) | ||
- [Models and Utils](#models-and-utils) | ||
- [Who is using `isomorphic-git`?](#who-is-using-isomorphic-git) | ||
- [Who is using isomorphic-git?](#who-is-using-isomorphic-git) | ||
- [Similar projects](#similar-projects) | ||
@@ -50,5 +45,5 @@ - [Acknowledgments](#acknowledgments) | ||
```js | ||
const { Git } = require('isomorphic-git') | ||
const fs = require('fs') | ||
let repo = new Git({fs, dir: __dirname}) | ||
const git = require('isomorphic-git'); | ||
const fs = require('fs'); | ||
git.listFiles({fs, dir: __dirname}); | ||
``` | ||
@@ -67,3 +62,3 @@ | ||
window.fs = BrowserFS.BFSRequire("fs"); | ||
var repo = new Git({fs: window.fs, dir: '/'}) | ||
git.listFiles({fs: window.fs, dir: '/'}); | ||
}); | ||
@@ -112,3 +107,3 @@ </script> | ||
## API - New website for docs! | ||
## Supported Git commands | ||
@@ -119,2 +114,42 @@ I may continue to make changes to the API until the 1.0 release, after which I promise not to make any breaking changes. | ||
### commands | ||
- [add](https://wmhilton.github.io/isomorphic-git/doc/function/index.html#static-function-add) | ||
- [checkout](https://wmhilton.github.io/isomorphic-git/doc/function/index.html#static-function-checkout) | ||
- [clone](https://wmhilton.github.io/isomorphic-git/doc/function/index.html#static-function-clone) | ||
- [commit](https://wmhilton.github.io/isomorphic-git/doc/function/index.html#static-function-commit) | ||
- [config](https://wmhilton.github.io/isomorphic-git/doc/function/index.html#static-function-config) | ||
- [fetch](https://wmhilton.github.io/isomorphic-git/doc/function/index.html#static-function-fetch) | ||
- [findRoot](https://wmhilton.github.io/isomorphic-git/doc/function/index.html#static-function-findRoot) | ||
- [init](https://wmhilton.github.io/isomorphic-git/doc/function/index.html#static-function-init) | ||
- [listBranches](https://wmhilton.github.io/isomorphic-git/doc/function/index.html#static-function-listBranches) | ||
- [listFiles](https://wmhilton.github.io/isomorphic-git/doc/function/index.html#static-function-listFiles) | ||
- [log](https://wmhilton.github.io/isomorphic-git/doc/function/index.html#static-function-log) | ||
- [push](https://wmhilton.github.io/isomorphic-git/doc/function/index.html#static-function-push) | ||
- [remove](https://wmhilton.github.io/isomorphic-git/doc/function/index.html#static-function-remove) | ||
- [status](https://wmhilton.github.io/isomorphic-git/doc/function/index.html#static-function-status) | ||
- [verify](https://wmhilton.github.io/isomorphic-git/doc/function/index.html#static-function-verify) | ||
- [version](https://wmhilton.github.io/isomorphic-git/doc/function/index.html#static-function-version) | ||
### utils | ||
- [auth](https://wmhilton.github.io/isomorphic-git/doc/function/index.html#static-function-auth) | ||
- [oauth2](https://wmhilton.github.io/isomorphic-git/doc/function/index.html#static-function-oauth2) | ||
### dir vs gitdir | ||
I looked hard and wide for a good explanation of the "working tree" and the "git directory" and the best I found was [this one](https://stackoverflow.com/a/5283457) from Stack Overflow: | ||
If you have a non-bare git repository, there are two parts to it: the *git directory* and the *working tree*: | ||
- The *working tree* has your checked out source code, with any changes you might have made. | ||
- The *git directory* is normally named `.git`, and is in the top level of your working tree - this contains all the history of your project, configuration settings, pointers to branches, the index (staging area) and so on. | ||
> While this is the default layout of a git repository, you can actually set any directories in the filesystem to be your git directory and working tree. You can change these directories from their defaults either with the --work-tree and --git-dir options to git or by using the GIT_DIR and GIT_WORK_TREE environment variables. Usually, however, you shouldn't need to set these. | ||
In isomorphic-git the equivalent of `--work-tree` is the **`dir`** argument. | ||
In isomorphic-git the equivalent of `--git-dir` is the **`gitdir`** argument. | ||
This is really only important when working with bare repositories. | ||
## Internal code architecture | ||
@@ -145,3 +180,2 @@ | ||
This makes them portable to many different environments so they can be a useful lowest common denominator. | ||
They do not rely on Utils. | ||
@@ -151,3 +185,3 @@ Utils are basically miscellaneous functions. | ||
## Who is using `isomorphic-git`? | ||
## Who is using isomorphic-git? | ||
@@ -154,0 +188,0 @@ - [nde](https://nde.now.sh) - a futuristic next-generation web IDE |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
9083269
24555
198