Browse Source

Fixes #503 - Open Changes (w difftool) should only open single file

Changes Open All Changes (w difftool) to open files, rather than dirdiff
Changes Open All Changes (w difftool) to prompt for repo when needed
main
Eric Amodio 6 years ago
parent
commit
065bd0ff40
6 changed files with 110 additions and 62 deletions
  1. +1
    -0
      CHANGELOG.md
  2. +1
    -6
      package.json
  3. +25
    -0
      src/commands/common.ts
  4. +0
    -6
      src/commands/diffDirectory.ts
  5. +80
    -47
      src/commands/externalDiff.ts
  6. +3
    -3
      src/git/gitService.ts

+ 1
- 0
CHANGELOG.md View File

@ -23,6 +23,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/) and this p
### Fixed
- Fixes [#503](https://github.com/eamodio/vscode-gitlens/issues/503) - Open Changes (with difftool) opens one difftool window per changed file
- Fixes [#405](https://github.com/eamodio/vscode-gitlens/issues/405) - Secondary, blank repository appears repeatedly in gitExplorer view
- Fixes [#430](https://github.com/eamodio/vscode-gitlens/issues/430) - File revisions can end up being parsed by language servers (causing errors and warnings, etc)
- Fixes [#388](https://github.com/eamodio/vscode-gitlens/issues/388) - Support the mailmap feature of git

+ 1
- 6
package.json View File

@ -2285,7 +2285,7 @@
},
{
"command": "gitlens.externalDiff",
"when": "gitlens:enabled"
"when": "gitlens:activeFileStatus =~ /tracked/"
},
{
"command": "gitlens.externalDiffAll",
@ -2879,11 +2879,6 @@
"group": "2_gitlens@3"
},
{
"command": "gitlens.externalDiffAll",
"when": "gitlens:enabled",
"group": "2_gitlens@4"
},
{
"command": "gitlens.stashSave",
"when": "gitlens:enabled",
"group": "3_gitlens@1"

+ 25
- 0
src/commands/common.ts View File

@ -118,6 +118,31 @@ export async function getRepoPathOrActiveOrPrompt(
return repoPath;
}
export async function getRepoPathOrPrompt(
uri: Uri | undefined,
placeholder: string,
goBackCommand?: CommandQuickPickItem
) {
let repoPath = await Container.git.getRepoPath(uri);
if (!repoPath) {
const pick = await RepositoriesQuickPick.show(placeholder, goBackCommand);
if (pick instanceof CommandQuickPickItem) {
await pick.execute();
return undefined;
}
if (pick === undefined) {
if (goBackCommand !== undefined) {
await goBackCommand.execute();
}
return undefined;
}
repoPath = pick.repoPath;
}
return repoPath;
}
export interface CommandContextParsingOptions {
editor: boolean;
uri: boolean;

+ 0
- 6
src/commands/diffDirectory.ts View File

@ -24,7 +24,6 @@ export class DiffDirectoryCommand extends ActiveEditorCommand {
constructor() {
super([
Commands.DiffDirectory,
Commands.ExternalDiffAll,
Commands.ExplorersOpenDirectoryDiff,
Commands.ExplorersOpenDirectoryDiffWithWorking
]);
@ -32,11 +31,6 @@ export class DiffDirectoryCommand extends ActiveEditorCommand {
protected async preExecute(context: CommandContext, args: DiffDirectoryCommandArgs = {}): Promise<any> {
switch (context.command) {
case Commands.ExternalDiffAll:
args.ref1 = 'HEAD';
args.ref2 = undefined;
break;
case Commands.ExplorersOpenDirectoryDiff:
if (context.type === 'view' && context.node instanceof ResultsComparisonNode) {
args.ref1 = context.node.ref1.ref;

+ 80
- 47
src/commands/externalDiff.ts View File

@ -5,7 +5,7 @@ import { Container } from '../container';
import { Logger } from '../logger';
import { Messages } from '../messages';
import { Arrays } from '../system';
import { Command, CommandContext, Commands, getRepoPathOrActiveOrPrompt } from './common';
import { Command, CommandContext, Commands, getRepoPathOrPrompt } from './common';
enum Status {
INDEX_MODIFIED,
@ -52,32 +52,61 @@ export interface ExternalDiffCommandArgs {
export class ExternalDiffCommand extends Command {
constructor() {
super(Commands.ExternalDiff);
super([Commands.ExternalDiff, Commands.ExternalDiffAll]);
}
protected async preExecute(context: CommandContext, args: ExternalDiffCommandArgs = {}): Promise<any> {
if (context.type === 'scm-states') {
args = { ...args };
args.files = context.scmResourceStates.map(
r => new ExternalDiffFile(r.resourceUri, (r as Resource).resourceGroupType === ResourceGroupType.Index)
);
return this.execute(args);
if (args.files === undefined) {
if (context.type === 'scm-states') {
args = { ...args };
args.files = context.scmResourceStates.map(
r =>
new ExternalDiffFile(
r.resourceUri,
(r as Resource).resourceGroupType === ResourceGroupType.Index
)
);
}
else if (context.type === 'scm-groups') {
args = { ...args };
args.files = Arrays.filterMap(
context.scmResourceGroups[0].resourceStates,
r =>
this.isModified(r)
? new ExternalDiffFile(
r.resourceUri,
(r as Resource).resourceGroupType === ResourceGroupType.Index
)
: undefined
);
}
}
else if (context.type === 'scm-groups') {
args = { ...args };
args.files = Arrays.filterMap(
context.scmResourceGroups[0].resourceStates,
r =>
this.isModified(r)
? new ExternalDiffFile(
r.resourceUri,
(r as Resource).resourceGroupType === ResourceGroupType.Index
)
: undefined
);
return this.execute(args);
if (context.command === Commands.ExternalDiffAll) {
if (args.files === undefined) {
const repoPath = await getRepoPathOrPrompt(
undefined,
`Open changes from which repository${GlyphChars.Ellipsis}`
);
if (!repoPath) return undefined;
const status = await Container.git.getStatusForRepo(repoPath);
if (status === undefined) {
return window.showInformationMessage("The repository doesn't have any changes");
}
args.files = [];
for (const file of status.files) {
if (file.indexStatus === 'M') {
args.files.push(new ExternalDiffFile(file.uri, true));
}
if (file.workingTreeStatus === 'M') {
args.files.push(new ExternalDiffFile(file.uri, false));
}
}
}
}
return this.execute(args);
@ -90,17 +119,38 @@ export class ExternalDiffCommand extends Command {
async execute(args: ExternalDiffCommandArgs = {}) {
try {
const repoPath = await getRepoPathOrActiveOrPrompt(
undefined,
undefined,
`Open changes from which repository${GlyphChars.Ellipsis}`
);
if (!repoPath) return undefined;
let repoPath;
if (args.files === undefined) {
const editor = window.activeTextEditor;
if (editor === undefined) return undefined;
repoPath = await Container.git.getRepoPathOrActive(undefined, editor);
if (!repoPath) return undefined;
const uri = editor.document.uri;
const status = await Container.git.getStatusForFile(repoPath, uri.fsPath);
if (status === undefined) {
return window.showInformationMessage("The current file doesn't have any changes");
}
args.files = [];
if (status.indexStatus === 'M') {
args.files.push(new ExternalDiffFile(status.uri, true));
}
if (status.workingTreeStatus === 'M') {
args.files.push(new ExternalDiffFile(status.uri, false));
}
}
else {
repoPath = await Container.git.getRepoPath(args.files[0].uri.fsPath);
if (!repoPath) return undefined;
}
const tool = await Container.git.getDiffTool(repoPath);
if (tool === undefined) {
const result = await window.showWarningMessage(
`Unable to open changes in diff tool because there is no Git diff tool configured`,
`Unable to open changes in diff tool. No Git diff tool is configured`,
'View Git Docs'
);
if (!result) return undefined;
@ -111,23 +161,6 @@ export class ExternalDiffCommand extends Command {
);
}
if (args.files === undefined) {
const status = await Container.git.getStatusForRepo(repoPath);
if (status === undefined) return window.showWarningMessage(`Unable to open changes in diff tool`);
args.files = [];
for (const file of status.files) {
if (file.indexStatus === 'M') {
args.files.push(new ExternalDiffFile(file.uri, true));
}
if (file.workingTreeStatus === 'M') {
args.files.push(new ExternalDiffFile(file.uri, false));
}
}
}
for (const file of args.files) {
void Container.git.openDiffTool(repoPath, file.uri, file.staged, tool);
}

+ 3
- 3
src/git/gitService.ts View File

@ -1491,7 +1491,7 @@ export class GitService implements Disposable {
filePathOrUri: string | Uri | undefined,
options: { ref?: string } = {}
): Promise<string | undefined> {
if (filePathOrUri == null) return await this.getActiveRepoPath();
if (filePathOrUri == null) return this.getHighlanderRepoPath();
if (filePathOrUri instanceof GitUri) return filePathOrUri.repoPath;
// Don't save the tracking info to the cache, because we could be looking in the wrong place (e.g. looking in the root when the file is in a submodule)
@ -1541,10 +1541,10 @@ export class GitService implements Disposable {
}
async getRepoPathOrActive(uri: Uri | undefined, editor: TextEditor | undefined) {
const repoPath = await Container.git.getRepoPath(uri);
const repoPath = await this.getRepoPath(uri);
if (repoPath) return repoPath;
return Container.git.getActiveRepoPath(editor);
return this.getActiveRepoPath(editor);
}
async getRepositories(predicate?: (repo: Repository) => boolean): Promise<Iterable<Repository>> {

Loading…
Cancel
Save