diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..28dc60f --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,31 @@ +name: CI + +on: + push: + branches: ["**"] + pull_request: + +concurrency: + group: ci-${{ github.ref }} + cancel-in-progress: true + +jobs: + ci: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + + - uses: actions/setup-node@v4 + with: + node-version: 22 + cache: npm + + - run: npm ci + - run: npm run lint --if-present + - run: npm run compile + + - name: Install xvfb + run: sudo apt-get update && sudo apt-get install -y xvfb + + - name: Test (VS Code) + run: xvfb-run -a npm test diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..2f54d6c --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,81 @@ +name: Release + +on: + workflow_dispatch: + inputs: + bump: + description: "Version bump type" + required: true + type: choice + options: [patch, minor, major] + +concurrency: + group: release + cancel-in-progress: false + +permissions: + contents: write + +jobs: + release: + runs-on: ubuntu-latest + steps: + - name: Checkout main (full history for tags) + uses: actions/checkout@v4 + with: + fetch-depth: 0 + ref: main + + - uses: actions/setup-node@v4 + with: + node-version: 22 + cache: npm + + - run: npm ci + - run: npm run lint --if-present + - run: npm run typecheck --if-present + - run: npm run compile + + - name: Install xvfb + run: sudo apt-get update && sudo apt-get install -y xvfb + + - name: Test (VS Code) + run: xvfb-run -a npm test + + - name: Configure git identity + run: | + git config user.name "github-actions[bot]" + git config user.email "github-actions[bot]@users.noreply.github.com" + + - name: Ensure working tree is clean + run: | + if [ -n "$(git status --porcelain)" ]; then + echo "Working tree is not clean." + git status --porcelain + exit 1 + fi + + - name: Bump version + create tag + id: bump + run: | + NEW_TAG="$(npm version ${{ inputs.bump }} -m "chore(release): v%s")" + echo "new_tag=$NEW_TAG" >> "$GITHUB_OUTPUT" + echo "Created tag: $NEW_TAG" + + - name: Push commit + tag + run: git push --follow-tags origin main + + - name: Package (vsix) + run: npx vsce package --no-dependencies + + - name: Publish to VS Code Marketplace + env: + VSCE_PAT: ${{ secrets.VSCE_PAT }} + run: npx vsce publish -p "$VSCE_PAT" + + - name: Create GitHub Release + upload VSIX + uses: softprops/action-gh-release@v2 + with: + tag_name: ${{ steps.bump.outputs.new_tag }} + generate_release_notes: true + files: "*.vsix" diff --git a/.vscode/extensions.json b/.vscode/extensions.json index 186459d..a208412 100644 --- a/.vscode/extensions.json +++ b/.vscode/extensions.json @@ -3,6 +3,7 @@ // for the documentation about the extensions.json format "recommendations": [ "dbaeumer.vscode-eslint", - "ms-vscode.extension-test-runner" + "ms-vscode.extension-test-runner", + "ozgen.git-worklists" ] } diff --git a/CHANGELOG.md b/CHANGELOG.md index 90a4888..afcea04 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,10 +7,26 @@ and adheres to Semantic Versioning. --- -## [0.0.1] - 2026-02-13 +## [Unreleased] + +- No changes yet + +--- + +## [0.0.2] - 2026-02-15 ### Added +- Discard button in the changelist + +### Fixed +- Correct staged count detection +- Push now sets upstream for new branches automatically + +--- +## [0.0.1] - 2026-02-13 + +### Added - Changelists view - Custom commit panel - Git staging support (`git add`, `git restore --staged`) @@ -26,9 +42,3 @@ and adheres to Semantic Versioning. - Clean stash label formatting - Context menu + inline icon actions - Error handling improvements - ---- - -## [Unreleased] - -- No changes yet diff --git a/README.md b/README.md index 0df4dca..2a73220 100644 --- a/README.md +++ b/README.md @@ -165,21 +165,37 @@ Planned improvements: # Release Notes +## 0.0.2 + +### Added + +* Discard action for files directly from the Changelists view + +### Fixed + +* Correct staged file detection (UI now accurately reflects Git index state) +* Automatic upstream setup when pushing new local branches +* Improved amend behavior when commit would otherwise be empty + +--- + ## 0.0.1 -- Changelists view -- Custom commit panel -- Git staging, commit, amend, push -- Per-changelist stash creation -- Dedicated Stashes view -- Apply / Pop / Delete stash actions -- Move files between changelists -- Move group to changelist -- Move selected files to changelist -- Improved reconciliation with Git status -- Clean stash label formatting -- Context menu + icon actions -- Error handling improvements +### Added + +* Changelists view +* Custom commit panel +* Git staging, commit, amend, push support +* Per-changelist stash creation +* Dedicated Stashes view +* Apply / Pop / Delete stash actions +* Move files between changelists +* Move group to changelist +* Move selected files to changelist +* Improved reconciliation with Git status +* Clean stash label formatting +* Context menu + icon actions +* Error handling improvements --- diff --git a/package.json b/package.json index 8c03524..e1dcb80 100644 --- a/package.json +++ b/package.json @@ -143,6 +143,11 @@ "command": "gitWorklists.stash.drop", "title": "Delete Stash", "icon": "$(trash)" + }, + { + "command": "gitWorklists.file.discard", + "title": "Discard", + "icon": "$(discard)" } ], "menus": { @@ -194,6 +199,11 @@ "when": "view == gitWorklists.changelists && viewItem == gitWorklists.file", "group": "inline@2" }, + { + "command": "gitWorklists.file.discard", + "when": "view == gitWorklists.changelists && viewItem == gitWorklists.file", + "group": "inline@3" + }, { "command": "gitWorklists.stash.createFromChangelist", "when": "view == gitWorklists.changelists && viewItem == gitWorklists.group.custom", @@ -228,7 +238,10 @@ "watch": "tsc -watch -p ./", "pretest": "npm run compile && npm run lint", "lint": "eslint src", - "test": "vscode-test" + "test": "vscode-test", + "release:patch": "npm version patch -m \"chore(release): v%s\"", + "release:minor": "npm version minor -m \"chore(release): v%s\"", + "release:major": "npm version major -m \"chore(release): v%s\"" }, "devDependencies": { "@types/vscode": "^1.109.0", diff --git a/src/extension.ts b/src/extension.ts index 5252d7f..c31ebb9 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -1,3 +1,5 @@ +import * as fs from "fs/promises"; +import * as path from "path"; import * as vscode from "vscode"; import { normalizeRepoRelPath, toRepoRelPath } from "./utils/paths"; @@ -54,6 +56,51 @@ async function getHeadMessage(repoRoot: string): Promise { return msg.trim(); } +async function getCurrentBranch(repoRoot: string): Promise { + const out = await runGitCapture(repoRoot, [ + "rev-parse", + "--abbrev-ref", + "HEAD", + ]); + const branch = out.trim(); + + if (!branch || branch === "HEAD") { + throw new Error("Detached HEAD: cannot push without a branch."); + } + return branch; +} + +function looksLikeNoUpstream(err: unknown): boolean { + const msg = String(err ?? ""); + return ( + msg.includes("no upstream branch") || + msg.includes("has no upstream branch") || + msg.includes("set the remote as upstream") || + (msg.includes("The current branch") && msg.includes("has no upstream")) + ); +} + +async function pushWithUpstreamFallback( + repoRoot: string, + { amend }: { amend: boolean }, +): Promise { + try { + await runGit(repoRoot, amend ? ["push", "--force-with-lease"] : ["push"]); + return; + } catch (e) { + if (!looksLikeNoUpstream(e)) { + throw e; + } + } + + const branch = await getCurrentBranch(repoRoot); + + const baseArgs = ["push", "-u", "origin", branch]; + const args = amend ? [...baseArgs, "--force-with-lease"] : baseArgs; + + await runGit(repoRoot, args); +} + export async function activate(context: vscode.ExtensionContext) { const workspaceFolder = vscode.workspace.workspaceFolders?.[0]; if (!workspaceFolder) { @@ -117,28 +164,45 @@ export async function activate(context: vscode.ExtensionContext) { const staged = await getStagedPaths(repoRoot); if (amend) { + const oldMsg = await getHeadMessage(repoRoot); + + // If nothing is staged, only allow amend when the message changes. if (staged.size === 0) { - const headEmpty = await isHeadEmptyVsParent(repoRoot); - const oldMsg = await getHeadMessage(repoRoot); - - // allow empty amend ONLY if message changes - if (newMsg !== oldMsg) { - await runGit(repoRoot, [ - "commit", - "--amend", - "--allow-empty", - "-m", - newMsg, - ]); - } else { + if (newMsg === oldMsg) { + const headEmpty = await isHeadEmptyVsParent(repoRoot); throw new Error( headEmpty ? "Nothing to amend: last commit is empty and message is unchanged." : "Nothing staged to amend. Stage files or disable Amend.", ); } + + // message-only amend + await runGit(repoRoot, [ + "commit", + "--amend", + "--allow-empty", + "-m", + newMsg, + ]); } else { - await runGit(repoRoot, ["commit", "--amend", "-m", newMsg]); + // staged amend (but Git may still complain it would become empty) + try { + await runGit(repoRoot, ["commit", "--amend", "-m", newMsg]); + } catch (e) { + const msg = String((e as any)?.message ?? e); + if (msg.includes("would make it empty")) { + await runGit(repoRoot, [ + "commit", + "--amend", + "--allow-empty", + "-m", + newMsg, + ]); + } else { + throw e; + } + } } } else { if (staged.size === 0) { @@ -168,11 +232,7 @@ export async function activate(context: vscode.ExtensionContext) { return; } - if (amend) { - await runGit(repoRoot, ["push", "--force-with-lease"]); - } else { - await runGit(repoRoot, ["push"]); - } + await pushWithUpstreamFallback(repoRoot, { amend }); }, ); @@ -219,12 +279,32 @@ export async function activate(context: vscode.ExtensionContext) { // ---------------------------- async function getStagedPaths(repoRoot: string): Promise> { const out = await runGitCapture(repoRoot, [ - "diff", - "--cached", - "--name-only", + "status", + "--porcelain=v1", "-z", ]); - return new Set(out.split("\0").filter(Boolean)); + + const staged = new Set(); + const entries = out.split("\0").filter(Boolean); + + for (const e of entries) { + // v1 format: XYpath + // "M file" => staged (index) + // " M file" => not staged (working tree) + // "?? file" => untracked + const xy = e.slice(0, 2); + const p = e.slice(3); + if (!p) { + continue; + } + + const x = xy[0]; // index status + if (x !== " " && x !== "?") { + staged.add(normalizeRepoRelPath(p)); + } + } + + return staged; } async function stagePaths(paths: string[]) { @@ -420,7 +500,7 @@ export async function activate(context: vscode.ExtensionContext) { if (!rel) { return; } - + await runGit(repoRoot, ["add", "--", normalizeRepoRelPath(rel)]); //Open File await vscode.commands.executeCommand("vscode.open", uri); @@ -575,6 +655,61 @@ export async function activate(context: vscode.ExtensionContext) { ), ); + context.subscriptions.push( + vscode.commands.registerCommand( + "gitWorklists.file.discard", + async (node: any) => { + try { + const rel = + typeof node?.repoRelativePath === "string" + ? normalizeRepoRelPath(node.repoRelativePath) + : ""; + if (!rel) { + return; + } + + const status = node?.workStatus as + | "unversioned" + | "tracked" + | undefined; + + if (status === "unversioned") { + const ok = await vscode.window.showWarningMessage( + "Delete unversioned file?", + { modal: true, detail: rel }, + "Delete", + ); + if (ok !== "Delete") { + return; + } + + await fs.rm(path.join(repoRoot, rel), { + recursive: true, + force: true, + }); + await coordinator.requestNow(); + return; + } + + // tracked: discard working tree changes + await runGit(repoRoot, [ + "restore", + "--staged", + "--worktree", + "--", + rel, + ]); + await coordinator.requestNow(); + } catch (e) { + console.error(e); + vscode.window.showErrorMessage( + "Git Worklists: discard failed (see console)", + ); + } + }, + ), + ); + // ---------------------------------- // Commands (context menus) for Stash // ---------------------------------- diff --git a/src/views/changelistTreeProvider.ts b/src/views/changelistTreeProvider.ts index cab0c3b..939c07f 100644 --- a/src/views/changelistTreeProvider.ts +++ b/src/views/changelistTreeProvider.ts @@ -13,6 +13,7 @@ abstract class Node extends vscode.TreeItem { } type GroupStageState = "all" | "none" | "mixed"; +type FileWorkStatus = "unversioned" | "tracked"; class GroupNode extends Node { readonly kind = "group" as const; @@ -47,6 +48,7 @@ class FileNode extends Node { repoRoot: vscode.Uri, public readonly repoRelativePath: string, public readonly isStaged: boolean, + public readonly workStatus: FileWorkStatus, ) { super(repoRelativePath, vscode.TreeItemCollapsibleState.None); @@ -159,7 +161,12 @@ export class ChangelistTreeProvider implements vscode.TreeDataProvider { return files.map((p) => { const norm = normalizeRepoRelPath(p); const staged = this.stagedPaths.has(norm); - return new FileNode(repoRoot, norm, staged); + const workStatus: FileWorkStatus = + element.list.id === SystemChangelist.Unversioned + ? "unversioned" + : "tracked"; + + return new FileNode(repoRoot, norm, staged, workStatus); }); }