Skip to content

Commit

Permalink
Adds push repositories command
Browse files Browse the repository at this point in the history
Adds @command decorator
Changes (fetch|pull|push)All to be cancelable
  • Loading branch information
eamodio committed Nov 1, 2018
1 parent 6934dc7 commit 9a1b48a
Show file tree
Hide file tree
Showing 54 changed files with 390 additions and 327 deletions.
18 changes: 18 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -1913,6 +1913,15 @@
"light": "images/light/icon-pull.svg"
}
},
{
"command": "gitlens.pushRepositories",
"title": "Push Repositories",
"category": "GitLens",
"icon": {
"dark": "images/dark/icon-push.svg",
"light": "images/light/icon-push.svg"
}
},
{
"command": "gitlens.views.fetch",
"title": "Fetch Repository",
Expand Down Expand Up @@ -2594,6 +2603,10 @@
"command": "gitlens.pullRepositories",
"when": "gitlens:hasRemotes"
},
{
"command": "gitlens.pushRepositories",
"when": "gitlens:hasRemotes"
},
{
"command": "gitlens.views.fetch",
"when": "false"
Expand Down Expand Up @@ -3111,6 +3124,11 @@
"when": "gitlens:enabled && view =~ /^gitlens.views.repositories:/",
"group": "navigation@1"
},
{
"command": "gitlens.pushRepositories",
"when": "gitlens:enabled && view =~ /^gitlens.views.repositories:/",
"group": "navigation@6"
},
{
"command": "gitlens.pullRepositories",
"when": "gitlens:enabled && view =~ /^gitlens.views.repositories:/",
Expand Down
112 changes: 4 additions & 108 deletions src/commands.ts
Original file line number Diff line number Diff line change
@@ -1,57 +1,8 @@
'use strict';
import { ClearFileAnnotationsCommand } from './commands/clearFileAnnotations';
import { CloseUnchangedFilesCommand } from './commands/closeUnchangedFiles';
import { CopyMessageToClipboardCommand } from './commands/copyMessageToClipboard';
import { CopyRemoteFileUrlToClipboardCommand } from './commands/copyRemoteFileUrlToClipboard';
import { CopyShaToClipboardCommand } from './commands/copyShaToClipboard';
import { DiffBranchWithBranchCommand } from './commands/diffBranchWithBranch';
import { DiffDirectoryCommand } from './commands/diffDirectory';
import { DiffLineWithPreviousCommand } from './commands/diffLineWithPrevious';
import { DiffLineWithWorkingCommand } from './commands/diffLineWithWorking';
import { DiffWithCommand } from './commands/diffWith';
import { DiffWithBranchCommand } from './commands/diffWithBranch';
import { DiffWithNextCommand } from './commands/diffWithNext';
import { DiffWithPreviousCommand } from './commands/diffWithPrevious';
import { DiffWithRevisionCommand } from './commands/diffWithRevision';
import { DiffWithWorkingCommand } from './commands/diffWithWorking';
import { ExternalDiffCommand } from './commands/externalDiff';
import { FetchRepositoriesCommand } from './commands/fetchRepositories';
import { OpenBranchesInRemoteCommand } from './commands/openBranchesInRemote';
import { OpenBranchInRemoteCommand } from './commands/openBranchInRemote';
import { OpenChangedFilesCommand } from './commands/openChangedFiles';
import { OpenCommitInRemoteCommand } from './commands/openCommitInRemote';
import { OpenFileInRemoteCommand } from './commands/openFileInRemote';
import { OpenFileRevisionCommand } from './commands/openFileRevision';
import { OpenInRemoteCommand } from './commands/openInRemote';
import { OpenRepoInRemoteCommand } from './commands/openRepoInRemote';
import { OpenWorkingFileCommand } from './commands/openWorkingFile';
import { PullRepositoriesCommand } from './commands/pullRepositories';
import { ResetSuppressedWarningsCommand } from './commands/resetSuppressedWarnings';
import { ShowCommitSearchCommand } from './commands/showCommitSearch';
import { ShowLastQuickPickCommand } from './commands/showLastQuickPick';
import { ShowQuickBranchHistoryCommand } from './commands/showQuickBranchHistory';
import { ShowQuickCommitDetailsCommand } from './commands/showQuickCommitDetails';
import { ShowQuickCommitFileDetailsCommand } from './commands/showQuickCommitFileDetails';
import { ShowQuickCurrentBranchHistoryCommand } from './commands/showQuickCurrentBranchHistory';
import { ShowQuickFileHistoryCommand } from './commands/showQuickFileHistory';
import { ShowQuickRepoStatusCommand } from './commands/showQuickRepoStatus';
import { ShowQuickStashListCommand } from './commands/showQuickStashList';
import { ShowViewCommand } from './commands/showView';
import { StashApplyCommand } from './commands/stashApply';
import { StashDeleteCommand } from './commands/stashDelete';
import { StashSaveCommand } from './commands/stashSave';
import { SwitchModeCommand, ToggleReviewModeCommand, ToggleZenModeCommand } from './commands/switchMode';
import { ToggleCodeLensCommand } from './commands/toggleCodeLens';
import { ToggleFileBlameCommand } from './commands/toggleFileBlame';
import { ToggleFileHeatmapCommand } from './commands/toggleFileHeatmap';
import { ToggleFileRecentChangesCommand } from './commands/toggleFileRecentChanges';
import { ToggleLineBlameCommand } from './commands/toggleLineBlame';
import { CommandContext, setCommandContext } from './constants';
import { Container } from './container';

export * from './commands/common';
export * from './commands/clearFileAnnotations';
export * from './commands/annotations';
export * from './commands/closeUnchangedFiles';
export * from './commands/common';
export * from './commands/copyMessageToClipboard';
export * from './commands/copyRemoteFileUrlToClipboard';
export * from './commands/copyShaToClipboard';
Expand All @@ -75,9 +26,9 @@ export * from './commands/openFileRevision';
export * from './commands/openInRemote';
export * from './commands/openRepoInRemote';
export * from './commands/openWorkingFile';
export * from './commands/repositories';
export * from './commands/resetSuppressedWarnings';
export * from './commands/showCommitSearch';
export * from './commands/showView';
export * from './commands/showLastQuickPick';
export * from './commands/showQuickBranchHistory';
export * from './commands/showQuickCommitDetails';
Expand All @@ -86,64 +37,9 @@ export * from './commands/showQuickCurrentBranchHistory';
export * from './commands/showQuickFileHistory';
export * from './commands/showQuickRepoStatus';
export * from './commands/showQuickStashList';
export * from './commands/showView';
export * from './commands/stashApply';
export * from './commands/stashDelete';
export * from './commands/stashSave';
export * from './commands/switchMode';
export * from './commands/toggleCodeLens';
export * from './commands/toggleFileBlame';
export * from './commands/toggleFileHeatmap';
export * from './commands/toggleFileRecentChanges';
export * from './commands/toggleLineBlame';

export function configureCommands(): void {
Container.context.subscriptions.push(new ClearFileAnnotationsCommand());
Container.context.subscriptions.push(new CloseUnchangedFilesCommand());
Container.context.subscriptions.push(new CopyMessageToClipboardCommand());
Container.context.subscriptions.push(new CopyRemoteFileUrlToClipboardCommand());
Container.context.subscriptions.push(new CopyShaToClipboardCommand());
Container.context.subscriptions.push(new DiffBranchWithBranchCommand());
Container.context.subscriptions.push(new DiffDirectoryCommand());
Container.context.subscriptions.push(new DiffLineWithPreviousCommand());
Container.context.subscriptions.push(new DiffLineWithWorkingCommand());
Container.context.subscriptions.push(new DiffWithCommand());
Container.context.subscriptions.push(new DiffWithBranchCommand());
Container.context.subscriptions.push(new DiffWithNextCommand());
Container.context.subscriptions.push(new DiffWithPreviousCommand());
Container.context.subscriptions.push(new DiffWithRevisionCommand());
Container.context.subscriptions.push(new DiffWithWorkingCommand());
Container.context.subscriptions.push(new ExternalDiffCommand());
Container.context.subscriptions.push(new FetchRepositoriesCommand());
Container.context.subscriptions.push(new OpenBranchesInRemoteCommand());
Container.context.subscriptions.push(new OpenBranchInRemoteCommand());
Container.context.subscriptions.push(new OpenChangedFilesCommand());
Container.context.subscriptions.push(new OpenCommitInRemoteCommand());
Container.context.subscriptions.push(new OpenFileInRemoteCommand());
Container.context.subscriptions.push(new OpenFileRevisionCommand());
Container.context.subscriptions.push(new OpenInRemoteCommand());
Container.context.subscriptions.push(new OpenRepoInRemoteCommand());
Container.context.subscriptions.push(new OpenWorkingFileCommand());
Container.context.subscriptions.push(new PullRepositoriesCommand());
Container.context.subscriptions.push(new ResetSuppressedWarningsCommand());
Container.context.subscriptions.push(new ShowCommitSearchCommand());
Container.context.subscriptions.push(new ShowViewCommand());
Container.context.subscriptions.push(new ShowLastQuickPickCommand());
Container.context.subscriptions.push(new ShowQuickBranchHistoryCommand());
Container.context.subscriptions.push(new ShowQuickCommitDetailsCommand());
Container.context.subscriptions.push(new ShowQuickCommitFileDetailsCommand());
Container.context.subscriptions.push(new ShowQuickCurrentBranchHistoryCommand());
Container.context.subscriptions.push(new ShowQuickFileHistoryCommand());
Container.context.subscriptions.push(new ShowQuickRepoStatusCommand());
Container.context.subscriptions.push(new ShowQuickStashListCommand());
Container.context.subscriptions.push(new StashApplyCommand());
Container.context.subscriptions.push(new StashDeleteCommand());
Container.context.subscriptions.push(new StashSaveCommand());
Container.context.subscriptions.push(new SwitchModeCommand());
Container.context.subscriptions.push(new ToggleCodeLensCommand());
Container.context.subscriptions.push(new ToggleFileBlameCommand());
Container.context.subscriptions.push(new ToggleFileHeatmapCommand());
Container.context.subscriptions.push(new ToggleFileRecentChangesCommand());
Container.context.subscriptions.push(new ToggleLineBlameCommand());
Container.context.subscriptions.push(new ToggleReviewModeCommand());
Container.context.subscriptions.push(new ToggleZenModeCommand());
}
123 changes: 123 additions & 0 deletions src/commands/annotations.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
'use strict';
import { commands, TextEditor, TextEditorEdit, Uri, window } from 'vscode';
import { UriComparer } from '../comparers';
import { FileAnnotationType } from '../configuration';
import { isTextEditor } from '../constants';
import { Container } from '../container';
import { Logger } from '../logger';
import { Messages } from '../messages';
import { ActiveEditorCommand, command, Commands, EditorCommand } from './common';

@command()
export class ClearFileAnnotationsCommand extends EditorCommand {
constructor() {
super([Commands.ClearFileAnnotations, Commands.ComputingFileAnnotations]);
}

async execute(editor: TextEditor, edit: TextEditorEdit, uri?: Uri): Promise<any> {
// Handle the case where we are focused on a non-editor editor (output, debug console)
if (editor != null && !isTextEditor(editor)) {
if (uri != null && !UriComparer.equals(uri, editor.document.uri)) {
const e = window.visibleTextEditors.find(e => UriComparer.equals(uri, e.document.uri));
if (e !== undefined) {
editor = e;
}
}
}

try {
return Container.fileAnnotations.clear(editor);
}
catch (ex) {
Logger.error(ex, 'ClearFileAnnotationsCommand');
return Messages.showGenericErrorMessage('Unable to clear file annotations');
}
}
}

export interface ToggleFileBlameCommandArgs {
sha?: string;
type?: FileAnnotationType;
}

@command()
export class ToggleFileBlameCommand extends ActiveEditorCommand {
constructor() {
super(Commands.ToggleFileBlame);
}

async execute(editor: TextEditor, uri?: Uri, args: ToggleFileBlameCommandArgs = {}): Promise<any> {
// Handle the case where we are focused on a non-editor editor (output, debug console)
if (editor != null && !isTextEditor(editor)) {
if (uri != null && !UriComparer.equals(uri, editor.document.uri)) {
const e = window.visibleTextEditors.find(e => UriComparer.equals(uri, e.document.uri));
if (e !== undefined) {
editor = e;
}
}
}

try {
if (args.type === undefined) {
args = { ...args, type: FileAnnotationType.Blame };
}

return Container.fileAnnotations.toggle(
editor,
args.type!,
args.sha !== undefined ? args.sha : editor && editor.selection.active.line
);
}
catch (ex) {
Logger.error(ex, 'ToggleFileBlameCommand');
return window.showErrorMessage(
`Unable to toggle file ${args.type} annotations. See output channel for more details`
);
}
}
}

@command()
export class ToggleFileHeatmapCommand extends ActiveEditorCommand {
constructor() {
super(Commands.ToggleFileHeatmap);
}

async execute(editor: TextEditor, uri?: Uri): Promise<any> {
commands.executeCommand(Commands.ToggleFileBlame, uri, {
type: FileAnnotationType.Heatmap
} as ToggleFileBlameCommandArgs);
}
}

@command()
export class ToggleFileRecentChangesCommand extends ActiveEditorCommand {
constructor() {
super(Commands.ToggleFileRecentChanges);
}

async execute(editor: TextEditor, uri?: Uri): Promise<any> {
commands.executeCommand(Commands.ToggleFileBlame, uri, {
type: FileAnnotationType.RecentChanges
} as ToggleFileBlameCommandArgs);
}
}

@command()
export class ToggleLineBlameCommand extends ActiveEditorCommand {
constructor() {
super(Commands.ToggleLineBlame);
}

async execute(editor: TextEditor, uri?: Uri): Promise<any> {
try {
return Container.lineAnnotations.toggle(editor);
}
catch (ex) {
Logger.error(ex, 'ToggleLineBlameCommand');
return window.showErrorMessage(
`Unable to toggle line blame annotations. See output channel for more details`
);
}
}
}
34 changes: 0 additions & 34 deletions src/commands/clearFileAnnotations.ts

This file was deleted.

3 changes: 2 additions & 1 deletion src/commands/closeUnchangedFiles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,13 @@ import { Container } from '../container';
import { Logger } from '../logger';
import { Messages } from '../messages';
import { Functions } from '../system';
import { ActiveEditorCommand, Commands, getCommandUri, getRepoPathOrPrompt } from './common';
import { ActiveEditorCommand, command, Commands, getCommandUri, getRepoPathOrPrompt } from './common';

export interface CloseUnchangedFilesCommandArgs {
uris?: Uri[];
}

@command()
export class CloseUnchangedFilesCommand extends ActiveEditorCommand {
private _onEditorChangedFn: ((editor: TextEditor | undefined) => void) | undefined;

Expand Down
20 changes: 20 additions & 0 deletions src/commands/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import * as paths from 'path';
import {
commands,
Disposable,
ExtensionContext,
SourceControlResourceGroup,
SourceControlResourceState,
TextDocumentShowOptions,
Expand Down Expand Up @@ -53,6 +54,7 @@ export enum Commands {
OpenRepoInRemote = 'gitlens.openRepoInRemote',
OpenWorkingFile = 'gitlens.openWorkingFile',
PullRepositories = 'gitlens.pullRepositories',
PushRepositories = 'gitlens.pushRepositories',
ResetSuppressedWarnings = 'gitlens.resetSuppressedWarnings',
ShowCommitInResults = 'gitlens.showCommitInResults',
ShowCommitSearch = 'gitlens.showCommitSearch',
Expand Down Expand Up @@ -87,6 +89,24 @@ export enum Commands {
ViewsOpenDirectoryDiffWithWorking = 'gitlens.views.openDirectoryDiffWithWorking'
}

interface CommandConstructor {
new (): any;
}

const registrableCommands: CommandConstructor[] = [];

export function command(): ClassDecorator {
return (target: any) => {
registrableCommands.push(target);
};
}

export function registerCommands(context: ExtensionContext): void {
for (const c of registrableCommands) {
context.subscriptions.push(new c());
}
}

export function getCommandUri(uri?: Uri, editor?: TextEditor): Uri | undefined {
if (uri instanceof Uri) return uri;
if (editor == null) return undefined;
Expand Down

0 comments on commit 9a1b48a

Please sign in to comment.