Browse Source

Adds fromFileStatus to GitUri

main
Eric Amodio 7 years ago
parent
commit
276c24ac24
4 changed files with 14 additions and 7 deletions
  1. +1
    -2
      src/commands/closeUnchangedFiles.ts
  2. +1
    -2
      src/commands/openChangedFiles.ts
  3. +10
    -1
      src/git/gitUri.ts
  4. +2
    -2
      src/quickPicks/commitDetails.ts

+ 1
- 2
src/commands/closeUnchangedFiles.ts View File

@ -5,7 +5,6 @@ import { ActiveEditorCommand, Commands } from './common';
import { TextEditorComparer, UriComparer } from '../comparers';
import { GitService } from '../gitService';
import { Logger } from '../logger';
import * as path from 'path';
export class CloseUnchangedFilesCommand extends ActiveEditorCommand {
@ -26,7 +25,7 @@ export class CloseUnchangedFilesCommand extends ActiveEditorCommand {
const status = await this.git.getStatusForRepo(repoPath);
if (!status) return window.showWarningMessage(`Unable to close unchanged files`);
uris = status.files.map(_ => Uri.file(path.resolve(repoPath, _.fileName)));
uris = status.files.map(_ => _.Uri);
}
const editorTracker = new ActiveEditorTracker();

+ 1
- 2
src/commands/openChangedFiles.ts View File

@ -3,7 +3,6 @@ import { TextEditor, Uri, window } from 'vscode';
import { ActiveEditorCommand, Commands, openEditor } from './common';
import { GitService } from '../gitService';
import { Logger } from '../logger';
import * as path from 'path';
export class OpenChangedFilesCommand extends ActiveEditorCommand {
@ -24,7 +23,7 @@ export class OpenChangedFilesCommand extends ActiveEditorCommand {
const status = await this.git.getStatusForRepo(repoPath);
if (!status) return window.showWarningMessage(`Unable to open changed files`);
uris = status.files.filter(_ => _.status !== 'D').map(_ => Uri.file(path.resolve(repoPath, _.fileName)));
uris = status.files.filter(_ => _.status !== 'D').map(_ => _.Uri);
}
for (const uri of uris) {

+ 10
- 1
src/git/gitUri.ts View File

@ -1,7 +1,7 @@
'use strict';
import { Uri } from 'vscode';
import { DocumentSchemes } from '../constants';
import { Git, GitService } from '../gitService';
import { Git, GitCommit, GitService, IGitStatusFile } from '../gitService';
import * as path from 'path';
export class GitUri extends Uri {
@ -12,6 +12,7 @@ export class GitUri extends Uri {
constructor(uri?: Uri, commit?: IGitCommitInfo);
constructor(uri?: Uri, repoPath?: string);
constructor(uri?: Uri, commitOrRepoPath?: IGitCommitInfo | string);
constructor(uri?: Uri, commitOrRepoPath?: IGitCommitInfo | string) {
super();
if (!uri) return;
@ -88,6 +89,14 @@ export class GitUri extends Uri {
return new GitUri(uri, git && git.repoPath);
}
static fromFileStatus(status: IGitStatusFile, repoPath: string, original?: boolean): GitUri;
static fromFileStatus(status: IGitStatusFile, commit: GitCommit, original?: boolean): GitUri;
static fromFileStatus(status: IGitStatusFile, repoPathOrCommit: string | GitCommit, original: boolean = false): GitUri {
const repoPath = repoPathOrCommit instanceof GitCommit ? repoPathOrCommit.repoPath : repoPathOrCommit;
const uri = Uri.file(path.resolve(repoPath, original ? status.originalFileName || status.fileName : status.fileName));
return new GitUri(uri, repoPathOrCommit);
}
}
export interface IGitCommitInfo {

+ 2
- 2
src/quickPicks/commitDetails.ts View File

@ -34,7 +34,7 @@ export class CommitWithFileStatusQuickPickItem extends OpenFileCommandQuickPickI
});
this.fileName = status.fileName;
this.gitUri = new GitUri(Uri.file(path.resolve(commit.repoPath, status.fileName)));
this.gitUri = GitUri.fromFileStatus(status, commit.repoPath);
this.sha = commit.sha;
this.shortSha = commit.shortSha;
this.status = status.status;
@ -58,7 +58,7 @@ export class OpenCommitWorkingTreeFilesCommandQuickPickItem extends OpenFilesCom
constructor(commit: GitLogCommit, versioned: boolean = false, item?: QuickPickItem) {
const repoPath = commit.repoPath;
const uris = commit.fileStatuses.map(_ => Uri.file(path.resolve(repoPath, _.fileName)));
const uris = commit.fileStatuses.map(_ => GitUri.fromFileStatus(_, repoPath));
super(uris, item || {
label: `$(file-symlink-file) Open Changed Working Files`,
description: undefined

Loading…
Cancel
Save