Socket
Socket
Sign inDemoInstall

dugite-extra

Package Overview
Dependencies
76
Maintainers
1
Versions
41
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 0.1.1 to 0.1.2

3

lib/command/apply.d.ts

@@ -0,2 +1,3 @@

import { IGitExecutionOptions } from '../core/git';
import { WorkingDirectoryFileChange } from '../model/status';
export declare function applyPatchToIndex(repositoryPath: string, file: WorkingDirectoryFileChange): Promise<void>;
export declare function applyPatchToIndex(repositoryPath: string, file: WorkingDirectoryFileChange, options?: IGitExecutionOptions): Promise<void>;
"use strict";
var __assign = (this && this.__assign) || Object.assign || function(t) {
for (var s, i = 1, n = arguments.length; i < n; i++) {
s = arguments[i];
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
t[p] = s[p];
}
return t;
};
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {

@@ -59,5 +67,5 @@ return new (P || (P = Promise))(function (resolve, reject) {

var patch_formatter_1 = require("../parser/patch-formatter");
function applyPatchToIndex(repositoryPath, file) {
function applyPatchToIndex(repositoryPath, file, options) {
return __awaiter(this, void 0, void 0, function () {
var oldFile, _a, info, _b, mode, oid, applyArgs, diff, patch;
var oldFile, _a, info, _b, mode, oid, applyArgs, diff, opts, patch;
return __generator(this, function (_c) {

@@ -90,3 +98,3 @@ switch (_c.label) {

// Add the old file blob to the index under the new name
return [4 /*yield*/, git_1.git(['update-index', '--add', '--cacheinfo', mode, oid, file.path], repositoryPath, 'applyPatchToIndex')];
return [4 /*yield*/, git_1.git(['update-index', '--add', '--cacheinfo', mode, oid, file.path], repositoryPath, 'applyPatchToIndex', options)];
case 3:

@@ -104,6 +112,11 @@ // Add the old file blob to the index under the new name

}
opts = {};
if (options) {
opts = __assign({}, options);
}
return [4 /*yield*/, patch_formatter_1.formatPatch(file, diff)];
case 6:
patch = _c.sent();
return [4 /*yield*/, git_1.git(applyArgs, repositoryPath, 'applyPatchToIndex', { stdin: patch })];
opts = __assign({}, opts, { stdin: patch });
return [4 /*yield*/, git_1.git(applyArgs, repositoryPath, 'applyPatchToIndex', options)];
case 7:

@@ -110,0 +123,0 @@ _c.sent();

@@ -0,13 +1,14 @@

import { IGitExecutionOptions } from '../core/git';
import { Branch } from '../model/branch';
export declare function listBranch(repositoryPath: string, type: 'current'): Promise<undefined | Branch>;
export declare function listBranch(repositoryPath: string, type: 'local' | 'remote' | 'all'): Promise<Branch[]>;
export declare function listBranch(repositoryPath: string, type: 'current', options?: IGitExecutionOptions): Promise<undefined | Branch>;
export declare function listBranch(repositoryPath: string, type: 'local' | 'remote' | 'all', options?: IGitExecutionOptions): Promise<Branch[]>;
export declare function createBranch(repositoryPath: string, name: string, options?: {
startPoint?: string;
}): Promise<void>;
export declare function renameBranch(repositoryPath: string, name: string, newName: string, options?: {
export declare function renameBranch(repositoryPath: string, name: string, newName: string, renameOptions?: {
force?: boolean;
}): Promise<void>;
export declare function deleteBranch(repositoryPath: string, name: string, options?: {
}, options?: IGitExecutionOptions): Promise<void>;
export declare function deleteBranch(repositoryPath: string, name: string, deleteOptions?: {
force?: boolean;
remote?: boolean;
}): Promise<void>;
}, options?: IGitExecutionOptions): Promise<void>;
"use strict";
var __assign = (this && this.__assign) || Object.assign || function(t) {
for (var s, i = 1, n = arguments.length; i < n; i++) {
s = arguments[i];
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
t[p] = s[p];
}
return t;
};
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {

@@ -74,5 +82,5 @@ return new (P || (P = Promise))(function (resolve, reject) {

].join('%00');
function listBranch(repositoryPath, type) {
function listBranch(repositoryPath, type, options) {
return __awaiter(this, void 0, void 0, function () {
var successExitCodes, result, exitCode, name, result;
var opts, result, exitCode, name, result;
return __generator(this, function (_a) {

@@ -82,4 +90,8 @@ switch (_a.label) {

if (!(type === 'current')) return [3 /*break*/, 3];
successExitCodes = new Set([0, 1, 128]);
return [4 /*yield*/, git_1.git(['rev-parse', '--abbrev-ref', 'HEAD'], repositoryPath, 'getCurrentBranch', { successExitCodes: successExitCodes })];
opts = {};
if (options) {
opts = __assign({}, opts);
}
opts = __assign({}, opts, { successExitCodes: new Set([0, 1, 128]) });
return [4 /*yield*/, git_1.git(['rev-parse', '--abbrev-ref', 'HEAD'], repositoryPath, 'getCurrentBranch', opts)];
case 1:

@@ -94,5 +106,5 @@ result = _a.sent();

name = result.stdout.trim().replace(/^heads\//, '');
return [4 /*yield*/, getBranches(repositoryPath, "refs/heads/" + name)];
return [4 /*yield*/, getBranches(repositoryPath, ["refs/heads/" + name], options)];
case 2: return [2 /*return*/, (_a.sent()).shift()];
case 3: return [4 /*yield*/, getBranches(repositoryPath)];
case 3: return [4 /*yield*/, getBranches(repositoryPath, [], options)];
case 4:

@@ -133,3 +145,3 @@ result = _a.sent();

exports.createBranch = createBranch;
function renameBranch(repositoryPath, name, newName, options) {
function renameBranch(repositoryPath, name, newName, renameOptions, options) {
return __awaiter(this, void 0, void 0, function () {

@@ -140,5 +152,5 @@ var force, args;

case 0:
force = options ? options.force : false;
force = renameOptions ? renameOptions.force : false;
args = ['branch', "" + (force ? '-M' : '-m'), name, newName];
return [4 /*yield*/, git_1.git(args, repositoryPath, 'renameBranch')];
return [4 /*yield*/, git_1.git(args, repositoryPath, 'renameBranch', options)];
case 1:

@@ -152,3 +164,3 @@ _a.sent();

exports.renameBranch = renameBranch;
function deleteBranch(repositoryPath, name, options) {
function deleteBranch(repositoryPath, name, deleteOptions, options) {
return __awaiter(this, void 0, void 0, function () {

@@ -159,7 +171,7 @@ var force, remote, args, branches, _a, branch;

case 0:
force = options ? options.force : false;
remote = options ? options.remote : false;
force = deleteOptions ? deleteOptions.force : false;
remote = deleteOptions ? deleteOptions.remote : false;
args = ['branch', "" + (force ? '-D' : '-d'), "" + name];
if (!remote) return [3 /*break*/, 2];
return [4 /*yield*/, getBranches(repositoryPath)];
return [4 /*yield*/, getBranches(repositoryPath, [], options)];
case 1:

@@ -173,3 +185,3 @@ _a = _b.sent();

branches = _a;
return [4 /*yield*/, git_1.git(args, repositoryPath, 'deleteBranch')];
return [4 /*yield*/, git_1.git(args, repositoryPath, 'deleteBranch', options)];
case 4:

@@ -181,3 +193,3 @@ _b.sent();

// Push the remote deletion.
return [4 /*yield*/, git_1.git(['push', branch.remote, ":" + branch.upstreamWithoutRemote], repositoryPath, 'deleteRemoteBranch')];
return [4 /*yield*/, git_1.git(['push', branch.remote, ":" + branch.upstreamWithoutRemote], repositoryPath, 'deleteRemoteBranch', options)];
case 5:

@@ -193,7 +205,3 @@ // Push the remote deletion.

exports.deleteBranch = deleteBranch;
function getBranches(repositoryPath) {
var prefixes = [];
for (var _i = 1; _i < arguments.length; _i++) {
prefixes[_i - 1] = arguments[_i];
}
function getBranches(repositoryPath, prefixes, options) {
return __awaiter(this, void 0, void 0, function () {

@@ -208,3 +216,3 @@ var args, result, names, lines;

args = __spread(['for-each-ref', "--format=" + forEachRefFormat, '--sort=-committerdate'], prefixes);
return [4 /*yield*/, git_1.git(args, repositoryPath, 'getBranches')];
return [4 /*yield*/, git_1.git(args, repositoryPath, 'getBranches', options)];
case 1:

@@ -211,0 +219,0 @@ result = _a.sent();

@@ -0,1 +1,2 @@

import { IGitExecutionOptions } from '../core/git';
import { ICheckoutProgress } from '../progress';

@@ -17,5 +18,5 @@ export declare type ProgressCallback = (progress: ICheckoutProgress) => void;

*/
export declare function checkoutBranch(repositoryPath: string, name: string, progressCallback?: ProgressCallback): Promise<void>;
export declare function checkoutBranch(repositoryPath: string, name: string, options?: IGitExecutionOptions, progressCallback?: ProgressCallback): Promise<void>;
/** Check out the paths at HEAD. */
export declare function checkoutPaths(repositoryPath: string, paths: string[]): Promise<void>;
export declare function checkoutPaths(repositoryPath: string, paths: string[], options?: IGitExecutionOptions): Promise<void>;
/**

@@ -30,2 +31,2 @@ * Reverts the state of the file to the specified one.

*/
export declare function checkout(repositoryPath: string, paths: string[], commitSHA?: string, merge?: boolean, force?: boolean): Promise<void>;
export declare function checkout(repositoryPath: string, paths: string[], commitSHA: string, merge?: boolean, force?: boolean, options?: IGitExecutionOptions): Promise<void>;
"use strict";
var __assign = (this && this.__assign) || Object.assign || function(t) {
for (var s, i = 1, n = arguments.length; i < n; i++) {
s = arguments[i];
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
t[p] = s[p];
}
return t;
};
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {

@@ -75,5 +83,5 @@ return new (P || (P = Promise))(function (resolve, reject) {

*/
function checkoutBranch(repositoryPath, name, progressCallback) {
function checkoutBranch(repositoryPath, name, options, progressCallback) {
return __awaiter(this, void 0, void 0, function () {
var processCallback, title_1, kind_1, targetBranch_1, args;
var processCallback, title_1, kind_1, targetBranch_1, args, opts;
return __generator(this, function (_a) {

@@ -100,3 +108,4 @@ switch (_a.label) {

: ['checkout', name, '--'];
return [4 /*yield*/, git_1.git(args, repositoryPath, 'checkoutBranch', { processCallback: processCallback })];
opts = __assign({}, options, { processCallback: processCallback });
return [4 /*yield*/, git_1.git(args, repositoryPath, 'checkoutBranch', opts)];
case 1:

@@ -111,7 +120,7 @@ _a.sent();

/** Check out the paths at HEAD. */
function checkoutPaths(repositoryPath, paths) {
function checkoutPaths(repositoryPath, paths, options) {
return __awaiter(this, void 0, void 0, function () {
return __generator(this, function (_a) {
switch (_a.label) {
case 0: return [4 /*yield*/, checkout(repositoryPath, paths, 'HEAD')];
case 0: return [4 /*yield*/, checkout(repositoryPath, paths, 'HEAD', false, false, options)];
case 1:

@@ -134,3 +143,3 @@ _a.sent();

*/
function checkout(repositoryPath, paths, commitSHA, merge, force) {
function checkout(repositoryPath, paths, commitSHA, merge, force, options) {
return __awaiter(this, void 0, void 0, function () {

@@ -153,3 +162,3 @@ var args;

args.push.apply(args, __spread(paths.map(function (p) { return Path.relative(repositoryPath, p); })));
return [4 /*yield*/, git_1.git(args, repositoryPath, 'checkoutPaths')];
return [4 /*yield*/, git_1.git(args, repositoryPath, 'checkoutPaths', options)];
case 1:

@@ -156,0 +165,0 @@ _a.sent();

@@ -0,1 +1,2 @@

import { IGitExecutionOptions } from '../core/git';
import { ICloneProgress } from '../progress';

@@ -21,3 +22,3 @@ /**

*
* @param options - Options specific to the clone operation, see the
* @param cloneOptions - Options specific to the clone operation, see the
* documentation for CloneOptions for more details.

@@ -32,2 +33,2 @@ *

*/
export declare function clone(url: string, path: string, options?: CloneOptions, progressCallback?: (progress: ICloneProgress) => void): Promise<void>;
export declare function clone(url: string, path: string, cloneOptions?: CloneOptions, options?: IGitExecutionOptions, progressCallback?: (progress: ICloneProgress) => void): Promise<void>;
"use strict";
var __assign = (this && this.__assign) || Object.assign || function(t) {
for (var s, i = 1, n = arguments.length; i < n; i++) {
s = arguments[i];
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
t[p] = s[p];
}
return t;
};
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {

@@ -50,3 +58,3 @@ return new (P || (P = Promise))(function (resolve, reject) {

*
* @param options - Options specific to the clone operation, see the
* @param cloneOptions - Options specific to the clone operation, see the
* documentation for CloneOptions for more details.

@@ -61,4 +69,4 @@ *

*/
function clone(url, path, options, progressCallback) {
if (options === void 0) { options = {}; }
function clone(url, path, cloneOptions, options, progressCallback) {
if (cloneOptions === void 0) { cloneOptions = {}; }
return __awaiter(this, void 0, void 0, function () {

@@ -73,2 +81,5 @@ var args, opts, title_1, kind_1;

opts = {};
if (options) {
opts = __assign({}, options);
}
if (progressCallback) {

@@ -88,4 +99,4 @@ args.push('--progress');

}
if (options.branch) {
args.push('-b', options.branch);
if (cloneOptions.branch) {
args.push('-b', cloneOptions.branch);
}

@@ -92,0 +103,0 @@ args.push('--', url, path);

@@ -1,1 +0,2 @@

export declare function createCommit(repositoryPath: string, message: string, signOff?: boolean, amend?: boolean): Promise<void>;
import { IGitExecutionOptions } from '../core/git';
export declare function createCommit(repositoryPath: string, message: string, signOff?: boolean, amend?: boolean, options?: IGitExecutionOptions): Promise<void>;
"use strict";
var __assign = (this && this.__assign) || Object.assign || function(t) {
for (var s, i = 1, n = arguments.length; i < n; i++) {
s = arguments[i];
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
t[p] = s[p];
}
return t;
};
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {

@@ -39,7 +47,7 @@ return new (P || (P = Promise))(function (resolve, reject) {

var git_1 = require("../core/git");
function createCommit(repositoryPath, message, signOff, amend) {
function createCommit(repositoryPath, message, signOff, amend, options) {
if (signOff === void 0) { signOff = false; }
if (amend === void 0) { amend = false; }
return __awaiter(this, void 0, void 0, function () {
var args, e_1, output, standardError, exitCode, error;
var args, opts, e_1, output, standardError, exitCode, error;
return __generator(this, function (_a) {

@@ -56,3 +64,8 @@ switch (_a.label) {

}
return [4 /*yield*/, git_1.git(args, repositoryPath, 'createCommit', { stdin: message })];
opts = {};
if (options) {
opts = __assign({}, options);
}
opts = __assign({}, opts, { stdin: message });
return [4 /*yield*/, git_1.git(args, repositoryPath, 'createCommit', opts)];
case 1:

@@ -59,0 +72,0 @@ _a.sent();

@@ -0,1 +1,2 @@

import { IGitExecutionOptions } from '../core/git';
import { WorkingDirectoryFileChange, FileChange } from '../model/status';

@@ -9,3 +10,3 @@ import { IRawDiff, IDiff, Image } from '../model/diff';

*/
export declare function getCommitDiff(repositoryPath: string, file: FileChange, commitish: string): Promise<IDiff>;
export declare function getCommitDiff(repositoryPath: string, file: FileChange, commitish: string, options?: IGitExecutionOptions): Promise<IDiff>;
/**

@@ -16,5 +17,5 @@ * Render the diff for a file within the repository working directory. The file will be

*/
export declare function getWorkingDirectoryDiff(repositoryPath: string, file: WorkingDirectoryFileChange): Promise<IDiff>;
export declare function getWorkingDirectoryDiff(repositoryPath: string, file: WorkingDirectoryFileChange, exec?: IGitExecutionOptions.ExecFunc): Promise<IDiff>;
export declare function convertDiff(repositoryPath: string, file: FileChange, diff: IRawDiff, commitish: string): Promise<IDiff>;
export declare function getBlobImage(repositoryPath: string, path: string, commitish: string): Promise<Image>;
export declare function getWorkingDirectoryImage(repositoryPath: string, file: FileChange): Promise<Image>;
"use strict";
var __assign = (this && this.__assign) || Object.assign || function(t) {
for (var s, i = 1, n = arguments.length; i < n; i++) {
s = arguments[i];
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
t[p] = s[p];
}
return t;
};
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {

@@ -55,5 +63,5 @@ return new (P || (P = Promise))(function (resolve, reject) {

*/
function getCommitDiff(repositoryPath, file, commitish) {
function getCommitDiff(repositoryPath, file, commitish, options) {
var args = ['log', commitish, '-m', '-1', '--first-parent', '--patch-with-raw', '-z', '--no-color', '--', file.path];
return git_1.git(args, repositoryPath, 'getCommitDiff')
return git_1.git(args, repositoryPath, 'getCommitDiff', options)
.then(function (value) { return diffFromRawDiffOutput(value.stdout); })

@@ -68,4 +76,4 @@ .then(function (diff) { return convertDiff(repositoryPath, file, diff, commitish); });

*/
function getWorkingDirectoryDiff(repositoryPath, file) {
var opts;
function getWorkingDirectoryDiff(repositoryPath, file, exec) {
var opts = {};
var args;

@@ -101,2 +109,5 @@ // `--no-ext-diff` should be provided wherever we invoke `git diff` so that any

}
if (exec) {
opts = __assign({}, opts, { exec: exec });
}
return git_1.git(args, repositoryPath, 'getWorkingDirectoryDiff', opts)

@@ -103,0 +114,0 @@ .then(function (value) { return diffFromRawDiffOutput(value.stdout); })

@@ -0,1 +1,2 @@

import { IGitExecutionOptions } from '../core/git';
import { IFetchProgress } from '../progress';

@@ -15,4 +16,4 @@ /**

*/
export declare function fetch(repositoryPath: string, remote: string, progressCallback?: (progress: IFetchProgress) => void): Promise<void>;
export declare function fetch(repositoryPath: string, remote: string, exec: IGitExecutionOptions.ExecFunc, progressCallback?: (progress: IFetchProgress) => void): Promise<void>;
/** Fetch a given refspec from the given remote. */
export declare function fetchRefspec(repositoryPath: string, remote: string, refspec: string): Promise<void>;
export declare function fetchRefspec(repositoryPath: string, remote: string, refspec: string, exec?: IGitExecutionOptions.ExecFunc): Promise<void>;
"use strict";
var __assign = (this && this.__assign) || Object.assign || function(t) {
for (var s, i = 1, n = arguments.length; i < n; i++) {
s = arguments[i];
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
t[p] = s[p];
}
return t;
};
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {

@@ -53,3 +61,3 @@ return new (P || (P = Promise))(function (resolve, reject) {

*/
function fetch(repositoryPath, remote, progressCallback) {
function fetch(repositoryPath, remote, exec, progressCallback) {
return __awaiter(this, void 0, void 0, function () {

@@ -63,2 +71,5 @@ var opts, title_1, kind_1, args;

};
if (exec) {
opts = __assign({}, opts, { exec: exec });
}
if (progressCallback) {

@@ -97,3 +108,3 @@ title_1 = "Fetching " + remote;

/** Fetch a given refspec from the given remote. */
function fetchRefspec(repositoryPath, remote, refspec) {
function fetchRefspec(repositoryPath, remote, refspec, exec) {
return __awaiter(this, void 0, void 0, function () {

@@ -107,2 +118,5 @@ var options, args;

};
if (exec) {
options = __assign({}, options, { exec: exec });
}
args = ['fetch', remote, refspec];

@@ -109,0 +123,0 @@ return [4 /*yield*/, git_1.git(args, repositoryPath, 'fetchRefspec', options)];

@@ -0,1 +1,2 @@

import { IGitExecutionOptions } from '../core/git';
/**

@@ -8,2 +9,2 @@ * Returns with an inverse chronologically ordered array of commit SHA for the given file. The first element is the `HEAD` commit.

*/
export declare function logCommitSHAs(repositoryPath: string, path: string, branch?: string): Promise<string[]>;
export declare function logCommitSHAs(repositoryPath: string, path: string, branch?: string, options?: IGitExecutionOptions): Promise<string[]>;

@@ -47,3 +47,3 @@ "use strict";

*/
function logCommitSHAs(repositoryPath, path, branch) {
function logCommitSHAs(repositoryPath, path, branch, options) {
return __awaiter(this, void 0, void 0, function () {

@@ -53,3 +53,3 @@ var result;

switch (_a.label) {
case 0: return [4 /*yield*/, git_1.git(['log', '--follow', '--pretty="%h"', Path.relative(repositoryPath, path)], repositoryPath, 'logCommitSHAs')];
case 0: return [4 /*yield*/, git_1.git(['log', '--follow', '--pretty="%h"', Path.relative(repositoryPath, path)], repositoryPath, 'logCommitSHAs', options)];
case 1:

@@ -56,0 +56,0 @@ result = _a.sent();

@@ -0,2 +1,3 @@

import { IGitExecutionOptions } from '../core/git';
/** Merge the named branch into the current branch. */
export declare function merge(repositoryPath: string, branch: string): Promise<void>;
export declare function merge(repositoryPath: string, branch: string, options?: IGitExecutionOptions): Promise<void>;

@@ -40,7 +40,7 @@ "use strict";

/** Merge the named branch into the current branch. */
function merge(repositoryPath, branch) {
function merge(repositoryPath, branch, options) {
return __awaiter(this, void 0, void 0, function () {
return __generator(this, function (_a) {
switch (_a.label) {
case 0: return [4 /*yield*/, git_1.git(['merge', branch], repositoryPath, 'merge')];
case 0: return [4 /*yield*/, git_1.git(['merge', branch], repositoryPath, 'merge', options)];
case 1:

@@ -47,0 +47,0 @@ _a.sent();

@@ -0,1 +1,2 @@

import { IGitExecutionOptions } from '../core/git';
import { IPullProgress } from '../progress';

@@ -18,2 +19,2 @@ /**

*/
export declare function pull(repositoryPath: string, remote: string, branch?: string, progressCallback?: (progress: IPullProgress) => void): Promise<void>;
export declare function pull(repositoryPath: string, remote: string, branch?: string, exec?: IGitExecutionOptions.ExecFunc, progressCallback?: (progress: IPullProgress) => void): Promise<void>;
"use strict";
var __assign = (this && this.__assign) || Object.assign || function(t) {
for (var s, i = 1, n = arguments.length; i < n; i++) {
s = arguments[i];
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
t[p] = s[p];
}
return t;
};
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {

@@ -56,3 +64,3 @@ return new (P || (P = Promise))(function (resolve, reject) {

*/
function pull(repositoryPath, remote, branch, progressCallback) {
function pull(repositoryPath, remote, branch, exec, progressCallback) {
return __awaiter(this, void 0, void 0, function () {

@@ -64,2 +72,5 @@ var opts, title_1, kind_1, args, result;

opts = {};
if (exec) {
opts = __assign({}, opts, { exec: exec });
}
if (progressCallback) {

@@ -66,0 +77,0 @@ title_1 = "Pulling " + remote;

@@ -0,1 +1,2 @@

import { IGitExecutionOptions } from '../core/git';
import { IPushProgress } from '../progress';

@@ -24,2 +25,2 @@ /**

*/
export declare function push(repositoryPath: string, remote: string, localBranch: string, remoteBranch?: string, progressCallback?: (progress: IPushProgress) => void): Promise<void>;
export declare function push(repositoryPath: string, remote: string, localBranch: string, remoteBranch?: string, exec?: IGitExecutionOptions.ExecFunc, progressCallback?: (progress: IPushProgress) => void): Promise<void>;
"use strict";
var __assign = (this && this.__assign) || Object.assign || function(t) {
for (var s, i = 1, n = arguments.length; i < n; i++) {
s = arguments[i];
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
t[p] = s[p];
}
return t;
};
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {

@@ -62,3 +70,3 @@ return new (P || (P = Promise))(function (resolve, reject) {

*/
function push(repositoryPath, remote, localBranch, remoteBranch, progressCallback) {
function push(repositoryPath, remote, localBranch, remoteBranch, exec, progressCallback) {
return __awaiter(this, void 0, void 0, function () {

@@ -75,2 +83,5 @@ var args, opts, title_1, kind_1, result;

opts = {};
if (exec) {
opts = __assign({}, opts, { exec: exec });
}
if (progressCallback) {

@@ -77,0 +88,0 @@ args.push('--progress');

@@ -0,1 +1,2 @@

import { IGitExecutionOptions } from '../core/git';
/** The reset modes which are supported. */

@@ -22,3 +23,3 @@ export declare const enum GitResetMode {

/** Reset with the mode to the ref. */
export declare function reset(repositoryPath: string, mode: GitResetMode, ref: string): Promise<void>;
export declare function reset(repositoryPath: string, mode: GitResetMode, ref: string, options?: IGitExecutionOptions): Promise<void>;
/**

@@ -39,4 +40,4 @@ * Updates the index with information from a particular tree for a given

*/
export declare function resetPaths(repositoryPath: string, mode: GitResetMode, ref: string, paths: string[]): Promise<void>;
export declare function resetPaths(repositoryPath: string, mode: GitResetMode, ref: string, paths: string[], options?: IGitExecutionOptions): Promise<void>;
/** Unstage all paths. */
export declare function unstageAll(repositoryPath: string): Promise<void>;
export declare function unstageAll(repositoryPath: string, options?: IGitExecutionOptions): Promise<void>;

@@ -72,3 +72,3 @@ "use strict";

/** Reset with the mode to the ref. */
function reset(repositoryPath, mode, ref) {
function reset(repositoryPath, mode, ref, options) {
return __awaiter(this, void 0, void 0, function () {

@@ -80,3 +80,3 @@ var modeFlag;

modeFlag = resetModeToFlag(mode);
return [4 /*yield*/, git_1.git(['reset', modeFlag, ref, '--'], repositoryPath, 'reset')];
return [4 /*yield*/, git_1.git(['reset', modeFlag, ref, '--'], repositoryPath, 'reset', options)];
case 1:

@@ -105,3 +105,3 @@ _a.sent();

*/
function resetPaths(repositoryPath, mode, ref, paths) {
function resetPaths(repositoryPath, mode, ref, paths, options) {
return __awaiter(this, void 0, void 0, function () {

@@ -116,3 +116,3 @@ var modeFlag;

modeFlag = resetModeToFlag(mode);
return [4 /*yield*/, git_1.git(__spread(['reset', modeFlag, ref, '--'], paths), repositoryPath, 'reset')];
return [4 /*yield*/, git_1.git(__spread(['reset', modeFlag, ref, '--'], paths), repositoryPath, 'reset', options)];
case 1:

@@ -127,7 +127,7 @@ _a.sent();

/** Unstage all paths. */
function unstageAll(repositoryPath) {
function unstageAll(repositoryPath, options) {
return __awaiter(this, void 0, void 0, function () {
return __generator(this, function (_a) {
switch (_a.label) {
case 0: return [4 /*yield*/, git_1.git(['reset', '--', '.'], repositoryPath, 'unstageAll')];
case 0: return [4 /*yield*/, git_1.git(['reset', '--', '.'], repositoryPath, 'unstageAll', options)];
case 1:

@@ -134,0 +134,0 @@ _a.sent();

/// <reference types="node" />
import { IGitExecutionOptions } from '../core/git';
/**

@@ -14,3 +15,3 @@ * Retrieve the text (UTF-8) contents of a file from the repository at a given

*/
export declare function getTextContents(repositoryPath: string, commitish: string, path: string): Promise<Buffer>;
export declare function getTextContents(repositoryPath: string, commitish: string, path: string, options?: IGitExecutionOptions): Promise<Buffer>;
/**

@@ -28,2 +29,2 @@ * Retrieve the binary contents of a blob from the repository at a given

*/
export declare function getBlobContents(repositoryPath: string, commitish: string, path: string): Promise<Buffer>;
export declare function getBlobContents(repositoryPath: string, commitish: string, path: string, options?: IGitExecutionOptions): Promise<Buffer>;
"use strict";
var __assign = (this && this.__assign) || Object.assign || function(t) {
for (var s, i = 1, n = arguments.length; i < n; i++) {
s = arguments[i];
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
t[p] = s[p];
}
return t;
};
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {

@@ -57,3 +65,4 @@ return new (P || (P = Promise))(function (resolve, reject) {

*/
function getTextContents(repositoryPath, commitish, path) {
function getTextContents(repositoryPath, commitish, path, options) {
if (options === void 0) { options = {}; }
return __awaiter(this, void 0, void 0, function () {

@@ -65,6 +74,3 @@ var args, opts, textContents;

args = ['show', commitish + ":" + normalizeSafe(path_1.relative(repositoryPath, path))];
opts = {
successExitCodes: successExitCodes,
processCallback: utf8Encoding,
};
opts = __assign({}, options, { successExitCodes: successExitCodes, processCallback: utf8Encoding });
return [4 /*yield*/, git_1.git(args, repositoryPath, 'getTextContents', opts)];

@@ -91,3 +97,4 @@ case 1:

*/
function getBlobContents(repositoryPath, commitish, path) {
function getBlobContents(repositoryPath, commitish, path, options) {
if (options === void 0) { options = {}; }
return __awaiter(this, void 0, void 0, function () {

@@ -99,6 +106,3 @@ var args, opts, blobContents;

args = ['show', commitish + ":" + path];
opts = {
successExitCodes: successExitCodes,
processCallback: binaryEncoding,
};
opts = __assign({}, options, { successExitCodes: successExitCodes, processCallback: binaryEncoding });
return [4 /*yield*/, git_1.git(args, repositoryPath, 'getBlobContents', opts)];

@@ -105,0 +109,0 @@ case 1:

@@ -0,1 +1,2 @@

import { IGitExecutionOptions } from '../core/git';
import { WorkingDirectoryFileChange } from '../model/status';

@@ -8,3 +9,3 @@ /**

*/
export declare function stage(repositoryPath: string, filePaths?: string | string[]): Promise<void>;
export declare function stage(repositoryPath: string, filePaths?: string | string[], options?: IGitExecutionOptions): Promise<void>;
/**

@@ -18,3 +19,3 @@ * Removes the given files from the index. In other words, unstages the files.

*/
export declare function unstage(repositoryPath: string, filePaths?: string | string[], treeish?: string, where?: 'index' | 'working-tree' | 'all'): Promise<void>;
export declare function unstage(repositoryPath: string, filePaths?: string | string[], treeish?: string, where?: 'index' | 'working-tree' | 'all', options?: IGitExecutionOptions): Promise<void>;
/**

@@ -25,2 +26,2 @@ * Returns with a list of all staged files from the repository.

*/
export declare function getStagedFiles(repositoryPath: string): Promise<WorkingDirectoryFileChange[]>;
export declare function getStagedFiles(repositoryPath: string, options?: IGitExecutionOptions): Promise<WorkingDirectoryFileChange[]>;

@@ -67,3 +67,3 @@ "use strict";

*/
function stage(repositoryPath, filePaths) {
function stage(repositoryPath, filePaths, options) {
return __awaiter(this, void 0, void 0, function () {

@@ -81,3 +81,3 @@ var paths;

}
return [4 /*yield*/, git_1.git(__spread(['add'], paths), repositoryPath, 'stage')];
return [4 /*yield*/, git_1.git(__spread(['add'], paths), repositoryPath, 'stage', options)];
case 1:

@@ -99,3 +99,6 @@ _a.sent();

*/
function unstage(repositoryPath, filePaths, treeish, where) {
function unstage(repositoryPath, filePaths, treeish, where, options) {
if (filePaths === void 0) { filePaths = []; }
if (treeish === void 0) { treeish = 'HEAD'; }
if (where === void 0) { where = 'all'; }
return __awaiter(this, void 0, void 0, function () {

@@ -136,3 +139,3 @@ var _treeish, _where, branch, args, paths;

args.push.apply(args, __spread(paths));
return [4 /*yield*/, git_1.git(args, repositoryPath, 'unstage')];
return [4 /*yield*/, git_1.git(args, repositoryPath, 'unstage', options)];
case 2:

@@ -151,3 +154,3 @@ _a.sent();

*/
function getStagedFiles(repositoryPath) {
function getStagedFiles(repositoryPath, options) {
return __awaiter(this, void 0, void 0, function () {

@@ -157,3 +160,3 @@ var status;

switch (_a.label) {
case 0: return [4 /*yield*/, status_1.getStatus(repositoryPath)];
case 0: return [4 /*yield*/, status_1.getStatus(repositoryPath, true, Number.MIN_SAFE_INTEGER, options)];
case 1:

@@ -160,0 +163,0 @@ status = _a.sent();

@@ -0,1 +1,2 @@

import { IGitExecutionOptions } from '../core/git';
import { IStatusResult } from '../model/status';

@@ -6,2 +7,2 @@ /**

*/
export declare function getStatus(repositoryPath: string, noOptionalLocks?: boolean, limit?: number): Promise<IStatusResult>;
export declare function getStatus(repositoryPath: string, noOptionalLocks?: boolean, limit?: number, options?: IGitExecutionOptions): Promise<IStatusResult>;

@@ -106,3 +106,3 @@ "use strict";

*/
function getStatus(repositoryPath, noOptionalLocks, limit) {
function getStatus(repositoryPath, noOptionalLocks, limit, options) {
if (noOptionalLocks === void 0) { noOptionalLocks = true; }

@@ -124,3 +124,3 @@ if (limit === void 0) { limit = Number.MAX_SAFE_INTEGER; }

_d.trys.push([1, 3, , 4]);
return [4 /*yield*/, git_1.gitVersion()];
return [4 /*yield*/, git_1.gitVersion(options)];
case 2:

@@ -163,3 +163,3 @@ version = _d.sent();

args.push('status', '--untracked-files=all', '--branch', '--porcelain=2', '-z');
return [4 /*yield*/, git_1.git(args, repositoryPath, 'getStatus')];
return [4 /*yield*/, git_1.git(args, repositoryPath, 'getStatus', options)];
case 7:

@@ -166,0 +166,0 @@ result = _d.sent();

@@ -19,3 +19,17 @@ import { IGitResult as DugiteResult, GitError as DugiteError, IGitExecutionOptions as DugiteExecutionOptions } from 'dugite';

readonly expectedErrors?: ReadonlySet<DugiteError>;
/**
* `path` is equivalent to `cwd`.
* If the `exec` function is set:
* - then this will be called instead of the `child_process.execFile`. Clients will **not** have access to the `stdin`.
* - then the `USE_LOCAL_GIT` must be set to `"true"`. Otherwise, an error will be thrown.
* - the all other properties defined by this option will be ignored except the `env` property.
*/
readonly exec?: IGitExecutionOptions.ExecFunc;
}
export declare namespace IGitExecutionOptions {
type ExecFunc = (args: string[], options: {
cwd: string;
stdin?: string;
}, callback: (error: Error | null, stdout: string, stderr: string) => void) => void;
}
/**

@@ -62,2 +76,2 @@ * The result of using `git`. This wraps dugite's results to provide

export declare function git(args: string[], path: string, name: string, options?: IGitExecutionOptions): Promise<IGitResult>;
export declare function gitVersion(): Promise<string>;
export declare function gitVersion(options?: IGitExecutionOptions): Promise<string>;

@@ -57,4 +57,6 @@ "use strict";

var fs = require("fs");
var Path = require("path");
var find_git_exec_1 = require("find-git-exec");
var dugite_1 = require("dugite");
var find_git_exec_2 = require("find-git-exec");
// tslint:disable:max-line-length

@@ -89,3 +91,82 @@ var __GIT_PATH__ = { gitDir: undefined, gitExecPath: undefined, searched: false };

exports.GitError = GitError;
function pathExists(path) {
if (path === undefined) {
return false;
}
try {
fs.accessSync(path, fs.F_OK);
return true;
}
catch (_a) {
return false;
}
}
/**
* `path` is the `pwd` where the Git command gets executed.
*/
function gitExternal(args, path, options) {
if (options.exec === undefined) {
throw new Error("options.exec must be defined.");
}
// XXX: this is just to keep the original code from here https://github.com/desktop/dugite/blob/master/lib/git-process.ts#L172-L227
var maxBuffer = options.maxBuffer ? options.maxBuffer : 10 * 1024 * 1024;
var exec = options.exec;
return new Promise(function (resolve, reject) {
var stdin = undefined;
if (options.stdin !== undefined) {
if (typeof options.stdin === 'string') {
stdin = options.stdin;
}
else {
stdin = options.stdin.toString('utf8');
}
}
exec(args, { cwd: path, stdin: stdin }, function (err, stdout, stderr) {
if (!err) {
resolve({ stdout: stdout, stderr: stderr, exitCode: 0 });
return;
}
var errWithCode = err;
var code = errWithCode.code;
// If the error's code is a string then it means the code isn't the
// process's exit code but rather an error coming from Node's bowels,
// e.g., ENOENT.
if (typeof code === 'string') {
if (code === 'ENOENT') {
var message = err.message;
if (pathExists(process.env.LOCAL_GIT_DIRECTORY) === false) {
message = 'Unable to find path to repository on disk.';
code = dugite_1.RepositoryDoesNotExistErrorCode;
}
else {
message = "Git could not be found at the expected path: '" + process.env.LOCAL_GIT_DIRECTORY + "'. This might be a problem with how the application is packaged, so confirm this folder hasn't been removed when packaging.";
code = dugite_1.GitNotFoundErrorCode;
}
var error = new Error(message);
error.name = err.name;
error.code = code;
reject(error);
}
else {
reject(err);
}
return;
}
if (typeof code === 'number') {
resolve({ stdout: stdout, stderr: stderr, exitCode: code });
return;
}
// Git has returned an output that couldn't fit in the specified buffer
// as we don't know how many bytes it requires, rethrow the error with
// details about what it was previously set to...
if (err.message === 'stdout maxBuffer exceeded') {
reject(new Error("The output from the command could not fit into the allocated stdout buffer. Set options.maxBuffer to a larger value than " + maxBuffer + " bytes"));
}
else {
reject(err);
}
});
});
}
/**
* Shell out to git with the given arguments, at the given path.

@@ -111,6 +192,18 @@ *

return __awaiter(this, void 0, void 0, function () {
var defaultOptions, opts, result, exitCode, gitError, acceptableExitCode, gitErrorDescription, gitResult, acceptableError;
var ssh, defaultOptions, opts, result, exitCode, gitError, acceptableExitCode, gitErrorDescription, gitResult, acceptableError;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
if (!(process.env.GIT_OVER_SSH_TEST === 'true')) return [3 /*break*/, 2];
return [4 /*yield*/, setupSsh()];
case 1:
ssh = _a.sent();
_a.label = 2;
case 2:
_a.trys.push([2, , 9, 10]);
if (options
&& options.exec
&& (typeof process.env.LOCAL_GIT_PATH === 'undefined')) {
throw new Error('LOCAL_GIT_PATH must be specified when using an exec function.');
}
defaultOptions = {

@@ -120,12 +213,20 @@ successExitCodes: new Set([0]),

};
return [4 /*yield*/, initGitEnv()];
case 1:
opts = __assign({}, defaultOptions, options);
result = void 0;
if (!(options && options.exec)) return [3 /*break*/, 4];
return [4 /*yield*/, gitExternal(args, path, options)];
case 3:
result = _a.sent();
return [3 /*break*/, 8];
case 4: return [4 /*yield*/, initGitEnv()];
case 5:
_a.sent();
return [4 /*yield*/, configureGitEnv()];
case 2:
case 6:
_a.sent();
opts = __assign({}, defaultOptions, options);
return [4 /*yield*/, dugite_1.GitProcess.exec(args, path, options)];
case 3:
case 7:
result = _a.sent();
_a.label = 8;
case 8:
exitCode = result.exitCode;

@@ -160,2 +261,8 @@ gitError = undefined;

throw new GitError(gitResult, args);
case 9:
if (ssh && 'dispose' in ssh && typeof ssh.dispose === 'function') {
ssh.dispose();
}
return [7 /*endfinally*/];
case 10: return [2 /*return*/];
}

@@ -166,16 +273,50 @@ });

exports.git = git;
function splitPath(path) {
function setupSsh(options) {
return __awaiter(this, void 0, void 0, function () {
var parts;
var ssh, gitPath, SSH, exec;
var _this = this;
return __generator(this, function (_a) {
parts = path.split(/(\/|\\)/);
if (!parts.length) {
return [2 /*return*/, parts];
switch (_a.label) {
case 0:
if (options === undefined) {
options = {};
}
return [4 /*yield*/, find_git_exec_2.default()];
case 1:
gitPath = _a.sent();
if (typeof process.env.LOCAL_GIT_PATH === 'undefined') {
process.env.LOCAL_GIT_PATH = gitPath.path;
}
SSH = require('node-ssh');
return [4 /*yield*/, new SSH().connect({
host: process.env.GIT_OVER_SSH_TEST_HOST || 'localhost',
username: process.env.GIT_OVER_SSH_TEST_USERNAME || 'username',
password: process.env.GIT_OVER_SSH_TEST_PASSWORD || 'password',
})];
case 2:
ssh = _a.sent();
exec = function (args, options, callback) { return __awaiter(_this, void 0, void 0, function () {
var _a, stdout, stderr, code, error;
return __generator(this, function (_b) {
switch (_b.label) {
case 0: return [4 /*yield*/, ssh.execCommand(gitPath.path + " " + args.join(' '), { cwd: options.cwd, stdin: options.stdin })];
case 1:
_a = _b.sent(), stdout = _a.stdout, stderr = _a.stderr, code = _a.code;
error = null;
if (code) {
error = new Error(stderr || 'Unknown error.');
error.code = code;
}
callback(error, stdout, stderr);
return [2 /*return*/];
}
});
}); };
options.exec = exec;
return [2 /*return*/, ssh];
}
// When the `path` starts with a slash, the the first part is empty string.
return [2 /*return*/, !parts[0].length ? parts.slice(1) : parts];
});
});
}
function gitVersion() {
function gitVersion(options) {
return __awaiter(this, void 0, void 0, function () {

@@ -191,3 +332,3 @@ var stdout;

_a.sent();
return [4 /*yield*/, dugite_1.GitProcess.exec(['--version'], '')];
return [4 /*yield*/, dugite_1.GitProcess.exec(['--version'], '', options)];
case 3:

@@ -203,30 +344,27 @@ stdout = ((_a.sent()) || '').stdout;

return __awaiter(this, void 0, void 0, function () {
var git_1, segments, gitDir, error_1;
var git_1, gitDir, error_1;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
if (!(process.env.USE_LOCAL_GIT === 'true' && !process.env.LOCAL_GIT_DIRECTORY && !process.env.GIT_EXEC_PATH && !__GIT_PATH__.searched)) return [3 /*break*/, 7];
if (!(process.env.USE_LOCAL_GIT === 'true' && !process.env.LOCAL_GIT_DIRECTORY && !process.env.GIT_EXEC_PATH && !__GIT_PATH__.searched)) return [3 /*break*/, 5];
console.log("'USE_LOCAL_GIT' is set to true. Trying to use local Git for 'dugite' execution.");
_a.label = 1;
case 1:
_a.trys.push([1, 5, 6, 7]);
_a.trys.push([1, 3, 4, 5]);
return [4 /*yield*/, find_git_exec_1.default()];
case 2:
git_1 = _a.sent();
if (!(git_1 && git_1.path && git_1.execPath)) return [3 /*break*/, 4];
return [4 /*yield*/, splitPath(git_1.path)];
if (git_1 && git_1.path && git_1.execPath) {
gitDir = Path.dirname(Path.dirname(git_1.path));
if (fs.existsSync(gitDir) && fs.existsSync(git_1.execPath)) {
__GIT_PATH__.gitDir = gitDir;
__GIT_PATH__.gitExecPath = git_1.execPath;
console.log("Using external Git executable. Git path: " + git_1.path + ". Git exec-path: " + git_1.execPath + ". [Version: " + git_1.version + "]");
}
else {
throw new Error("Cannot find local Git executable: " + git_1 + ".");
}
}
return [3 /*break*/, 5];
case 3:
segments = _a.sent();
gitDir = segments.slice(0, segments.length - 4).join('');
if (fs.existsSync(gitDir) && fs.existsSync(git_1.execPath)) {
__GIT_PATH__.gitDir = gitDir;
__GIT_PATH__.gitExecPath = git_1.execPath;
console.log("Using external Git executable. Git path: " + git_1.path + ". Git exec-path: " + git_1.execPath + ". [Version: " + git_1.version + "]");
}
else {
throw new Error("Cannot find local Git executable: " + git_1 + ".");
}
_a.label = 4;
case 4: return [3 /*break*/, 7];
case 5:
error_1 = _a.sent();

@@ -236,7 +374,7 @@ console.error("Cannot find local Git executable.", error_1);

__GIT_PATH__.gitExecPath = undefined;
return [3 /*break*/, 7];
case 6:
return [3 /*break*/, 5];
case 4:
__GIT_PATH__.searched = true;
return [7 /*endfinally*/];
case 7: return [2 /*return*/];
case 5: return [2 /*return*/];
}

@@ -243,0 +381,0 @@ });

{
"name": "dugite-extra",
"version": "0.1.1",
"version": "0.1.2",
"description": "High-level Git commands for dugite.",

@@ -12,2 +12,3 @@ "main": "lib/index",

"test:embedded": "mocha --opts ./mocha.opts src/**/*.spec.ts",
"test:ssh": "cross-env GIT_OVER_SSH_TEST=true mocha --opts ./mocha.opts src/**/*.spec.ts",
"test:external": "cross-env USE_LOCAL_GIT=true mocha --opts ./mocha.opts src/**/*.spec.ts",

@@ -36,3 +37,3 @@ "test:embedded:watch": "mocha -w --opts ./mocha.opts src/**/*.spec.ts",

"byline": "^5.0.0",
"dugite": "1.52.0",
"dugite": "1.74.0",
"find-git-exec": "0.0.1-alpha.2",

@@ -52,2 +53,3 @@ "upath": "^1.0.0"

"mocha": "^3.4.2",
"node-ssh": "^5.1.2",
"rimraf": "^2.6.1",

@@ -54,0 +56,0 @@ "temp": "^0.8.3",

@@ -1,2 +0,2 @@

import { git } from '../core/git'
import { git, IGitExecutionOptions } from '../core/git'
import { AppFileStatus, WorkingDirectoryFileChange } from '../model/status'

@@ -7,3 +7,3 @@ import { DiffType } from '../model/diff'

export async function applyPatchToIndex(repositoryPath: string, file: WorkingDirectoryFileChange): Promise<void> {
export async function applyPatchToIndex(repositoryPath: string, file: WorkingDirectoryFileChange, options?: IGitExecutionOptions): Promise<void> {

@@ -31,3 +31,3 @@ // If the file was a rename we have to recreate that rename since we've

// Add the old file blob to the index under the new name
await git(['update-index', '--add', '--cacheinfo', mode, oid, file.path], repositoryPath, 'applyPatchToIndex');
await git(['update-index', '--add', '--cacheinfo', mode, oid, file.path], repositoryPath, 'applyPatchToIndex', options);
}

@@ -42,6 +42,15 @@

}
let opts = {};
if (options) {
opts = {
...options
};
}
const patch = await formatPatch(file, diff);
await git(applyArgs, repositoryPath, 'applyPatchToIndex', { stdin: patch });
opts = {
...opts,
stdin: patch
}
await git(applyArgs, repositoryPath, 'applyPatchToIndex', options);
}

@@ -1,2 +0,2 @@

import { git } from '../core/git';
import { git, IGitExecutionOptions } from '../core/git';
import { Branch, BranchType } from '../model/branch';

@@ -19,8 +19,17 @@ import { CommitIdentity } from '../model/commit-identity';

export async function listBranch(repositoryPath: string, type: 'current'): Promise<undefined | Branch>;
export async function listBranch(repositoryPath: string, type: 'local' | 'remote' | 'all'): Promise<Branch[]>;
export async function listBranch(repositoryPath: string, type: 'current' | 'local' | 'remote' | 'all'): Promise<undefined | Branch | Branch[]> {
export async function listBranch(repositoryPath: string, type: 'current', options?: IGitExecutionOptions): Promise<undefined | Branch>;
export async function listBranch(repositoryPath: string, type: 'local' | 'remote' | 'all', options?: IGitExecutionOptions): Promise<Branch[]>;
export async function listBranch(repositoryPath: string, type: 'current' | 'local' | 'remote' | 'all', options?: IGitExecutionOptions): Promise<undefined | Branch | Branch[]> {
if (type === 'current') {
const successExitCodes = new Set([0, 1, 128]);
const result = await git(['rev-parse', '--abbrev-ref', 'HEAD'], repositoryPath, 'getCurrentBranch', { successExitCodes });
let opts = {};
if (options) {
opts = {
...opts
};
}
opts = {
...opts,
successExitCodes: new Set([0, 1, 128])
}
const result = await git(['rev-parse', '--abbrev-ref', 'HEAD'], repositoryPath, 'getCurrentBranch', opts);
const { exitCode } = result;

@@ -34,5 +43,5 @@ // If the error code 1 is returned if no upstream.

const name = result.stdout.trim().replace(/^heads\//, '');
return (await getBranches(repositoryPath, `refs/heads/${name}`)).shift();
return (await getBranches(repositoryPath, [`refs/heads/${name}`], options)).shift();
} else {
const result = await getBranches(repositoryPath);
const result = await getBranches(repositoryPath, [], options);
switch (type) {

@@ -56,14 +65,14 @@ case 'local': return result.filter(branch => branch.type === BranchType.Local);

export async function renameBranch(repositoryPath: string, name: string, newName: string, options?: { force?: boolean }): Promise<void> {
const force = options ? options.force : false;
export async function renameBranch(repositoryPath: string, name: string, newName: string, renameOptions?: { force?: boolean }, options?: IGitExecutionOptions): Promise<void> {
const force = renameOptions ? renameOptions.force : false;
const args = ['branch', `${force ? '-M' : '-m'}`, name, newName];
await git(args, repositoryPath, 'renameBranch');
await git(args, repositoryPath, 'renameBranch', options);
}
export async function deleteBranch(repositoryPath: string, name: string, options?: { force?: boolean, remote?: boolean }): Promise<void> {
const force = options ? options.force : false;
const remote = options ? options.remote : false;
export async function deleteBranch(repositoryPath: string, name: string, deleteOptions?: { force?: boolean, remote?: boolean }, options?: IGitExecutionOptions): Promise<void> {
const force = deleteOptions ? deleteOptions.force : false;
const remote = deleteOptions ? deleteOptions.remote : false;
const args = ['branch', `${force ? '-D' : '-d'}`, `${name}`];
const branches = remote ? await getBranches(repositoryPath) : [];
await git(args, repositoryPath, 'deleteBranch');
const branches = remote ? await getBranches(repositoryPath, [], options) : [];
await git(args, repositoryPath, 'deleteBranch', options);
if (remote && branches && branches.length) {

@@ -73,3 +82,3 @@ const branch = branches.find(branch => branch.name.replace(/^heads\//, '') === name);

// Push the remote deletion.
await git(['push', branch.remote, `:${branch.upstreamWithoutRemote}`], repositoryPath, 'deleteRemoteBranch');
await git(['push', branch.remote, `:${branch.upstreamWithoutRemote}`], repositoryPath, 'deleteRemoteBranch', options);
}

@@ -79,3 +88,3 @@ }

async function getBranches(repositoryPath: string, ...prefixes: string[]): Promise<Branch[]> {
async function getBranches(repositoryPath: string, prefixes: string[], options?: IGitExecutionOptions): Promise<Branch[]> {
if (!prefixes || !prefixes.length) {

@@ -86,3 +95,3 @@ prefixes = ['refs/heads', 'refs/remotes'];

const args = ['for-each-ref', `--format=${forEachRefFormat}`, '--sort=-committerdate', ...prefixes];
const result = await git(args, repositoryPath, 'getBranches');
const result = await git(args, repositoryPath, 'getBranches', options);
const names = result.stdout;

@@ -89,0 +98,0 @@ const lines = names.split(delimiterString);

import * as Path from 'path';
import { git } from '../core/git'
import { git, IGitExecutionOptions } from '../core/git'
import { ChildProcess } from 'child_process'

@@ -23,3 +23,3 @@ import { ICheckoutProgress, CheckoutProgressParser, progressProcessCallback } from '../progress'

*/
export async function checkoutBranch(repositoryPath: string, name: string, progressCallback?: ProgressCallback): Promise<void> {
export async function checkoutBranch(repositoryPath: string, name: string, options?: IGitExecutionOptions, progressCallback?: ProgressCallback): Promise<void> {
let processCallback: ProcessCallback | undefined = undefined

@@ -51,8 +51,12 @@ if (progressCallback) {

await git(args, repositoryPath, 'checkoutBranch', { processCallback });
const opts = {
...options,
processCallback
}
await git(args, repositoryPath, 'checkoutBranch', opts);
}
/** Check out the paths at HEAD. */
export async function checkoutPaths(repositoryPath: string, paths: string[]): Promise<void> {
await checkout(repositoryPath, paths, 'HEAD');
export async function checkoutPaths(repositoryPath: string, paths: string[], options?: IGitExecutionOptions): Promise<void> {
await checkout(repositoryPath, paths, 'HEAD', false, false, options);
}

@@ -69,3 +73,3 @@

*/
export async function checkout(repositoryPath: string, paths: string[], commitSHA?: string, merge?: boolean, force?: boolean): Promise<void> {
export async function checkout(repositoryPath: string, paths: string[], commitSHA: string, merge?: boolean, force?: boolean, options?: IGitExecutionOptions): Promise<void> {
const args = ['checkout'];

@@ -83,3 +87,3 @@ if (commitSHA) {

args.push(...paths.map(p => Path.relative(repositoryPath, p)));
await git(args, repositoryPath, 'checkoutPaths');
await git(args, repositoryPath, 'checkoutPaths', options);
}

@@ -26,3 +26,3 @@ import { git, IGitExecutionOptions } from '../core/git'

*
* @param options - Options specific to the clone operation, see the
* @param cloneOptions - Options specific to the clone operation, see the
* documentation for CloneOptions for more details.

@@ -37,3 +37,8 @@ *

*/
export async function clone(url: string, path: string, options: CloneOptions = {}, progressCallback?: (progress: ICloneProgress) => void): Promise<void> {
export async function clone(
url: string,
path: string,
cloneOptions: CloneOptions = {},
options?: IGitExecutionOptions,
progressCallback?: (progress: ICloneProgress) => void): Promise<void> {

@@ -45,2 +50,7 @@ const args = [

let opts: IGitExecutionOptions = {};
if (options) {
opts = {
...options
};
}

@@ -66,4 +76,4 @@ if (progressCallback) {

if (options.branch) {
args.push('-b', options.branch);
if (cloneOptions.branch) {
args.push('-b', cloneOptions.branch);
}

@@ -70,0 +80,0 @@

@@ -1,4 +0,4 @@

import { git, GitError } from '../core/git'
import { git, GitError, IGitExecutionOptions } from '../core/git'
export async function createCommit(repositoryPath: string, message: string, signOff: boolean = false, amend: boolean = false): Promise<void> {
export async function createCommit(repositoryPath: string, message: string, signOff: boolean = false, amend: boolean = false, options?: IGitExecutionOptions): Promise<void> {
try {

@@ -12,3 +12,13 @@ const args = ['commit', '-F', '-'];

}
await git(args, repositoryPath, 'createCommit', { stdin: message });
let opts = {};
if (options) {
opts = {
...options
}
}
opts = {
...opts,
stdin: message
}
await git(args, repositoryPath, 'createCommit', opts);
} catch (e) {

@@ -15,0 +25,0 @@ // Commit failures could come from a pre-commit hook rejection. So display

@@ -20,5 +20,5 @@ import * as Path from 'path';

*/
export function getCommitDiff(repositoryPath: string, file: FileChange, commitish: string): Promise<IDiff> {
export function getCommitDiff(repositoryPath: string, file: FileChange, commitish: string, options?: IGitExecutionOptions): Promise<IDiff> {
const args = ['log', commitish, '-m', '-1', '--first-parent', '--patch-with-raw', '-z', '--no-color', '--', file.path];
return git(args, repositoryPath, 'getCommitDiff')
return git(args, repositoryPath, 'getCommitDiff', options)
.then(value => diffFromRawDiffOutput(value.stdout))

@@ -33,5 +33,5 @@ .then(diff => convertDiff(repositoryPath, file, diff, commitish));

*/
export function getWorkingDirectoryDiff(repositoryPath: string, file: WorkingDirectoryFileChange): Promise<IDiff> {
export function getWorkingDirectoryDiff(repositoryPath: string, file: WorkingDirectoryFileChange, exec?: IGitExecutionOptions.ExecFunc): Promise<IDiff> {
let opts: IGitExecutionOptions | undefined;
let opts: IGitExecutionOptions | undefined = {};
let args: string[];

@@ -68,2 +68,9 @@

if (exec) {
opts = {
...opts,
exec
}
}
return git(args, repositoryPath, 'getWorkingDirectoryDiff', opts)

@@ -70,0 +77,0 @@ .then(value => diffFromRawDiffOutput(value.stdout))

@@ -18,6 +18,12 @@ import { git, IGitExecutionOptions } from '../core/git';

*/
export async function fetch(repositoryPath: string, remote: string, progressCallback?: (progress: IFetchProgress) => void): Promise<void> {
export async function fetch(repositoryPath: string, remote: string, exec: IGitExecutionOptions.ExecFunc, progressCallback?: (progress: IFetchProgress) => void): Promise<void> {
let opts: IGitExecutionOptions = {
successExitCodes: new Set([0]),
};
if (exec) {
opts = {
...opts,
exec
};
}

@@ -61,8 +67,14 @@ if (progressCallback) {

/** Fetch a given refspec from the given remote. */
export async function fetchRefspec(repositoryPath: string, remote: string, refspec: string): Promise<void> {
const options = {
export async function fetchRefspec(repositoryPath: string, remote: string, refspec: string, exec?: IGitExecutionOptions.ExecFunc): Promise<void> {
let options: IGitExecutionOptions = {
successExitCodes: new Set([0, 128])
};
if (exec) {
options = {
...options,
exec
};
}
const args = ['fetch', remote, refspec];
await git(args, repositoryPath, 'fetchRefspec', options);
}
import * as Path from 'path';
import { git } from '../core/git';
import { git, IGitExecutionOptions } from '../core/git';

@@ -11,5 +11,5 @@ /**

*/
export async function logCommitSHAs(repositoryPath: string, path: string, branch?: string): Promise<string[]> {
const result = await git(['log', '--follow', '--pretty="%h"', Path.relative(repositoryPath, path)], repositoryPath, 'logCommitSHAs');
export async function logCommitSHAs(repositoryPath: string, path: string, branch?: string, options?: IGitExecutionOptions): Promise<string[]> {
const result = await git(['log', '--follow', '--pretty="%h"', Path.relative(repositoryPath, path)], repositoryPath, 'logCommitSHAs', options);
return result.stdout.trim().split('\n').map(sh => sh.replace(/^"(.*)"$/, '$1'));
}

@@ -1,6 +0,6 @@

import { git } from '../core/git';
import { git, IGitExecutionOptions } from '../core/git';
/** Merge the named branch into the current branch. */
export async function merge(repositoryPath: string, branch: string): Promise<void> {
await git(['merge', branch], repositoryPath, 'merge');
export async function merge(repositoryPath: string, branch: string, options?: IGitExecutionOptions): Promise<void> {
await git(['merge', branch], repositoryPath, 'merge', options);
}

@@ -21,4 +21,17 @@ import { git, GitError, IGitExecutionOptions } from '../core/git';

*/
export async function pull(repositoryPath: string, remote: string, branch?: string, progressCallback?: (progress: IPullProgress) => void): Promise<void> {
export async function pull(
repositoryPath: string,
remote: string,
branch?: string,
exec?: IGitExecutionOptions.ExecFunc,
progressCallback?: (progress: IPullProgress) => void): Promise<void> {
let opts: IGitExecutionOptions = {};
if (exec) {
opts = {
...opts,
exec
};
}
if (progressCallback) {

@@ -25,0 +38,0 @@ const title = `Pulling ${remote}`;

@@ -27,3 +27,3 @@ import { git, IGitExecutionOptions, GitError } from '../core/git';

export async function push(repositoryPath: string, remote: string, localBranch: string, remoteBranch?: string,
progressCallback?: (progress: IPushProgress) => void): Promise<void> {
exec?: IGitExecutionOptions.ExecFunc, progressCallback?: (progress: IPushProgress) => void): Promise<void> {

@@ -37,2 +37,8 @@ const args = [

let opts: IGitExecutionOptions = {};
if (exec) {
opts = {
...opts,
exec
};
}

@@ -39,0 +45,0 @@ if (progressCallback) {

@@ -1,2 +0,2 @@

import { git } from '../core/git';
import { git, IGitExecutionOptions } from '../core/git';

@@ -39,5 +39,5 @@ /** The reset modes which are supported. */

/** Reset with the mode to the ref. */
export async function reset(repositoryPath: string, mode: GitResetMode, ref: string): Promise<void> {
export async function reset(repositoryPath: string, mode: GitResetMode, ref: string, options?: IGitExecutionOptions): Promise<void> {
const modeFlag = resetModeToFlag(mode);
await git(['reset', modeFlag, ref, '--'], repositoryPath, 'reset');
await git(['reset', modeFlag, ref, '--'], repositoryPath, 'reset', options);
}

@@ -60,3 +60,3 @@

*/
export async function resetPaths(repositoryPath: string, mode: GitResetMode, ref: string, paths: string[]): Promise<void> {
export async function resetPaths(repositoryPath: string, mode: GitResetMode, ref: string, paths: string[], options?: IGitExecutionOptions): Promise<void> {
if (!paths.length) {

@@ -67,8 +67,8 @@ return;

const modeFlag = resetModeToFlag(mode);
await git(['reset', modeFlag, ref, '--', ...paths], repositoryPath, 'reset');
await git(['reset', modeFlag, ref, '--', ...paths], repositoryPath, 'reset', options);
}
/** Unstage all paths. */
export async function unstageAll(repositoryPath: string): Promise<void> {
await git(['reset', '--', '.'], repositoryPath, 'unstageAll');
export async function unstageAll(repositoryPath: string, options?: IGitExecutionOptions): Promise<void> {
await git(['reset', '--', '.'], repositoryPath, 'unstageAll', options);
}
import { relative } from 'path';
import { ChildProcess } from 'child_process';
import { git } from '../core/git';
import { git, IGitExecutionOptions } from '../core/git';

@@ -24,5 +24,6 @@ const upath = require('upath');

*/
export async function getTextContents(repositoryPath: string, commitish: string, path: string): Promise<Buffer> {
export async function getTextContents(repositoryPath: string, commitish: string, path: string, options: IGitExecutionOptions = {}): Promise<Buffer> {
const args = ['show', `${commitish}:${normalizeSafe(relative(repositoryPath, path))}`];
const opts = {
...options,
successExitCodes,

@@ -47,5 +48,6 @@ processCallback: utf8Encoding,

*/
export async function getBlobContents(repositoryPath: string, commitish: string, path: string): Promise<Buffer> {
export async function getBlobContents(repositoryPath: string, commitish: string, path: string, options: IGitExecutionOptions = {}): Promise<Buffer> {
const args = ['show', `${commitish}:${path}`];
const opts = {
...options,
successExitCodes,

@@ -52,0 +54,0 @@ processCallback: binaryEncoding,

import * as path from 'path';
import { git } from '../core/git';
import { git, IGitExecutionOptions } from '../core/git';
import { getStatus } from './status';

@@ -12,3 +12,3 @@ import { WorkingDirectoryFileChange } from '../model/status';

*/
export async function stage(repositoryPath: string, filePaths?: string | string[]): Promise<void> {
export async function stage(repositoryPath: string, filePaths?: string | string[], options?: IGitExecutionOptions): Promise<void> {
const paths: string[] = [];

@@ -20,3 +20,3 @@ if (filePaths === undefined || (Array.isArray(filePaths) && filePaths.length === 0)) {

}
await git(['add', ...paths], repositoryPath, 'stage');
await git(['add', ...paths], repositoryPath, 'stage', options);
}

@@ -32,3 +32,9 @@

*/
export async function unstage(repositoryPath: string, filePaths?: string | string[], treeish?: string, where?: 'index' | 'working-tree' | 'all'): Promise<void> {
export async function unstage(
repositoryPath: string,
filePaths: string | string[] = [],
treeish: string = 'HEAD',
where: 'index' | 'working-tree' | 'all' = 'all',
options?: IGitExecutionOptions): Promise<void> {
const _treeish = treeish || 'HEAD';

@@ -59,3 +65,3 @@ const _where = where || 'all';

args.push(...paths);
await git(args, repositoryPath, 'unstage');
await git(args, repositoryPath, 'unstage', options);
}

@@ -68,5 +74,5 @@

*/
export async function getStagedFiles(repositoryPath: string): Promise<WorkingDirectoryFileChange[]> {
const status = await getStatus(repositoryPath);
export async function getStagedFiles(repositoryPath: string, options?: IGitExecutionOptions): Promise<WorkingDirectoryFileChange[]> {
const status = await getStatus(repositoryPath, true, Number.MIN_SAFE_INTEGER, options);
return status.workingDirectory.files.filter(f => f.staged);
}

@@ -1,2 +0,2 @@

import { git, gitVersion } from '../core/git';
import { git, gitVersion, IGitExecutionOptions } from '../core/git';
import { parsePorcelainStatus, mapStatus } from '../parser/status-parser';

@@ -44,3 +44,8 @@ import { DiffSelectionType, DiffSelection } from '../model/diff';

*/
export async function getStatus(repositoryPath: string, noOptionalLocks: boolean = true, limit: number = Number.MAX_SAFE_INTEGER): Promise<IStatusResult> {
export async function getStatus(
repositoryPath: string,
noOptionalLocks: boolean = true,
limit: number = Number.MAX_SAFE_INTEGER,
options?: IGitExecutionOptions): Promise<IStatusResult> {
const args: string[] = [];

@@ -54,3 +59,3 @@ if (noOptionalLocks) {

try {
version = await gitVersion();
version = await gitVersion(options);
} catch (e) {

@@ -87,3 +92,4 @@ console.error('Error ocurred when determining the Git version.', e);

repositoryPath,
'getStatus'
'getStatus',
options
);

@@ -90,0 +96,0 @@

import * as fs from 'fs';
import * as Path from 'path';
import findGit from 'find-git-exec';
import { GitProcess, IGitResult as DugiteResult, GitError as DugiteError, IGitExecutionOptions as DugiteExecutionOptions } from 'dugite';
import {
GitProcess,
IGitResult as DugiteResult,
GitError as DugiteError,
IGitExecutionOptions as DugiteExecutionOptions,
RepositoryDoesNotExistErrorCode,
GitNotFoundErrorCode
} from 'dugite';
import findGitExec from 'find-git-exec';

@@ -26,4 +35,17 @@ // tslint:disable:max-line-length

readonly expectedErrors?: ReadonlySet<DugiteError>
/**
* `path` is equivalent to `cwd`.
* If the `exec` function is set:
* - then this will be called instead of the `child_process.execFile`. Clients will **not** have access to the `stdin`.
* - then the `USE_LOCAL_GIT` must be set to `"true"`. Otherwise, an error will be thrown.
* - the all other properties defined by this option will be ignored except the `env` property.
*/
readonly exec?: IGitExecutionOptions.ExecFunc;
}
export namespace IGitExecutionOptions {
export type ExecFunc = (args: string[], options: { cwd: string, stdin?: string }, callback: (error: Error | null, stdout: string, stderr: string) => void) => void;
}
/**

@@ -76,3 +98,94 @@ * The result of using `git`. This wraps dugite's results to provide

function pathExists(path?: string): Boolean {
if (path === undefined) {
return false;
}
try {
fs.accessSync(path, (fs as any).F_OK)
return true
} catch {
return false
}
}
/**
* `path` is the `pwd` where the Git command gets executed.
*/
function gitExternal(args: string[], path: string, options: IGitExecutionOptions): Promise<DugiteResult> {
if (options.exec === undefined) {
throw new Error(`options.exec must be defined.`);
}
// XXX: this is just to keep the original code from here https://github.com/desktop/dugite/blob/master/lib/git-process.ts#L172-L227
const maxBuffer = options.maxBuffer ? options.maxBuffer : 10 * 1024 * 1024;
const { exec } = options;
return new Promise<DugiteResult>((resolve, reject) => {
let stdin: string | undefined = undefined;
if (options.stdin !== undefined) {
if (typeof options.stdin === 'string') {
stdin = options.stdin;
} else {
stdin = options.stdin.toString('utf8');
}
}
exec(args, { cwd: path, stdin }, (err: Error | null, stdout: string, stderr: string) => {
if (!err) {
resolve({ stdout, stderr, exitCode: 0 })
return
}
const errWithCode = err as (Error & { code: number | string | undefined })
let code = errWithCode.code
// If the error's code is a string then it means the code isn't the
// process's exit code but rather an error coming from Node's bowels,
// e.g., ENOENT.
if (typeof code === 'string') {
if (code === 'ENOENT') {
let message = err.message
if (pathExists(process.env.LOCAL_GIT_DIRECTORY) === false) {
message = 'Unable to find path to repository on disk.'
code = RepositoryDoesNotExistErrorCode
} else {
message = `Git could not be found at the expected path: '${
process.env.LOCAL_GIT_DIRECTORY
}'. This might be a problem with how the application is packaged, so confirm this folder hasn't been removed when packaging.`
code = GitNotFoundErrorCode
}
const error = new Error(message) as (Error & { code: number | string | undefined })
error.name = err.name
error.code = code
reject(error)
} else {
reject(err)
}
return
}
if (typeof code === 'number') {
resolve({ stdout, stderr, exitCode: code })
return
}
// Git has returned an output that couldn't fit in the specified buffer
// as we don't know how many bytes it requires, rethrow the error with
// details about what it was previously set to...
if (err.message === 'stdout maxBuffer exceeded') {
reject(
new Error(
`The output from the command could not fit into the allocated stdout buffer. Set options.maxBuffer to a larger value than ${
maxBuffer
} bytes`
)
)
} else {
reject(err)
}
});
});
}
/**
* Shell out to git with the given arguments, at the given path.

@@ -98,64 +211,108 @@ *

let defaultOptions: IGitExecutionOptions = {
successExitCodes: new Set([0]),
expectedErrors: new Set(),
// This is only for testing everything Git related over SSH with a naive way.
// Do not ever use this in production. The SSH dependency is not available in production mode.
let ssh: any;
if (process.env.GIT_OVER_SSH_TEST === 'true') {
ssh = await setupSsh();
}
await initGitEnv();
await configureGitEnv();
try {
if (
options
&& options.exec
&& (typeof process.env.LOCAL_GIT_PATH === 'undefined')) {
throw new Error('LOCAL_GIT_PATH must be specified when using an exec function.');
}
const opts = { ...defaultOptions, ...options }
const result = await GitProcess.exec(args, path, options);
const exitCode = result.exitCode
const defaultOptions: IGitExecutionOptions = {
successExitCodes: new Set([0]),
expectedErrors: new Set(),
}
let gitError: DugiteError | undefined = undefined
const acceptableExitCode = opts.successExitCodes ? opts.successExitCodes.has(exitCode) : false
if (!acceptableExitCode) {
gitError = GitProcess.parseError(result.stderr) || undefined
if (!gitError) {
gitError = GitProcess.parseError(result.stdout) || undefined
const opts = { ...defaultOptions, ...options }
let result: DugiteResult;
if (options && options.exec) {
result = await gitExternal(args, path, options);
} else {
await initGitEnv();
await configureGitEnv();
result = await GitProcess.exec(args, path, options);
}
}
const gitErrorDescription = gitError ? getDescriptionForError(gitError) : undefined
const gitResult = { ...result, gitError, gitErrorDescription }
const exitCode = result.exitCode
let acceptableError = true
if (gitError && opts.expectedErrors) {
acceptableError = opts.expectedErrors.has(gitError)
}
let gitError: DugiteError | undefined = undefined
const acceptableExitCode = opts.successExitCodes ? opts.successExitCodes.has(exitCode) : false
if (!acceptableExitCode) {
gitError = GitProcess.parseError(result.stderr) || undefined
if (!gitError) {
gitError = GitProcess.parseError(result.stdout) || undefined
}
}
if ((gitError && acceptableError) || acceptableExitCode) {
return gitResult
}
const gitErrorDescription = gitError ? getDescriptionForError(gitError) : undefined
const gitResult = { ...result, gitError, gitErrorDescription }
console.error(`The command \`git ${args.join(' ')}\` exited with an unexpected code: ${exitCode}. The caller should either handle this error, or expect that exit code.`)
if (result.stdout.length) {
console.error(result.stdout)
}
let acceptableError = true
if (gitError && opts.expectedErrors) {
acceptableError = opts.expectedErrors.has(gitError)
}
if (result.stderr.length) {
console.error(result.stderr)
}
if ((gitError && acceptableError) || acceptableExitCode) {
return gitResult
}
if (gitError) {
console.error(`(The error was parsed as ${gitError}: ${gitErrorDescription})`)
console.error(`The command \`git ${args.join(' ')}\` exited with an unexpected code: ${exitCode}. The caller should either handle this error, or expect that exit code.`)
if (result.stdout.length) {
console.error(result.stdout)
}
if (result.stderr.length) {
console.error(result.stderr)
}
if (gitError) {
console.error(`(The error was parsed as ${gitError}: ${gitErrorDescription})`)
}
throw new GitError(gitResult, args)
} finally {
if (ssh && 'dispose' in ssh && typeof ssh.dispose === 'function') {
ssh.dispose();
}
}
throw new GitError(gitResult, args)
}
async function splitPath(path: string): Promise<string[]> {
const parts = path.split(/(\/|\\)/);
if (!parts.length) {
return parts;
async function setupSsh(options?: IGitExecutionOptions): Promise<any> {
let ssh: any;
if (options === undefined) {
options = {};
}
// When the `path` starts with a slash, the the first part is empty string.
return !parts[0].length ? parts.slice(1) : parts;
const gitPath = await findGitExec();
if (typeof process.env.LOCAL_GIT_PATH === 'undefined') {
process.env.LOCAL_GIT_PATH = gitPath.path;
}
const SSH = require('node-ssh');
ssh = await new SSH().connect({
host: process.env.GIT_OVER_SSH_TEST_HOST || 'localhost',
username: process.env.GIT_OVER_SSH_TEST_USERNAME || 'username',
password: process.env.GIT_OVER_SSH_TEST_PASSWORD || 'password',
});
const exec: IGitExecutionOptions.ExecFunc = async (args: string[], options: { cwd: string, stdin?: string }, callback: (error: Error | null, stdout: string, stderr: string) => void) => {
const { stdout, stderr, code } = await ssh.execCommand(`${gitPath.path} ${args.join(' ')}`, { cwd: options.cwd, stdin: options.stdin });
let error: Error | null = null
if (code) {
error = new Error(stderr || 'Unknown error.');
(error as any).code = code
}
callback(error, stdout, stderr)
}
(options as any).exec = exec;
return ssh;
}
export async function gitVersion(): Promise<string> {
export async function gitVersion(options?: IGitExecutionOptions): Promise<string> {
await initGitEnv();
await configureGitEnv();
const { stdout } = await GitProcess.exec(['--version'], '') || '';
const { stdout } = await GitProcess.exec(['--version'], '', options) || '';
return stdout.trim();

@@ -171,5 +328,5 @@ }

// We need to traverse up two levels to get the expected Git directory.
// `dugite` expects the directory path instead of the executable path.
// https://github.com/desktop/dugite/issues/111
const segments = await splitPath(git.path);
const gitDir = segments.slice(0, segments.length - 4).join('');
const gitDir = Path.dirname(Path.dirname(git.path));
if (fs.existsSync(gitDir) && fs.existsSync(git.execPath)) {

@@ -176,0 +333,0 @@ __GIT_PATH__.gitDir = gitDir;

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 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 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 not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc