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
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

### Added

- Added keyboard shortcuts for committing and uncommitting patches (i.e. `stg commit` and `stg uncommit`) using the `ctrl+shift+.` and `ctrl+shift+,` keybindings.

## [2.0.0] - 2026-12-01

### Changed
Expand Down
22 changes: 21 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,16 @@
"category": "StGit",
"title": "Convert Patches to GIT Commits (or vice versa)"
},
{
"command": "stgit.commitPatch",
"category": "StGit",
"title": "Commit Bottom Patch"
},
{
"command": "stgit.uncommitPatch",
"category": "StGit",
"title": "Uncommit Git Commit"
},
{
"command": "stgit.toggleChanges",
"category": "StGit",
Expand Down Expand Up @@ -531,7 +541,7 @@
"when": "activeWebviewPanelId == stgit && !stgitEditing && !inQuickOpen && !terminalFocus && !inputFocus"
},
{
"key": "ctrl+c u",
"key": "ctrl+c shift+u",
"command": "stgit.selectUpstreamBranch",
"when": "activeWebviewPanelId == stgit && !stgitEditing && !inQuickOpen && !terminalFocus && !inputFocus"
},
Expand Down Expand Up @@ -570,6 +580,16 @@
"command": "stgit.commitOrUncommitPatches",
"when": "activeWebviewPanelId == stgit && !stgitEditing && !inQuickOpen && !terminalFocus && !inputFocus"
},
{
"key": "ctrl+shift+.",
"command": "stgit.commitPatch",
"when": "activeWebviewPanelId == stgit && !stgitEditing && !inQuickOpen && !terminalFocus && !inputFocus"
},
{
"key": "ctrl+shift+,",
"command": "stgit.uncommitPatch",
"when": "activeWebviewPanelId == stgit && !stgitEditing && !inQuickOpen && !terminalFocus && !inputFocus"
},
{
"key": "h",
"command": "stgit.help",
Expand Down
10 changes: 10 additions & 0 deletions src/stgit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1499,6 +1499,14 @@ class StGitDoc {
}
this.reload();
}
async commitPatch() {
await runAndReportErrors("stg", ["commit"]);
this.reload();
}
async uncommitPatch() {
await runAndReportErrors("stg", ["uncommit", "-n1"]);
this.reload();
}
toggleShowingUnknownFiles() {
this.unknownFilesVisible = !this.unknownFilesVisible;
this.reloadWorkTree();
Expand Down Expand Up @@ -1625,6 +1633,8 @@ class StGitMode {
cmd("openDiff", () => this.stgit?.openDiff()),
cmd("setHistorySize", () => this.stgit?.setHistorySize()),
cmd("commitOrUncommitPatches", () => this.stgit?.commitOrUncommitPatches()),
cmd("commitPatch", () => this.stgit?.commitPatch()),
cmd("uncommitPatch", () => this.stgit?.uncommitPatch()),
cmd("revertChanges", () => this.stgit?.revertChanges()),
cmd("undo", () => this.stgit?.undo()),
cmd("hardUndo", () => this.stgit?.hardUndo()),
Expand Down
48 changes: 48 additions & 0 deletions src/test/suite/extension.test.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
import * as assert from "assert";
import { execFileSync } from "child_process";
import * as fs from "fs/promises";
import * as path from "path";

// You can import and use all API from the 'vscode' module
// as well as import your extension to test it
import * as vscode from "vscode";
import { CommentDraft } from "../../comment-discard";
import { findHunkTargetLine, HunkTarget } from "../../diff-mode";
import { RepoReader } from "../../repo-reader";
import { RepositoryInfo } from "../../repo";
import { correspondingLine } from "../../stage-selection";
import { formatCommitDescription, History, StGitPatch, WorkTree } from "../../stgit";

Expand Down Expand Up @@ -331,6 +335,50 @@ suite("Extension Test Suite", () => {
assert.ok(registered.includes("stgit.submitComment"));
});

test("Commits and uncommits one patch independently of the selected row", async function () {
this.timeout(30000);
const temporaryRoot = path.resolve(__dirname, "../../../.tmp");
await fs.mkdir(temporaryRoot, { recursive: true });
await fs.writeFile(path.join(temporaryRoot, ".gitignore"), "*\n", { flag: "wx" }).catch((error: NodeJS.ErrnoException) => {
if (error.code !== "EEXIST") {
throw error;
}
});
const dir = await fs.mkdtemp(path.join(temporaryRoot, "conversion-"));
const previousRepo = await RepositoryInfo.getSelectedRepo();
const execute = (command: string, ...args: string[]) => execFileSync(command, args, { cwd: dir, encoding: "utf8" }).trim();
try {
execute("git", "init", "-q");
execute("git", "config", "user.name", "Test");
execute("git", "config", "user.email", "test@example.org");
const file = path.join(dir, "file.txt");
await fs.writeFile(file, "base\n");
execute("git", "add", "file.txt");
execute("git", "commit", "-qm", "base");
execute("stg", "init");
for (const name of ["first", "second"]) {
execute("stg", "new", "-m", name, name);
await fs.appendFile(file, `${name}\n`);
execute("stg", "refresh");
}
const head = execute("git", "rev-parse", "HEAD");
await vscode.extensions.getExtension("cedernaes.stgit-revived")!.activate();
await vscode.window.showTextDocument(await vscode.workspace.openTextDocument(file));
await vscode.commands.executeCommand("stgit.open");
await vscode.commands.executeCommand("stgit.commitPatch");
assert.strictEqual(execute("stg", "series", "--applied", "--noprefix"), "second");
assert.strictEqual(execute("git", "rev-parse", "HEAD"), head);
await vscode.commands.executeCommand("stgit.uncommitPatch");
assert.strictEqual(execute("stg", "series", "--applied", "--noprefix"), "first\nsecond");
assert.strictEqual(execute("git", "rev-parse", "HEAD"), head);
} finally {
await vscode.commands.executeCommand("workbench.action.closeActiveEditor");
await vscode.commands.executeCommand("workbench.action.closeActiveEditor");
RepositoryInfo.setSelectedRepo(previousRepo);
await fs.rm(dir, { recursive: true, force: true });
}
});

test("Keeps the cursor on its file when a redraw changes line counts", () => {
const before = "Branch\nIndex\n Modified file-a\nWork Tree";
const after = "Branch\nIndex\n Modified file-b\n" + " Modified file-a\nWork Tree";
Expand Down