isomorphic-git
Advanced tools
Comparing version 0.0.11 to 0.0.12
@@ -42,9 +42,46 @@ 'use strict'; | ||
} | ||
// This form works for basic username / password auth, or | ||
// the newer username / token auth that is often required if | ||
// 2FA is enabled. | ||
}, { | ||
key: 'githubToken', | ||
value: function githubToken(token) { | ||
this.operateToken = token; | ||
key: 'auth', | ||
value: function auth(username, password) { | ||
// Allow specifying it as one argument (mostly for CLI inputability) | ||
if (password === undefined) { | ||
var i = username.indexOf(':'); | ||
if (i > -1) { | ||
password = username.slice(i + 1); | ||
username = username.slice(0, i); | ||
} | ||
} | ||
this.operateUsername = username; | ||
this.operatePassword = password || ''; // Enables the .auth(GITHUB_TOKEN) no-username shorthand | ||
return this; | ||
} | ||
// This for is for actual OAuth2 uses. Unfortunately, the | ||
// major players all have different conventions. | ||
}, { | ||
key: 'oauth2', | ||
value: function oauth2(company, token) { | ||
switch (company) { | ||
case 'github': | ||
this.operateUsername = token; | ||
this.operatePassword = 'x-oauth-basic'; | ||
break; | ||
case 'bitbucket': | ||
this.operateUsername = 'x-token-auth'; | ||
this.operatePassword = token; | ||
break; | ||
case 'gitlab': | ||
this.operateUsername = 'oauth2'; | ||
this.operatePassword = token; | ||
break; | ||
default: | ||
throw new Error('I don\'t know how ' + company + ' expects its Basic Auth headers to be formatted for OAuth2 usage. If you do, you can use the regular \'.auth(username, password)\' to set the basic auth header yourself.'); | ||
} | ||
return this; | ||
} | ||
}, { | ||
key: 'remote', | ||
@@ -117,5 +154,5 @@ value: function remote(name) { | ||
}, { | ||
key: 'init', | ||
key: 'findRoot', | ||
value: function () { | ||
var _ref = _asyncToGenerator(_regeneratorRuntime.mark(function _callee() { | ||
var _ref = _asyncToGenerator(_regeneratorRuntime.mark(function _callee(dir) { | ||
return _regeneratorRuntime.wrap(function _callee$(_context) { | ||
@@ -125,6 +162,5 @@ while (1) { | ||
case 0: | ||
_context.next = 2; | ||
return commands_js.init(this.gitdir); | ||
return _context.abrupt('return', commands_js.findRoot(dir)); | ||
case 2: | ||
case 1: | ||
case 'end': | ||
@@ -137,13 +173,12 @@ return _context.stop(); | ||
function init$$1() { | ||
function findRoot$$1(_x) { | ||
return _ref.apply(this, arguments); | ||
} | ||
return init$$1; | ||
return findRoot$$1; | ||
}() | ||
}, { | ||
key: 'fetch', | ||
key: 'init', | ||
value: function () { | ||
var _ref2 = _asyncToGenerator(_regeneratorRuntime.mark(function _callee2(ref) { | ||
var params; | ||
var _ref2 = _asyncToGenerator(_regeneratorRuntime.mark(function _callee2() { | ||
return _regeneratorRuntime.wrap(function _callee2$(_context2) { | ||
@@ -153,19 +188,6 @@ while (1) { | ||
case 0: | ||
// TODO replace "auth" with just basicAuthUser and basicAuthPassword | ||
params = {}; | ||
_context2.next = 2; | ||
return commands_js.init(this.gitdir); | ||
params.remote = this.operateRemote; | ||
if (this.operateToken) { | ||
params.auth = { | ||
username: this.operateToken, | ||
password: this.operateToken | ||
}; | ||
} | ||
params.gitdir = this.gitdir; | ||
params.ref = ref; | ||
params.depth = this.operateDepth; | ||
_context2.next = 8; | ||
return commands_js.fetch(params); | ||
case 8: | ||
case 2: | ||
case 'end': | ||
@@ -178,10 +200,10 @@ return _context2.stop(); | ||
function fetch$$1(_x) { | ||
function init$$1() { | ||
return _ref2.apply(this, arguments); | ||
} | ||
return fetch$$1; | ||
return init$$1; | ||
}() | ||
}, { | ||
key: 'checkout', | ||
key: 'fetch', | ||
value: function () { | ||
@@ -194,7 +216,9 @@ var _ref3 = _asyncToGenerator(_regeneratorRuntime.mark(function _callee3(ref) { | ||
_context3.next = 2; | ||
return commands_js.checkout({ | ||
workdir: this.workdir, | ||
return commands_js.fetch({ | ||
gitdir: this.gitdir, | ||
ref: ref, | ||
remote: this.operateRemote | ||
depth: this.operateDepth, | ||
remote: this.operateRemote, | ||
authUsername: this.operateUsername, | ||
authPassword: this.operatePassword | ||
}); | ||
@@ -210,13 +234,12 @@ | ||
function checkout$$1(_x2) { | ||
function fetch$$1(_x2) { | ||
return _ref3.apply(this, arguments); | ||
} | ||
return checkout$$1; | ||
return fetch$$1; | ||
}() | ||
}, { | ||
key: 'clone', | ||
key: 'checkout', | ||
value: function () { | ||
var _ref4 = _asyncToGenerator(_regeneratorRuntime.mark(function _callee4(url) { | ||
var params; | ||
var _ref4 = _asyncToGenerator(_regeneratorRuntime.mark(function _callee4(ref) { | ||
return _regeneratorRuntime.wrap(function _callee4$(_context4) { | ||
@@ -227,6 +250,36 @@ while (1) { | ||
_context4.next = 2; | ||
return commands_js.checkout({ | ||
workdir: this.workdir, | ||
gitdir: this.gitdir, | ||
ref: ref, | ||
remote: this.operateRemote | ||
}); | ||
case 2: | ||
case 'end': | ||
return _context4.stop(); | ||
} | ||
} | ||
}, _callee4, this); | ||
})); | ||
function checkout$$1(_x3) { | ||
return _ref4.apply(this, arguments); | ||
} | ||
return checkout$$1; | ||
}() | ||
}, { | ||
key: 'clone', | ||
value: function () { | ||
var _ref5 = _asyncToGenerator(_regeneratorRuntime.mark(function _callee5(url) { | ||
return _regeneratorRuntime.wrap(function _callee5$(_context5) { | ||
while (1) { | ||
switch (_context5.prev = _context5.next) { | ||
case 0: | ||
_context5.next = 2; | ||
return commands_js.init(this.gitdir); | ||
case 2: | ||
_context4.next = 4; | ||
_context5.next = 4; | ||
return commands_js.setConfig({ | ||
@@ -239,20 +292,14 @@ gitdir: this.gitdir, | ||
case 4: | ||
// Fetch commits | ||
params = {}; | ||
_context5.next = 6; | ||
return commands_js.fetch({ | ||
gitdir: this.gitdir, | ||
ref: 'refs/heads/' + this.operateBranch, | ||
depth: this.operateDepth, | ||
remote: this.operateRemote, | ||
authUsername: this.operateUsername, | ||
authPassword: this.operatePassword | ||
}); | ||
params.remote = this.operateRemote; | ||
if (this.operateToken) { | ||
params.auth = { | ||
username: this.operateToken, | ||
password: this.operateToken | ||
}; | ||
} | ||
params.gitdir = this.gitdir; | ||
params.ref = 'refs/heads/' + this.operateBranch; | ||
params.depth = this.operateDepth; | ||
_context4.next = 12; | ||
return commands_js.fetch(params); | ||
case 12: | ||
_context4.next = 14; | ||
case 6: | ||
_context5.next = 8; | ||
return commands_js.checkout({ | ||
@@ -265,12 +312,12 @@ workdir: this.workdir, | ||
case 14: | ||
case 8: | ||
case 'end': | ||
return _context4.stop(); | ||
return _context5.stop(); | ||
} | ||
} | ||
}, _callee4, this); | ||
}, _callee5, this); | ||
})); | ||
function clone(_x3) { | ||
return _ref4.apply(this, arguments); | ||
function clone(_x4) { | ||
return _ref5.apply(this, arguments); | ||
} | ||
@@ -283,8 +330,8 @@ | ||
value: function () { | ||
var _ref5 = _asyncToGenerator(_regeneratorRuntime.mark(function _callee5() { | ||
return _regeneratorRuntime.wrap(function _callee5$(_context5) { | ||
var _ref6 = _asyncToGenerator(_regeneratorRuntime.mark(function _callee6() { | ||
return _regeneratorRuntime.wrap(function _callee6$(_context6) { | ||
while (1) { | ||
switch (_context5.prev = _context5.next) { | ||
switch (_context6.prev = _context6.next) { | ||
case 0: | ||
return _context5.abrupt('return', commands_js.list({ | ||
return _context6.abrupt('return', commands_js.list({ | ||
gitdir: this.gitdir | ||
@@ -295,10 +342,10 @@ })); | ||
case 'end': | ||
return _context5.stop(); | ||
return _context6.stop(); | ||
} | ||
} | ||
}, _callee5, this); | ||
}, _callee6, this); | ||
})); | ||
function list$$1() { | ||
return _ref5.apply(this, arguments); | ||
return _ref6.apply(this, arguments); | ||
} | ||
@@ -311,8 +358,8 @@ | ||
value: function () { | ||
var _ref6 = _asyncToGenerator(_regeneratorRuntime.mark(function _callee6(filepath) { | ||
return _regeneratorRuntime.wrap(function _callee6$(_context6) { | ||
var _ref7 = _asyncToGenerator(_regeneratorRuntime.mark(function _callee7(filepath) { | ||
return _regeneratorRuntime.wrap(function _callee7$(_context7) { | ||
while (1) { | ||
switch (_context6.prev = _context6.next) { | ||
switch (_context7.prev = _context7.next) { | ||
case 0: | ||
return _context6.abrupt('return', commands_js.add({ | ||
return _context7.abrupt('return', commands_js.add({ | ||
gitdir: this.gitdir, | ||
@@ -325,10 +372,10 @@ workdir: this.workdir, | ||
case 'end': | ||
return _context6.stop(); | ||
return _context7.stop(); | ||
} | ||
} | ||
}, _callee6, this); | ||
}, _callee7, this); | ||
})); | ||
function add$$1(_x4) { | ||
return _ref6.apply(this, arguments); | ||
function add$$1(_x5) { | ||
return _ref7.apply(this, arguments); | ||
} | ||
@@ -341,8 +388,8 @@ | ||
value: function () { | ||
var _ref7 = _asyncToGenerator(_regeneratorRuntime.mark(function _callee7(filepath) { | ||
return _regeneratorRuntime.wrap(function _callee7$(_context7) { | ||
var _ref8 = _asyncToGenerator(_regeneratorRuntime.mark(function _callee8(filepath) { | ||
return _regeneratorRuntime.wrap(function _callee8$(_context8) { | ||
while (1) { | ||
switch (_context7.prev = _context7.next) { | ||
switch (_context8.prev = _context8.next) { | ||
case 0: | ||
return _context7.abrupt('return', commands_js.remove({ | ||
return _context8.abrupt('return', commands_js.remove({ | ||
gitdir: this.gitdir, | ||
@@ -354,10 +401,10 @@ filepath: filepath | ||
case 'end': | ||
return _context7.stop(); | ||
return _context8.stop(); | ||
} | ||
} | ||
}, _callee7, this); | ||
}, _callee8, this); | ||
})); | ||
function remove$$1(_x5) { | ||
return _ref7.apply(this, arguments); | ||
function remove$$1(_x6) { | ||
return _ref8.apply(this, arguments); | ||
} | ||
@@ -370,106 +417,106 @@ | ||
value: function () { | ||
var _ref8 = _asyncToGenerator(_regeneratorRuntime.mark(function _callee8(message) { | ||
return _regeneratorRuntime.wrap(function _callee8$(_context8) { | ||
var _ref9 = _asyncToGenerator(_regeneratorRuntime.mark(function _callee9(message) { | ||
return _regeneratorRuntime.wrap(function _callee9$(_context9) { | ||
while (1) { | ||
switch (_context8.prev = _context8.next) { | ||
switch (_context9.prev = _context9.next) { | ||
case 0: | ||
_context8.t0 = commands_js.commit; | ||
_context8.t1 = this.gitdir; | ||
_context8.t2 = this.operateAuthorName; | ||
_context9.t0 = commands_js.commit; | ||
_context9.t1 = this.gitdir; | ||
_context9.t2 = this.operateAuthorName; | ||
if (_context8.t2) { | ||
_context8.next = 7; | ||
if (_context9.t2) { | ||
_context9.next = 7; | ||
break; | ||
} | ||
_context8.next = 6; | ||
_context9.next = 6; | ||
return this.getConfig('user.name'); | ||
case 6: | ||
_context8.t2 = _context8.sent; | ||
_context9.t2 = _context9.sent; | ||
case 7: | ||
_context8.t3 = _context8.t2; | ||
_context8.t4 = this.operateAuthorEmail; | ||
_context9.t3 = _context9.t2; | ||
_context9.t4 = this.operateAuthorEmail; | ||
if (_context8.t4) { | ||
_context8.next = 13; | ||
if (_context9.t4) { | ||
_context9.next = 13; | ||
break; | ||
} | ||
_context8.next = 12; | ||
_context9.next = 12; | ||
return this.getConfig('user.email'); | ||
case 12: | ||
_context8.t4 = _context8.sent; | ||
_context9.t4 = _context9.sent; | ||
case 13: | ||
_context8.t5 = _context8.t4; | ||
_context8.t6 = this.operateAuthorTimestamp; | ||
_context8.t7 = this.operateAuthorDateTime; | ||
_context8.t8 = { | ||
name: _context8.t3, | ||
email: _context8.t5, | ||
timestamp: _context8.t6, | ||
date: _context8.t7 | ||
_context9.t5 = _context9.t4; | ||
_context9.t6 = this.operateAuthorTimestamp; | ||
_context9.t7 = this.operateAuthorDateTime; | ||
_context9.t8 = { | ||
name: _context9.t3, | ||
email: _context9.t5, | ||
timestamp: _context9.t6, | ||
date: _context9.t7 | ||
}; | ||
_context8.t9 = this.operateAuthorName; | ||
_context9.t9 = this.operateAuthorName; | ||
if (_context8.t9) { | ||
_context8.next = 22; | ||
if (_context9.t9) { | ||
_context9.next = 22; | ||
break; | ||
} | ||
_context8.next = 21; | ||
_context9.next = 21; | ||
return this.getConfig('user.name'); | ||
case 21: | ||
_context8.t9 = _context8.sent; | ||
_context9.t9 = _context9.sent; | ||
case 22: | ||
_context8.t10 = _context8.t9; | ||
_context8.t11 = this.operateAuthorEmail; | ||
_context9.t10 = _context9.t9; | ||
_context9.t11 = this.operateAuthorEmail; | ||
if (_context8.t11) { | ||
_context8.next = 28; | ||
if (_context9.t11) { | ||
_context9.next = 28; | ||
break; | ||
} | ||
_context8.next = 27; | ||
_context9.next = 27; | ||
return this.getConfig('user.email'); | ||
case 27: | ||
_context8.t11 = _context8.sent; | ||
_context9.t11 = _context9.sent; | ||
case 28: | ||
_context8.t12 = _context8.t11; | ||
_context8.t13 = this.operateAuthorTimestamp; | ||
_context8.t14 = this.operateAuthorDateTime; | ||
_context8.t15 = { | ||
name: _context8.t10, | ||
email: _context8.t12, | ||
timestamp: _context8.t13, | ||
date: _context8.t14 | ||
_context9.t12 = _context9.t11; | ||
_context9.t13 = this.operateAuthorTimestamp; | ||
_context9.t14 = this.operateAuthorDateTime; | ||
_context9.t15 = { | ||
name: _context9.t10, | ||
email: _context9.t12, | ||
timestamp: _context9.t13, | ||
date: _context9.t14 | ||
}; | ||
_context8.t16 = message; | ||
_context8.t17 = this.privateKeys; | ||
_context8.t18 = { | ||
gitdir: _context8.t1, | ||
author: _context8.t8, | ||
committer: _context8.t15, | ||
message: _context8.t16, | ||
privateKeys: _context8.t17 | ||
_context9.t16 = message; | ||
_context9.t17 = this.privateKeys; | ||
_context9.t18 = { | ||
gitdir: _context9.t1, | ||
author: _context9.t8, | ||
committer: _context9.t15, | ||
message: _context9.t16, | ||
privateKeys: _context9.t17 | ||
}; | ||
return _context8.abrupt('return', (0, _context8.t0)(_context8.t18)); | ||
return _context9.abrupt('return', (0, _context9.t0)(_context9.t18)); | ||
case 36: | ||
case 'end': | ||
return _context8.stop(); | ||
return _context9.stop(); | ||
} | ||
} | ||
}, _callee8, this); | ||
}, _callee9, this); | ||
})); | ||
function commit$$1(_x6) { | ||
return _ref8.apply(this, arguments); | ||
function commit$$1(_x7) { | ||
return _ref9.apply(this, arguments); | ||
} | ||
@@ -482,8 +529,8 @@ | ||
value: function () { | ||
var _ref9 = _asyncToGenerator(_regeneratorRuntime.mark(function _callee9(ref) { | ||
return _regeneratorRuntime.wrap(function _callee9$(_context9) { | ||
var _ref10 = _asyncToGenerator(_regeneratorRuntime.mark(function _callee10(ref) { | ||
return _regeneratorRuntime.wrap(function _callee10$(_context10) { | ||
while (1) { | ||
switch (_context9.prev = _context9.next) { | ||
switch (_context10.prev = _context10.next) { | ||
case 0: | ||
return _context9.abrupt('return', commands_js.verify({ | ||
return _context10.abrupt('return', commands_js.verify({ | ||
gitdir: this.gitdir, | ||
@@ -496,10 +543,10 @@ publicKeys: this.publicKeys, | ||
case 'end': | ||
return _context9.stop(); | ||
return _context10.stop(); | ||
} | ||
} | ||
}, _callee9, this); | ||
}, _callee10, this); | ||
})); | ||
function verify$$1(_x7) { | ||
return _ref9.apply(this, arguments); | ||
function verify$$1(_x8) { | ||
return _ref10.apply(this, arguments); | ||
} | ||
@@ -512,8 +559,8 @@ | ||
value: function () { | ||
var _ref10 = _asyncToGenerator(_regeneratorRuntime.mark(function _callee10(oids) { | ||
return _regeneratorRuntime.wrap(function _callee10$(_context10) { | ||
var _ref11 = _asyncToGenerator(_regeneratorRuntime.mark(function _callee11(oids) { | ||
return _regeneratorRuntime.wrap(function _callee11$(_context11) { | ||
while (1) { | ||
switch (_context10.prev = _context10.next) { | ||
switch (_context11.prev = _context11.next) { | ||
case 0: | ||
return _context10.abrupt('return', commands_js.pack({ | ||
return _context11.abrupt('return', commands_js.pack({ | ||
gitdir: this.gitdir, | ||
@@ -526,10 +573,10 @@ outputStream: this.outputStream, | ||
case 'end': | ||
return _context10.stop(); | ||
return _context11.stop(); | ||
} | ||
} | ||
}, _callee10, this); | ||
}, _callee11, this); | ||
})); | ||
function pack$$1(_x8) { | ||
return _ref10.apply(this, arguments); | ||
function pack$$1(_x9) { | ||
return _ref11.apply(this, arguments); | ||
} | ||
@@ -542,8 +589,8 @@ | ||
value: function () { | ||
var _ref11 = _asyncToGenerator(_regeneratorRuntime.mark(function _callee11(oids) { | ||
return _regeneratorRuntime.wrap(function _callee11$(_context11) { | ||
var _ref12 = _asyncToGenerator(_regeneratorRuntime.mark(function _callee12(oids) { | ||
return _regeneratorRuntime.wrap(function _callee12$(_context12) { | ||
while (1) { | ||
switch (_context11.prev = _context11.next) { | ||
switch (_context12.prev = _context12.next) { | ||
case 0: | ||
return _context11.abrupt('return', commands_js.unpack({ | ||
return _context12.abrupt('return', commands_js.unpack({ | ||
gitdir: this.gitdir, | ||
@@ -555,10 +602,10 @@ inputStream: this.inputStream | ||
case 'end': | ||
return _context11.stop(); | ||
return _context12.stop(); | ||
} | ||
} | ||
}, _callee11, this); | ||
}, _callee12, this); | ||
})); | ||
function unpack$$1(_x9) { | ||
return _ref11.apply(this, arguments); | ||
function unpack$$1(_x10) { | ||
return _ref12.apply(this, arguments); | ||
} | ||
@@ -571,9 +618,9 @@ | ||
value: function () { | ||
var _ref12 = _asyncToGenerator(_regeneratorRuntime.mark(function _callee12(ref) { | ||
var _ref13 = _asyncToGenerator(_regeneratorRuntime.mark(function _callee13(ref) { | ||
var url; | ||
return _regeneratorRuntime.wrap(function _callee12$(_context12) { | ||
return _regeneratorRuntime.wrap(function _callee13$(_context13) { | ||
while (1) { | ||
switch (_context12.prev = _context12.next) { | ||
switch (_context13.prev = _context13.next) { | ||
case 0: | ||
_context12.next = 2; | ||
_context13.next = 2; | ||
return commands_js.getConfig({ | ||
@@ -585,13 +632,11 @@ gitdir: this.gitdir, | ||
case 2: | ||
url = _context12.sent; | ||
url = _context13.sent; | ||
console.log('url =', url); | ||
return _context12.abrupt('return', commands_js.push({ | ||
return _context13.abrupt('return', commands_js.push({ | ||
gitdir: this.gitdir, | ||
ref: ref, | ||
url: url, | ||
auth: { | ||
username: this.operateToken, | ||
password: this.operateToken | ||
} | ||
authUsername: this.operateUsername, | ||
authPassword: this.operatePassword | ||
})); | ||
@@ -601,10 +646,10 @@ | ||
case 'end': | ||
return _context12.stop(); | ||
return _context13.stop(); | ||
} | ||
} | ||
}, _callee12, this); | ||
}, _callee13, this); | ||
})); | ||
function push$$1(_x10) { | ||
return _ref12.apply(this, arguments); | ||
function push$$1(_x11) { | ||
return _ref13.apply(this, arguments); | ||
} | ||
@@ -617,31 +662,25 @@ | ||
value: function () { | ||
var _ref13 = _asyncToGenerator(_regeneratorRuntime.mark(function _callee13(ref) { | ||
var params; | ||
return _regeneratorRuntime.wrap(function _callee13$(_context13) { | ||
var _ref14 = _asyncToGenerator(_regeneratorRuntime.mark(function _callee14(ref) { | ||
return _regeneratorRuntime.wrap(function _callee14$(_context14) { | ||
while (1) { | ||
switch (_context13.prev = _context13.next) { | ||
switch (_context14.prev = _context14.next) { | ||
case 0: | ||
params = {}; | ||
return _context14.abrupt('return', commands_js.fetch({ | ||
gitdir: this.gitdir, | ||
ref: ref, | ||
remote: this.operateRemote, | ||
authUsername: this.operateUsername, | ||
authPassword: this.operatePassword | ||
})); | ||
params.remote = this.operateRemote; | ||
if (this.operateToken) { | ||
params.auth = { | ||
username: this.operateToken, | ||
password: this.operateToken | ||
}; | ||
} | ||
params.gitdir = this.gitdir; | ||
params.ref = ref; | ||
return _context13.abrupt('return', commands_js.fetch(params)); | ||
case 6: | ||
case 1: | ||
case 'end': | ||
return _context13.stop(); | ||
return _context14.stop(); | ||
} | ||
} | ||
}, _callee13, this); | ||
}, _callee14, this); | ||
})); | ||
function pull(_x11) { | ||
return _ref13.apply(this, arguments); | ||
function pull(_x12) { | ||
return _ref14.apply(this, arguments); | ||
} | ||
@@ -654,8 +693,8 @@ | ||
value: function () { | ||
var _ref14 = _asyncToGenerator(_regeneratorRuntime.mark(function _callee14(path) { | ||
return _regeneratorRuntime.wrap(function _callee14$(_context14) { | ||
var _ref15 = _asyncToGenerator(_regeneratorRuntime.mark(function _callee15(path) { | ||
return _regeneratorRuntime.wrap(function _callee15$(_context15) { | ||
while (1) { | ||
switch (_context14.prev = _context14.next) { | ||
switch (_context15.prev = _context15.next) { | ||
case 0: | ||
return _context14.abrupt('return', commands_js.getConfig({ | ||
return _context15.abrupt('return', commands_js.getConfig({ | ||
gitdir: this.gitdir, | ||
@@ -667,10 +706,10 @@ path: path | ||
case 'end': | ||
return _context14.stop(); | ||
return _context15.stop(); | ||
} | ||
} | ||
}, _callee14, this); | ||
}, _callee15, this); | ||
})); | ||
function getConfig$$1(_x12) { | ||
return _ref14.apply(this, arguments); | ||
function getConfig$$1(_x13) { | ||
return _ref15.apply(this, arguments); | ||
} | ||
@@ -683,8 +722,8 @@ | ||
value: function () { | ||
var _ref15 = _asyncToGenerator(_regeneratorRuntime.mark(function _callee15(path, value) { | ||
return _regeneratorRuntime.wrap(function _callee15$(_context15) { | ||
var _ref16 = _asyncToGenerator(_regeneratorRuntime.mark(function _callee16(path, value) { | ||
return _regeneratorRuntime.wrap(function _callee16$(_context16) { | ||
while (1) { | ||
switch (_context15.prev = _context15.next) { | ||
switch (_context16.prev = _context16.next) { | ||
case 0: | ||
return _context15.abrupt('return', commands_js.setConfig({ | ||
return _context16.abrupt('return', commands_js.setConfig({ | ||
gitdir: this.gitdir, | ||
@@ -697,10 +736,10 @@ path: path, | ||
case 'end': | ||
return _context15.stop(); | ||
return _context16.stop(); | ||
} | ||
} | ||
}, _callee15, this); | ||
}, _callee16, this); | ||
})); | ||
function setConfig$$1(_x13, _x14) { | ||
return _ref15.apply(this, arguments); | ||
function setConfig$$1(_x14, _x15) { | ||
return _ref16.apply(this, arguments); | ||
} | ||
@@ -713,8 +752,8 @@ | ||
value: function () { | ||
var _ref16 = _asyncToGenerator(_regeneratorRuntime.mark(function _callee16(pathname) { | ||
return _regeneratorRuntime.wrap(function _callee16$(_context16) { | ||
var _ref17 = _asyncToGenerator(_regeneratorRuntime.mark(function _callee17(pathname) { | ||
return _regeneratorRuntime.wrap(function _callee17$(_context17) { | ||
while (1) { | ||
switch (_context16.prev = _context16.next) { | ||
switch (_context17.prev = _context17.next) { | ||
case 0: | ||
return _context16.abrupt('return', commands_js.status({ | ||
return _context17.abrupt('return', commands_js.status({ | ||
gitdir: this.gitdir, | ||
@@ -727,10 +766,10 @@ workdir: this.workdir, | ||
case 'end': | ||
return _context16.stop(); | ||
return _context17.stop(); | ||
} | ||
} | ||
}, _callee16, this); | ||
}, _callee17, this); | ||
})); | ||
function status$$1(_x15) { | ||
return _ref16.apply(this, arguments); | ||
function status$$1(_x16) { | ||
return _ref17.apply(this, arguments); | ||
} | ||
@@ -737,0 +776,0 @@ |
@@ -613,3 +613,3 @@ 'use strict'; | ||
var name = "isomorphic-git"; | ||
var version = "0.0.11"; | ||
var version = "0.0.12"; | ||
var description = "Node library for interacting with git repositories, circa 2017"; | ||
@@ -616,0 +616,0 @@ var main = "dist/for-node/"; |
@@ -286,3 +286,4 @@ import path from 'path'; | ||
remote, | ||
auth, | ||
authUsername, | ||
authPassword, | ||
depth = 0 | ||
@@ -295,3 +296,8 @@ }) { | ||
let remoteHTTP = new GitRemoteHTTP(url); | ||
remoteHTTP.auth = auth; | ||
if (authUsername !== undefined && authPassword !== undefined) { | ||
remoteHTTP.auth = { | ||
username: authUsername, | ||
password: authPassword | ||
}; | ||
} | ||
await remoteHTTP.preparePull(); | ||
@@ -357,4 +363,18 @@ // Check server supports shallow cloning | ||
async function fetch({ gitdir, ref = 'HEAD', remote, auth, depth = 0 }) { | ||
let response = await fetchPackfile({ gitdir, ref, remote, auth, depth }); | ||
async function fetch({ | ||
gitdir, | ||
ref = 'HEAD', | ||
remote, | ||
authUsername, | ||
authPassword, | ||
depth = 0 | ||
}) { | ||
let response = await fetchPackfile({ | ||
gitdir, | ||
ref, | ||
remote, | ||
authUsername, | ||
authPassword, | ||
depth | ||
}); | ||
response.progress.on('data', data => console.log(data.toString('utf8'))); | ||
@@ -536,6 +556,17 @@ await unpack({ gitdir, inputStream: response.packfile }); | ||
// @flow | ||
async function push({ gitdir, ref = 'HEAD', url, auth }) { | ||
async function push({ | ||
gitdir, | ||
ref = 'HEAD', | ||
url, | ||
authUsername, | ||
authPassword | ||
}) { | ||
let oid = await resolveRef({ gitdir, ref }); | ||
let remote = new GitRemoteHTTP(url); | ||
remote.auth = auth; | ||
if (authUsername !== undefined && authPassword !== undefined) { | ||
remote.auth = { | ||
username: authUsername, | ||
password: authPassword | ||
}; | ||
} | ||
await remote.preparePush(); | ||
@@ -711,2 +742,18 @@ let commits = await listCommits({ | ||
export { add, checkout, commit, fetch, getConfig, init, list, listCommits, listObjects, pack, push, remove, setConfig, unpack, verify, status }; | ||
async function test(filepath) { | ||
try { | ||
await pify(fs().lstat)(path.join(filepath, '.git')); | ||
return true; | ||
} catch (err) { | ||
return false; | ||
} | ||
} | ||
// TODO: Detect base repositories? | ||
async function findRoot(filepath) { | ||
if (await test(filepath)) return filepath; | ||
let parent = path.dirname(filepath); | ||
if (parent === filepath) throw new Error('Unable to find git root'); | ||
return findRoot(parent); | ||
} | ||
export { add, checkout, commit, fetch, getConfig, init, list, listCommits, listObjects, pack, push, remove, setConfig, unpack, verify, status, findRoot }; |
@@ -1,2 +0,2 @@ | ||
import { add, checkout, commit, fetch, getConfig, init, list, pack, push, remove, setConfig, status, unpack, verify } from './commands.js'; | ||
import { add, checkout, commit, fetch, findRoot, getConfig, init, list, pack, push, remove, setConfig, status, unpack, verify } from './commands.js'; | ||
@@ -26,6 +26,39 @@ function git(dir) { | ||
} | ||
githubToken(token) { | ||
this.operateToken = token; | ||
// This form works for basic username / password auth, or | ||
// the newer username / token auth that is often required if | ||
// 2FA is enabled. | ||
auth(username, password) { | ||
// Allow specifying it as one argument (mostly for CLI inputability) | ||
if (password === undefined) { | ||
let i = username.indexOf(':'); | ||
if (i > -1) { | ||
password = username.slice(i + 1); | ||
username = username.slice(0, i); | ||
} | ||
} | ||
this.operateUsername = username; | ||
this.operatePassword = password || ''; // Enables the .auth(GITHUB_TOKEN) no-username shorthand | ||
return this; | ||
} | ||
// This for is for actual OAuth2 uses. Unfortunately, the | ||
// major players all have different conventions. | ||
oauth2(company, token) { | ||
switch (company) { | ||
case 'github': | ||
this.operateUsername = token; | ||
this.operatePassword = 'x-oauth-basic'; | ||
break; | ||
case 'bitbucket': | ||
this.operateUsername = 'x-token-auth'; | ||
this.operatePassword = token; | ||
break; | ||
case 'gitlab': | ||
this.operateUsername = 'oauth2'; | ||
this.operatePassword = token; | ||
break; | ||
default: | ||
throw new Error(`I don't know how ${company} expects its Basic Auth headers to be formatted for OAuth2 usage. If you do, you can use the regular '.auth(username, password)' to set the basic auth header yourself.`); | ||
} | ||
return this; | ||
} | ||
remote(name) { | ||
@@ -76,2 +109,5 @@ this.operateRemote = name; | ||
} | ||
async findRoot(dir) { | ||
return findRoot(dir); | ||
} | ||
async init() { | ||
@@ -81,15 +117,10 @@ await init(this.gitdir); | ||
async fetch(ref) { | ||
// TODO replace "auth" with just basicAuthUser and basicAuthPassword | ||
let params = {}; | ||
params.remote = this.operateRemote; | ||
if (this.operateToken) { | ||
params.auth = { | ||
username: this.operateToken, | ||
password: this.operateToken | ||
}; | ||
} | ||
params.gitdir = this.gitdir; | ||
params.ref = ref; | ||
params.depth = this.operateDepth; | ||
await fetch(params); | ||
await fetch({ | ||
gitdir: this.gitdir, | ||
ref, | ||
depth: this.operateDepth, | ||
remote: this.operateRemote, | ||
authUsername: this.operateUsername, | ||
authPassword: this.operatePassword | ||
}); | ||
} | ||
@@ -113,14 +144,10 @@ async checkout(ref) { | ||
// Fetch commits | ||
let params = {}; | ||
params.remote = this.operateRemote; | ||
if (this.operateToken) { | ||
params.auth = { | ||
username: this.operateToken, | ||
password: this.operateToken | ||
}; | ||
} | ||
params.gitdir = this.gitdir; | ||
params.ref = `refs/heads/${this.operateBranch}`; | ||
params.depth = this.operateDepth; | ||
await fetch(params); | ||
await fetch({ | ||
gitdir: this.gitdir, | ||
ref: `refs/heads/${this.operateBranch}`, | ||
depth: this.operateDepth, | ||
remote: this.operateRemote, | ||
authUsername: this.operateUsername, | ||
authPassword: this.operatePassword | ||
}); | ||
// Checkout branch | ||
@@ -201,20 +228,14 @@ await checkout({ | ||
url, | ||
auth: { | ||
username: this.operateToken, | ||
password: this.operateToken | ||
} | ||
authUsername: this.operateUsername, | ||
authPassword: this.operatePassword | ||
}); | ||
} | ||
async pull(ref) { | ||
let params = {}; | ||
params.remote = this.operateRemote; | ||
if (this.operateToken) { | ||
params.auth = { | ||
username: this.operateToken, | ||
password: this.operateToken | ||
}; | ||
} | ||
params.gitdir = this.gitdir; | ||
params.ref = ref; | ||
return fetch(params); | ||
return fetch({ | ||
gitdir: this.gitdir, | ||
ref, | ||
remote: this.operateRemote, | ||
authUsername: this.operateUsername, | ||
authPassword: this.operatePassword | ||
}); | ||
} | ||
@@ -221,0 +242,0 @@ async getConfig(path) { |
@@ -218,3 +218,3 @@ import systemfs from 'fs'; | ||
var name = "isomorphic-git"; | ||
var version = "0.0.11"; | ||
var version = "0.0.12"; | ||
var description = "Node library for interacting with git repositories, circa 2017"; | ||
@@ -221,0 +221,0 @@ var main = "dist/for-node/"; |
@@ -292,3 +292,4 @@ 'use strict'; | ||
remote, | ||
auth, | ||
authUsername, | ||
authPassword, | ||
depth = 0 | ||
@@ -301,3 +302,8 @@ }) { | ||
let remoteHTTP = new managers_js.GitRemoteHTTP(url); | ||
remoteHTTP.auth = auth; | ||
if (authUsername !== undefined && authPassword !== undefined) { | ||
remoteHTTP.auth = { | ||
username: authUsername, | ||
password: authPassword | ||
}; | ||
} | ||
await remoteHTTP.preparePull(); | ||
@@ -363,4 +369,18 @@ // Check server supports shallow cloning | ||
async function fetch({ gitdir, ref = 'HEAD', remote, auth, depth = 0 }) { | ||
let response = await fetchPackfile({ gitdir, ref, remote, auth, depth }); | ||
async function fetch({ | ||
gitdir, | ||
ref = 'HEAD', | ||
remote, | ||
authUsername, | ||
authPassword, | ||
depth = 0 | ||
}) { | ||
let response = await fetchPackfile({ | ||
gitdir, | ||
ref, | ||
remote, | ||
authUsername, | ||
authPassword, | ||
depth | ||
}); | ||
response.progress.on('data', data => console.log(data.toString('utf8'))); | ||
@@ -542,6 +562,17 @@ await unpack({ gitdir, inputStream: response.packfile }); | ||
// @flow | ||
async function push({ gitdir, ref = 'HEAD', url, auth }) { | ||
async function push({ | ||
gitdir, | ||
ref = 'HEAD', | ||
url, | ||
authUsername, | ||
authPassword | ||
}) { | ||
let oid = await utils_js.resolveRef({ gitdir, ref }); | ||
let remote = new managers_js.GitRemoteHTTP(url); | ||
remote.auth = auth; | ||
if (authUsername !== undefined && authPassword !== undefined) { | ||
remote.auth = { | ||
username: authUsername, | ||
password: authPassword | ||
}; | ||
} | ||
await remote.preparePush(); | ||
@@ -717,2 +748,18 @@ let commits = await listCommits({ | ||
async function test(filepath) { | ||
try { | ||
await pify(utils_js.fs().lstat)(path.join(filepath, '.git')); | ||
return true; | ||
} catch (err) { | ||
return false; | ||
} | ||
} | ||
// TODO: Detect base repositories? | ||
async function findRoot(filepath) { | ||
if (await test(filepath)) return filepath; | ||
let parent = path.dirname(filepath); | ||
if (parent === filepath) throw new Error('Unable to find git root'); | ||
return findRoot(parent); | ||
} | ||
exports.add = add; | ||
@@ -734,1 +781,2 @@ exports.checkout = checkout; | ||
exports.status = status; | ||
exports.findRoot = findRoot; |
@@ -28,6 +28,39 @@ 'use strict'; | ||
} | ||
githubToken(token) { | ||
this.operateToken = token; | ||
// This form works for basic username / password auth, or | ||
// the newer username / token auth that is often required if | ||
// 2FA is enabled. | ||
auth(username, password) { | ||
// Allow specifying it as one argument (mostly for CLI inputability) | ||
if (password === undefined) { | ||
let i = username.indexOf(':'); | ||
if (i > -1) { | ||
password = username.slice(i + 1); | ||
username = username.slice(0, i); | ||
} | ||
} | ||
this.operateUsername = username; | ||
this.operatePassword = password || ''; // Enables the .auth(GITHUB_TOKEN) no-username shorthand | ||
return this; | ||
} | ||
// This for is for actual OAuth2 uses. Unfortunately, the | ||
// major players all have different conventions. | ||
oauth2(company, token) { | ||
switch (company) { | ||
case 'github': | ||
this.operateUsername = token; | ||
this.operatePassword = 'x-oauth-basic'; | ||
break; | ||
case 'bitbucket': | ||
this.operateUsername = 'x-token-auth'; | ||
this.operatePassword = token; | ||
break; | ||
case 'gitlab': | ||
this.operateUsername = 'oauth2'; | ||
this.operatePassword = token; | ||
break; | ||
default: | ||
throw new Error(`I don't know how ${company} expects its Basic Auth headers to be formatted for OAuth2 usage. If you do, you can use the regular '.auth(username, password)' to set the basic auth header yourself.`); | ||
} | ||
return this; | ||
} | ||
remote(name) { | ||
@@ -78,2 +111,5 @@ this.operateRemote = name; | ||
} | ||
async findRoot(dir) { | ||
return commands_js.findRoot(dir); | ||
} | ||
async init() { | ||
@@ -83,15 +119,10 @@ await commands_js.init(this.gitdir); | ||
async fetch(ref) { | ||
// TODO replace "auth" with just basicAuthUser and basicAuthPassword | ||
let params = {}; | ||
params.remote = this.operateRemote; | ||
if (this.operateToken) { | ||
params.auth = { | ||
username: this.operateToken, | ||
password: this.operateToken | ||
}; | ||
} | ||
params.gitdir = this.gitdir; | ||
params.ref = ref; | ||
params.depth = this.operateDepth; | ||
await commands_js.fetch(params); | ||
await commands_js.fetch({ | ||
gitdir: this.gitdir, | ||
ref, | ||
depth: this.operateDepth, | ||
remote: this.operateRemote, | ||
authUsername: this.operateUsername, | ||
authPassword: this.operatePassword | ||
}); | ||
} | ||
@@ -115,14 +146,10 @@ async checkout(ref) { | ||
// Fetch commits | ||
let params = {}; | ||
params.remote = this.operateRemote; | ||
if (this.operateToken) { | ||
params.auth = { | ||
username: this.operateToken, | ||
password: this.operateToken | ||
}; | ||
} | ||
params.gitdir = this.gitdir; | ||
params.ref = `refs/heads/${this.operateBranch}`; | ||
params.depth = this.operateDepth; | ||
await commands_js.fetch(params); | ||
await commands_js.fetch({ | ||
gitdir: this.gitdir, | ||
ref: `refs/heads/${this.operateBranch}`, | ||
depth: this.operateDepth, | ||
remote: this.operateRemote, | ||
authUsername: this.operateUsername, | ||
authPassword: this.operatePassword | ||
}); | ||
// Checkout branch | ||
@@ -203,20 +230,14 @@ await commands_js.checkout({ | ||
url, | ||
auth: { | ||
username: this.operateToken, | ||
password: this.operateToken | ||
} | ||
authUsername: this.operateUsername, | ||
authPassword: this.operatePassword | ||
}); | ||
} | ||
async pull(ref) { | ||
let params = {}; | ||
params.remote = this.operateRemote; | ||
if (this.operateToken) { | ||
params.auth = { | ||
username: this.operateToken, | ||
password: this.operateToken | ||
}; | ||
} | ||
params.gitdir = this.gitdir; | ||
params.ref = ref; | ||
return commands_js.fetch(params); | ||
return commands_js.fetch({ | ||
gitdir: this.gitdir, | ||
ref, | ||
remote: this.operateRemote, | ||
authUsername: this.operateUsername, | ||
authPassword: this.operatePassword | ||
}); | ||
} | ||
@@ -223,0 +244,0 @@ async getConfig(path) { |
@@ -224,3 +224,3 @@ 'use strict'; | ||
var name = "isomorphic-git"; | ||
var version = "0.0.11"; | ||
var version = "0.0.12"; | ||
var description = "Node library for interacting with git repositories, circa 2017"; | ||
@@ -227,0 +227,0 @@ var main = "dist/for-node/"; |
{ | ||
"name": "isomorphic-git", | ||
"version": "0.0.11", | ||
"version": "0.0.12", | ||
"description": "Node library for interacting with git repositories, circa 2017", | ||
@@ -5,0 +5,0 @@ "main": "dist/for-node/", |
@@ -92,6 +92,28 @@ # isomorphic-git [![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) | ||
git('.') | ||
.githubToken(process.env.GITHUB_TOKEN) | ||
.auth(process.env.GITHUB_TOKEN) | ||
.remote('origin') | ||
.push('refs/heads/master') | ||
// Basic Authentication - may not work if 2FA is enabled on your account! | ||
git('.').auth('username', 'password') | ||
// a one-argument version is also supported | ||
git('.').auth('username:password') | ||
// Personal Access Token Authentication | ||
// (note Bitbucket calls theirs App Passwords instead for some reason) | ||
git('.').auth('username', 'personal access token') | ||
git('.').auth('username', 'app password') | ||
git('.').auth('personal access token') // Github (only) lets you leave out the username | ||
// OAuth2 Token Authentication | ||
// (each of the major players formats OAuth2 headers slightly differently | ||
// so you must pass the name of the company as the first argument) | ||
git('.').oauth2('github', 'token') | ||
git('.').oauth2('gitlab', 'token') | ||
git('.').oauth2('bitbucket', 'token') | ||
// Given a file path, find the nearest parent directory containing a .git folder | ||
git().findRoot('/path/to/some/gitrepo/path/to/some/file.txt') // '/path/to/some/gitrepo' | ||
// TODO: git.merge(), git.pull(), git.status(), git.diff(), git.tag(), git.branch(), etc | ||
@@ -98,0 +120,0 @@ |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
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
1571782
14467
219