Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 1 addition & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,17 +44,7 @@ Calling out known issues can help limit users opening duplicate issues against y

## Release Notes

Users appreciate release notes as you update your extension.

### 0.0.1

Initial release of Gops

## Following extension guidelines

Ensure that you've read through the extensions guidelines and follow the best practices for creating your extension.

- [Extension Guidelines](https://code.visualstudio.com/api/references/extension-guidelines)
Refer to CHANGELOG.md

## Build Process

Expand Down
47 changes: 46 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,26 @@
"command": "gops.showDiff",
"title": "Show Diff",
"icon": "$(diff)"
},
{
"command": "gops.stageFile",
"title": "Stage File",
"icon": "$(add)"
},
{
"command": "gops.unstageFile",
"title": "Unstage File",
"icon": "$(remove)"
},
{
"command": "gops.commit",
"title": "Commit",
"icon": "$(save)"
},
{
"command": "gops.unstageAllFiles",
"title": "Unstage All Files",
"icon": "$(collapse-all)"
}
],
"viewsContainers": {
Expand All @@ -119,6 +139,11 @@
},
"menus": {
"view/title": [
{
"command": "gops.commit",
"when": "view == gitOpsTreeview && gops.hasStagedFiles == true",
"group": "navigation"
},
{
"command": "gops.refresh",
"when": "view == gitOpsTreeview",
Expand All @@ -143,13 +168,33 @@
"view/item/context": [
{
"command": "gops.branch",
"title": "New Branch",
"when": "view == gitOpsTreeview && (viewItem == localBranches || viewItem == localBranches.current)",
"group": "navigation"
},
{
"command": "gops.checkout",
"title": "Checkout Branch",
"when": "view == gitOpsTreeview && viewItem == localBranches",
"group": "navigation"
},
{
"command": "gops.stageFile",
"title": "Stage File",
"when": "view == gitOpsTreeview && viewItem == changedFile",
"group": "inline"
},
{
"command": "gops.unstageFile",
"title": "Unstage File",
"when": "view == gitOpsTreeview && viewItem == stagedFile",
"group": "inline"
},
{
"command": "gops.unstageAllFiles",
"title": "Unstage All Files",
"when": "view == gitOpsTreeview && viewItem == stagedChangesSection",
"group": "inline"
}
]
}
Expand All @@ -170,7 +215,7 @@
"check:types": "tsc --noEmit",
"lint": "eslint src",
"test:unit": "vitest run",
"test:integration": "vscode-test",
"test:integration": "npm run compile && npm run compile:tests && vscode-test",
"coverage:unit": "vitest run --coverage --coverage.reporter=lcov --coverage.reportsDirectory=coverage/unit",
"coverage:integration": "vscode-test --coverage --coverage-reporter lcov --coverage-output ./coverage/integration"
},
Expand Down
138 changes: 29 additions & 109 deletions src/commands/CommandRegistrar.ts
Original file line number Diff line number Diff line change
@@ -1,122 +1,43 @@
import * as vscode from "vscode";
import { TreeDataProvider } from "../gopstree/TreeDataProvider";
import { GitService } from "../services/GitService";
import { COMMANDS } from "./Commands";
import { GitTreeNode } from "../gopstree/types";
import { GitOperationsDelegate } from "./GitOperationsDelegate";
import { Logger } from "../logging/Logger";
import { DiffService } from "../services/DiffService";
import { ChangedFileNode } from "../gopstree/nodes/ChangedFileNode";

export class CommandRegistrar {
constructor(
private context: vscode.ExtensionContext,
private treeDataProvider: TreeDataProvider,
private gitService: GitService,
private diffService: DiffService,
private delegate: GitOperationsDelegate,
) {}

registerAll() {
this.register(COMMANDS.REFRESH, () => {
console.debug(`executed command: ${COMMANDS.REFRESH}`);
this.treeDataProvider.refresh();
});

this.register(COMMANDS.CHECKOUT_BRANCH, async (node: GitTreeNode) => {
console.debug(`executed command: ${COMMANDS.CHECKOUT_BRANCH}`);
if (node && "branchName" in node) {
await this.gitService.checkout(node.branchName);
this.treeDataProvider.refresh(node.parent);
}
});

this.register(COMMANDS.DELETE_BRANCH, async (node: GitTreeNode) => {
console.debug(`executed command: ${COMMANDS.DELETE_BRANCH}`);
//this.gitService.deleteBranch(node);
});

this.register(COMMANDS.RENAME_BRANCH, async (node: GitTreeNode) => {
console.debug(`executed command: ${COMMANDS.RENAME_BRANCH}`);
//this.gitService.renameBranch(node);
});

this.register(COMMANDS.PUSH, async () => {
console.debug(`executed command: ${COMMANDS.PUSH}`);
await this.gitService.push();
});

this.register(COMMANDS.PULL, async () => {
console.debug(`executed command: ${COMMANDS.PULL}`);
await this.gitService.pull();
});

this.register(COMMANDS.CREATE_BRANCH_FROM_CURRENT, async (node: GitTreeNode) => {
console.debug(`executed command: ${COMMANDS.CREATE_BRANCH_FROM_CURRENT}`);
const branchName: string | undefined = await vscode.window.showInputBox({
prompt: "Enter new branch name",
placeHolder: "feature/my-new-feature",
ignoreFocusOut: true,
});

if (!branchName) {
return;
}

await this.gitService.checkoutLocalBranch(branchName);
if (node?.parent) {
this.treeDataProvider.refresh(node.parent);
}
});

this.register(
COMMANDS.CREATE_BRANCH,
async (node: GitTreeNode) => {
console.debug(
`executed command: ${COMMANDS.CREATE_BRANCH}`,
);
if (!node || !("branchName" in node)) {
return;
}

const baseBranch = node?.branchName;
const branchName: string | undefined = await vscode.window.showInputBox(
{
prompt: `Enter new branch name to create from ${baseBranch}`,
placeHolder: "feature/my-new-feature",
ignoreFocusOut: true,
},
);

if (!branchName) {
return;
}

await this.gitService.checkoutBranch(branchName, baseBranch);
if (node?.parent) {
this.treeDataProvider.refresh(node.parent);
}
},
this.register(COMMANDS.REFRESH, () => this.delegate.refresh());
this.register(COMMANDS.CHECKOUT_BRANCH, (node) =>
this.delegate.checkoutBranch(node),
);

this.register(COMMANDS.SHOW_DIFF, async (node: GitTreeNode) => {
console.debug(`executed command: ${COMMANDS.SHOW_DIFF}`);
if (!node || !(node instanceof ChangedFileNode) || !node.fileName) {
return;
}
const repoPath = this.gitService.getRepoPath();

await this.diffService.openDiff({
left: {
repositoryPath: repoPath,
fileName: node.fileName,
ref: "HEAD",
},
right: {
repositoryPath: repoPath,
fileName: node.fileName,
},
title: `Diff: ${node.fileName}`,
});
});
this.register(COMMANDS.DELETE_BRANCH, (node) =>
this.delegate.deleteBranch(node),
);
this.register(COMMANDS.RENAME_BRANCH, (node) =>
this.delegate.renameBranch(node),
);
this.register(COMMANDS.PUSH, () => this.delegate.push());
this.register(COMMANDS.PULL, () => this.delegate.pull());
this.register(COMMANDS.CREATE_BRANCH_FROM_CURRENT, (node) =>
this.delegate.createBranchFromCurrent(node),
);
this.register(COMMANDS.CREATE_BRANCH, (node) =>
this.delegate.createBranchFrom(node),
);
this.register(COMMANDS.SHOW_DIFF, (node) => this.delegate.showDiff(node));
this.register(COMMANDS.STAGE_FILE, (node) => this.delegate.stageFile(node));
this.register(COMMANDS.UNSTAGE_FILE, (node) =>
this.delegate.unstageFile(node),
);
this.register(COMMANDS.UNSTAGE_ALL_FILES, () =>
this.delegate.unstageAllFiles(),
);
this.register(COMMANDS.COMMIT, () => this.delegate.commit());
this.register(COMMANDS.CREATE_TAG, () => this.delegate.createTag());
}

private register(
Expand All @@ -135,7 +56,6 @@ export class CommandRegistrar {
}
},
);

this.context.subscriptions.push(disposable);
}
}
4 changes: 4 additions & 0 deletions src/commands/Commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,8 @@ export const COMMANDS = {
CREATE_BRANCH: "gops.branch",
CREATE_TAG: "gops.tag",
SHOW_DIFF: "gops.showDiff",
STAGE_FILE: "gops.stageFile",
UNSTAGE_FILE: "gops.unstageFile",
UNSTAGE_ALL_FILES: "gops.unstageAllFiles",
COMMIT: "gops.commit",
} as const;
Loading
Loading