Browse Source

Add new command to diff HEAD with branch using command palette

main
Geoffrey 6 years ago
committed by Eric Amodio
parent
commit
dd3768fa33
4 changed files with 66 additions and 0 deletions
  1. +9
    -0
      package.json
  2. +2
    -0
      src/commands.ts
  3. +1
    -0
      src/commands/common.ts
  4. +54
    -0
      src/commands/diffHeadWithBranch.ts

+ 9
- 0
package.json View File

@ -1102,6 +1102,11 @@
"category": "GitLens" "category": "GitLens"
}, },
{ {
"command": "gitlens.diffHeadWithBranch",
"title": "Compare Index (HEAD) with Branch or Tag...",
"category": "GitLens"
},
{
"command": "gitlens.diffWith", "command": "gitlens.diffWith",
"title": "Compare File Revisions", "title": "Compare File Revisions",
"category": "GitLens" "category": "GitLens"
@ -1653,6 +1658,10 @@
"when": "gitlens:enabled" "when": "gitlens:enabled"
}, },
{ {
"command": "gitlens.diffHeadWithBranch",
"when": "gitlens:enabled"
},
{
"command": "gitlens.diffWith", "command": "gitlens.diffWith",
"when": "false" "when": "false"
}, },

+ 2
- 0
src/commands.ts View File

@ -9,6 +9,7 @@ export * from './commands/closeUnchangedFiles';
export * from './commands/copyMessageToClipboard'; export * from './commands/copyMessageToClipboard';
export * from './commands/copyShaToClipboard'; export * from './commands/copyShaToClipboard';
export * from './commands/diffDirectory'; export * from './commands/diffDirectory';
export * from './commands/diffHeadWithBranch';
export * from './commands/diffLineWithPrevious'; export * from './commands/diffLineWithPrevious';
export * from './commands/diffLineWithWorking'; export * from './commands/diffLineWithWorking';
export * from './commands/diffWith'; export * from './commands/diffWith';
@ -59,6 +60,7 @@ export function configureCommands(): void {
Container.context.subscriptions.push(new Commands.CopyMessageToClipboardCommand()); Container.context.subscriptions.push(new Commands.CopyMessageToClipboardCommand());
Container.context.subscriptions.push(new Commands.CopyShaToClipboardCommand()); Container.context.subscriptions.push(new Commands.CopyShaToClipboardCommand());
Container.context.subscriptions.push(new Commands.DiffDirectoryCommand()); Container.context.subscriptions.push(new Commands.DiffDirectoryCommand());
Container.context.subscriptions.push(new Commands.DiffHeadWithBranchCommand());
Container.context.subscriptions.push(new Commands.DiffLineWithPreviousCommand()); Container.context.subscriptions.push(new Commands.DiffLineWithPreviousCommand());
Container.context.subscriptions.push(new Commands.DiffLineWithWorkingCommand()); Container.context.subscriptions.push(new Commands.DiffLineWithWorkingCommand());
Container.context.subscriptions.push(new Commands.DiffWithCommand()); Container.context.subscriptions.push(new Commands.DiffWithCommand());

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

@ -12,6 +12,7 @@ export enum Commands {
CopyMessageToClipboard = 'gitlens.copyMessageToClipboard', CopyMessageToClipboard = 'gitlens.copyMessageToClipboard',
CopyShaToClipboard = 'gitlens.copyShaToClipboard', CopyShaToClipboard = 'gitlens.copyShaToClipboard',
DiffDirectory = 'gitlens.diffDirectory', DiffDirectory = 'gitlens.diffDirectory',
DiffHeadWithBranch = 'gitlens.diffHeadWithBranch',
ExternalDiffAll = 'gitlens.externalDiffAll', ExternalDiffAll = 'gitlens.externalDiffAll',
DiffWith = 'gitlens.diffWith', DiffWith = 'gitlens.diffWith',
DiffWithBranch = 'gitlens.diffWithBranch', DiffWithBranch = 'gitlens.diffWithBranch',

+ 54
- 0
src/commands/diffHeadWithBranch.ts View File

@ -0,0 +1,54 @@
'use strict';
import { CancellationTokenSource, TextEditor, Uri, window } from 'vscode';
import { ActiveEditorCommand, Commands, getCommandUri } from './common';
import { GlyphChars } from '../constants';
import { Container } from '../container';
import { Logger } from '../logger';
import { Messages } from '../messages';
import { BranchesAndTagsQuickPick, CommandQuickPickItem } from '../quickPicks';
export class DiffHeadWithBranchCommand extends ActiveEditorCommand {
constructor() {
super([Commands.DiffHeadWithBranch]);
}
async execute(editor?: TextEditor, uri?: Uri): Promise<any> {
uri = getCommandUri(uri, editor);
let progressCancellation: CancellationTokenSource | undefined;
try {
const repoPath = await Container.git.getRepoPath(uri);
if (!repoPath) return Messages.showNoRepositoryWarningMessage(`Unable to open directory compare`);
const placeHolder = `Compare Index (HEAD) to ${GlyphChars.Ellipsis}`;
progressCancellation = BranchesAndTagsQuickPick.showProgress(placeHolder);
const [branches, tags] = await Promise.all([
Container.git.getBranches(repoPath),
Container.git.getTags(repoPath)
]);
if (progressCancellation.token.isCancellationRequested) return undefined;
const pick = await BranchesAndTagsQuickPick.show(branches, tags, placeHolder, { progressCancellation: progressCancellation });
if (pick === undefined) return undefined;
if (pick instanceof CommandQuickPickItem) return pick.execute();
const compareWith = pick.name;
if (compareWith === undefined) return undefined;
Container.resultsExplorer.showComparisonInResults(repoPath, compareWith, 'HEAD');
return undefined;
} catch (ex) {
Logger.error(ex, 'DiffHeadWithBranchCommand');
return window.showErrorMessage(`Unable to open directory compare. See output channel for more details`);
} finally {
progressCancellation && progressCancellation.dispose();
}
}
}

Loading…
Cancel
Save