提交 26b8508d 编写于 作者: J Joao Moreno

Merge branch 'git-submodules' of https://github.com/petkahl/vscode into petkahl-git-submodules

......@@ -13,6 +13,7 @@ import { toGitUri, fromGitUri } from './uri';
import { grep, eventToPromise, isDescendant } from './util';
import { applyLineChanges, intersectDiffWithRange, toLineRanges, invertLineChange } from './staging';
import * as path from 'path';
import { lstat, Stats } from 'fs';
import * as os from 'os';
import TelemetryReporter from 'vscode-extension-telemetry';
import * as nls from 'vscode-nls';
......@@ -168,8 +169,15 @@ export class CommandCenter {
}
private async _openResource(resource: Resource, preview?: boolean, preserveFocus?: boolean, preserveSelection?: boolean): Promise<void> {
const stat = await new Promise<Stats>((c, e) => lstat(resource.resourceUri.fsPath, (err, stat) => err ? e(err) : c(stat)));
if (stat.isDirectory()) {
return;
}
const left = await this.getLeftResource(resource);
const right = await this.getRightResource(resource);
const title = this.getTitle(resource);
if (!right) {
......
......@@ -34,6 +34,11 @@ export interface Remote {
url: string;
}
export interface ISubmodule {
Root: string;
Status: string;
}
export interface Stash {
index: number;
description: string;
......@@ -1108,6 +1113,18 @@ export class Repository {
return uniqBy(rawRemotes, remote => remote.name);
}
async getSubmodules(): Promise<ISubmodule[]> {
const result = await this.run(['submodule', 'status']);
const regex = /^([ \+\-U])\w* (\w*)( \(.*\))?/;
const submodules = result.stdout.split('\n')
.filter(b => !!b)
.map(line => regex.exec(line))
.filter(g => !!g)
.map((groups: RegExpExecArray) => ({ Root: path.join(this.repositoryRoot, groups[2]), Status: groups[1] }));
//this._git.onOutput.emit('log', submodules);
return submodules;
}
async getBranch(name: string): Promise<Branch> {
if (name === 'HEAD') {
return this.getHEAD();
......
......@@ -173,6 +173,23 @@ export class Model {
});
}
private async scanForSubmodules(repository: Repository): Promise<void> {
const submodules = await repository.getSubmodules();
//console.log(`Opening ${submoduleRoot} as git repository`);
for (const submodule of submodules) {
try {
// We can't call tryOpenRepository, because a submodule is going to be under an open repository, so will fail.
const subRepository = new Repository(this.git.open((submodule.Root)), this.globalState);
this.open(subRepository);
} catch (err) {
if (err.gitErrorCode === GitErrorCodes.NotAGitRepository) {
return;
}
}
}
}
@sequentialize
async tryOpenRepository(path: string): Promise<void> {
if (this.getRepository(path)) {
......@@ -227,6 +244,7 @@ export class Model {
const openRepository = { repository, dispose };
this.openRepositories.push(openRepository);
this._onDidOpenRepository.fire(repository);
this.scanForSubmodules(repository);
}
close(repository: Repository): void {
......@@ -281,7 +299,7 @@ export class Model {
if (hint instanceof Uri) {
const resourcePath = hint.fsPath;
for (const liveRepository of this.openRepositories) {
for (const liveRepository of this.openRepositories.sort((a, b) => b.repository.root.length - a.repository.root.length)) {
const relativePath = path.relative(liveRepository.repository.root, resourcePath);
if (isDescendant(liveRepository.repository.root, resourcePath)) {
......
......@@ -6,7 +6,7 @@
'use strict';
import { Uri, Command, EventEmitter, Event, scm, SourceControl, SourceControlInputBox, SourceControlResourceGroup, SourceControlResourceState, SourceControlResourceDecorations, Disposable, ProgressLocation, window, workspace, WorkspaceEdit, ThemeColor, DecorationData, Memento } from 'vscode';
import { Repository as BaseRepository, Ref, Branch, Remote, Commit, GitErrorCodes, Stash, RefType, GitError } from './git';
import { Repository as BaseRepository, Ref, Branch, Remote, Commit, GitErrorCodes, Stash, RefType, GitError, ISubmodule } from './git';
import { anyEvent, filterEvent, eventToPromise, dispose, find, isDescendant, IDisposable, onceEvent, EmptyDisposable, debounceEvent } from './util';
import { memoize, throttle, debounce } from './decorators';
import { toGitUri } from './uri';
......@@ -420,6 +420,18 @@ class ProgressManager {
}
}
export enum SubmoduleStatus {
Uninitialized,
Current,
Conflict,
Modified
}
export interface Submodule {
Root: string;
Status: SubmoduleStatus;
}
export class Repository implements Disposable {
private _onDidChangeRepository = new EventEmitter<Uri>();
......@@ -757,6 +769,19 @@ export class Repository implements Disposable {
return this.run(Operation.Show, () => this.repository.detectObjectType(object));
}
async getSubmodules(): Promise<Submodule[]> {
const submodules: ISubmodule[] = await this.repository.getSubmodules();
return submodules.map(isub => {
var status = SubmoduleStatus.Current;
switch (isub.Status) {
case '-': { status = SubmoduleStatus.Uninitialized; break; }
case '+': { status = SubmoduleStatus.Modified; break; }
case 'U': { status = SubmoduleStatus.Conflict; break; }
}
return { Root: isub.Root, Status: status };
});
}
async getStashes(): Promise<Stash[]> {
return await this.repository.getStashes();
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册