mirror of
https://github.com/microsoft/vscode.git
synced 2026-04-28 12:33:35 +01:00
@@ -103,7 +103,7 @@ export class CommandCenter {
|
||||
message = localize('clean repo', "Please clean your repository working tree before checkout.");
|
||||
break;
|
||||
default:
|
||||
message = (err.stderr || err.message).replace(/^error: /, '');
|
||||
message = (err.stderr || err.message || String(err)).replace(/^error: /, '');
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
@@ -10,8 +10,7 @@ import * as path from 'path';
|
||||
import * as os from 'os';
|
||||
import * as cp from 'child_process';
|
||||
import * as denodeify from 'denodeify';
|
||||
import { IDisposable, toDisposable, dispose } from './util';
|
||||
import * as _ from 'lodash';
|
||||
import { assign, uniqBy, groupBy, IDisposable, toDisposable, dispose } from './util';
|
||||
import { EventEmitter, Event } from 'vscode';
|
||||
import * as nls from 'vscode-nls';
|
||||
|
||||
@@ -292,12 +291,12 @@ export class Git {
|
||||
}
|
||||
|
||||
async exec(cwd: string, args: string[], options: any = {}): Promise<IExecutionResult> {
|
||||
options = _.assign({ cwd }, options || {});
|
||||
options = assign({ cwd }, options || {});
|
||||
return await this._exec(args, options);
|
||||
}
|
||||
|
||||
stream(cwd: string, args: string[], options: any = {}): cp.ChildProcess {
|
||||
options = _.assign({ cwd }, options || {});
|
||||
options = assign({ cwd }, options || {});
|
||||
return this.spawn(args, options);
|
||||
}
|
||||
|
||||
@@ -357,7 +356,7 @@ export class Git {
|
||||
options.stdio = ['ignore', null, null]; // Unless provided, ignore stdin and leave default streams for stdout and stderr
|
||||
}
|
||||
|
||||
options.env = _.assign({}, process.env, options.env || {});
|
||||
options.env = assign({}, process.env, options.env || {});
|
||||
|
||||
if (options.log !== false) {
|
||||
this.log(`git ${args.join(' ')}\n`);
|
||||
@@ -394,22 +393,22 @@ export class Repository {
|
||||
|
||||
// TODO@Joao: rename to exec
|
||||
async run(args: string[], options: any = {}): Promise<IExecutionResult> {
|
||||
options.env = _.assign({}, options.env || {});
|
||||
options.env = _.assign(options.env, this.env);
|
||||
options.env = assign({}, options.env || {});
|
||||
options.env = assign(options.env, this.env);
|
||||
|
||||
return await this.git.exec(this.repository, args, options);
|
||||
}
|
||||
|
||||
stream(args: string[], options: any = {}): cp.ChildProcess {
|
||||
options.env = _.assign({}, options.env || {});
|
||||
options.env = _.assign(options.env, this.env);
|
||||
options.env = assign({}, options.env || {});
|
||||
options.env = assign(options.env, this.env);
|
||||
|
||||
return this.git.stream(this.repository, args, options);
|
||||
}
|
||||
|
||||
spawn(args: string[], options: any = {}): cp.ChildProcess {
|
||||
options.env = _.assign({}, options.env || {});
|
||||
options.env = _.assign(options.env, this.env);
|
||||
options.env = assign({}, options.env || {});
|
||||
options.env = assign(options.env, this.env);
|
||||
|
||||
return this.git.spawn(args, options);
|
||||
}
|
||||
@@ -573,11 +572,9 @@ export class Repository {
|
||||
}
|
||||
|
||||
async clean(paths: string[]): Promise<void> {
|
||||
const tasks = _(paths)
|
||||
.groupBy(p => path.dirname(p))
|
||||
.values<string[]>()
|
||||
.map(paths => () => this.run(['clean', '-f', '-q', '--'].concat(paths)))
|
||||
.value();
|
||||
const pathsByGroup = groupBy(paths, p => path.dirname(p));
|
||||
const groups = Object.keys(pathsByGroup).map(k => pathsByGroup[k]);
|
||||
const tasks = groups.map(paths => () => this.run(['clean', '-f', '-q', '--'].concat(paths)));
|
||||
|
||||
for (let task of tasks) {
|
||||
await task();
|
||||
@@ -802,14 +799,13 @@ export class Repository {
|
||||
async getRemotes(): Promise<IRemote[]> {
|
||||
const result = await this.run(['remote', '--verbose']);
|
||||
const regex = /^([^\s]+)\s+([^\s]+)\s/;
|
||||
|
||||
return _(result.stdout.trim().split('\n'))
|
||||
const rawRemotes = result.stdout.trim().split('\n')
|
||||
.filter(b => !!b)
|
||||
.map(line => regex.exec(line))
|
||||
.filter(g => !!g)
|
||||
.map((groups: RegExpExecArray) => ({ name: groups[1], url: groups[2] }))
|
||||
.uniqBy(remote => remote.name)
|
||||
.value();
|
||||
.map((groups: RegExpExecArray) => ({ name: groups[1], url: groups[2] }));
|
||||
|
||||
return uniqBy(rawRemotes, remote => remote.name);
|
||||
}
|
||||
|
||||
async getBranch(name: string): Promise<IBranch> {
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
{
|
||||
"globalDependencies": {
|
||||
"denodeify": "registry:dt/denodeify#1.2.1+20160316155526",
|
||||
"lodash": "registry:dt/lodash#4.14.0+20161110215204"
|
||||
"denodeify": "registry:dt/denodeify#1.2.1+20160316155526"
|
||||
}
|
||||
}
|
||||
22713
extensions/git/src/typings/globals/lodash/index.d.ts
vendored
22713
extensions/git/src/typings/globals/lodash/index.d.ts
vendored
File diff suppressed because it is too large
Load Diff
@@ -1,8 +0,0 @@
|
||||
{
|
||||
"resolution": "main",
|
||||
"tree": {
|
||||
"src": "https://raw.githubusercontent.com/DefinitelyTyped/DefinitelyTyped/56a4356292163a8dd087810b820e511346882255/lodash/lodash.d.ts",
|
||||
"raw": "registry:dt/lodash#4.14.0+20161110215204",
|
||||
"typings": "https://raw.githubusercontent.com/DefinitelyTyped/DefinitelyTyped/56a4356292163a8dd087810b820e511346882255/lodash/lodash.d.ts"
|
||||
}
|
||||
}
|
||||
1
extensions/git/src/typings/index.d.ts
vendored
1
extensions/git/src/typings/index.d.ts
vendored
@@ -1,2 +1 @@
|
||||
/// <reference path="globals/denodeify/index.d.ts" />
|
||||
/// <reference path="globals/lodash/index.d.ts" />
|
||||
|
||||
@@ -57,4 +57,35 @@ export function once<T>(event: Event<T>): Event<T> {
|
||||
|
||||
export function eventToPromise<T>(event: Event<T>): Promise<T> {
|
||||
return new Promise(c => once(event)(c));
|
||||
}
|
||||
|
||||
export function assign<T>(destination: T, ...sources: any[]): T {
|
||||
for (const source of sources) {
|
||||
Object.keys(source).forEach(key => destination[key] = source[key]);
|
||||
}
|
||||
|
||||
return destination;
|
||||
}
|
||||
|
||||
export function uniqBy<T>(arr: T[], fn: (el: T) => string): T[] {
|
||||
const seen = Object.create(null);
|
||||
|
||||
return arr.filter(el => {
|
||||
const key = fn(el);
|
||||
|
||||
if (seen[key]) {
|
||||
return false;
|
||||
}
|
||||
|
||||
seen[key] = true;
|
||||
return true;
|
||||
});
|
||||
}
|
||||
|
||||
export function groupBy<T>(arr: T[], fn: (el: T) => string): { [key: string]: T[] } {
|
||||
return arr.reduce((result, el) => {
|
||||
const key = fn(el);
|
||||
result[key] = [...(result[key] || []), el];
|
||||
return result;
|
||||
}, Object.create(null));
|
||||
}
|
||||
Reference in New Issue
Block a user