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
11 changes: 10 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,13 @@ surface, and the HTTP API may change in any minor release.

## [Unreleased]

## [0.15.0] - 2026-11-04

### Added

- **Open in editor.** A toolbar button beside the GitHub link opens the repo in your
editor. Defaults to VS Code (`code`); set any other command in Settings → Editor command.

## [0.14.0] - 2026-10-21

### Added
Expand Down Expand Up @@ -330,7 +337,9 @@ First public release.
- Windows (arm64, x64): builds and runs, but untested on real hardware — recursive `fs.watch` crashes the test worker there, so auto-refresh is not covered by CI
- Linux: everything except the terminal — node-pty is an optionalDependency with no Linux prebuild, and the terminal button is hidden when it is unavailable

[Unreleased]: https://github.com/vuongvu1/megit/compare/v0.13.0...HEAD
[Unreleased]: https://github.com/vuongvu1/megit/compare/v0.15.0...HEAD
[0.15.0]: https://github.com/vuongvu1/megit/compare/v0.14.0...v0.15.0
[0.14.0]: https://github.com/vuongvu1/megit/compare/v0.13.0...v0.14.0
[0.13.0]: https://github.com/vuongvu1/megit/compare/v0.12.2...v0.13.0
[0.12.2]: https://github.com/vuongvu1/megit/compare/v0.12.1...v0.12.2
[0.12.1]: https://github.com/vuongvu1/megit/compare/v0.12.0...v0.12.1
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ If what you want is further back than the rows you've loaded, the globe button r

megit started as a viewer, but the common operations are here:

- **Toolbar** — pull (fast-forward only), push, create branch, stash all, pop latest stash, undo last commit (soft reset, keeps changes staged)
- **Toolbar** — pull (fast-forward only), push, create branch, stash all, pop latest stash, undo last commit (soft reset, keeps changes staged), open the repo in your editor
- **Ref chips** — checkout, create branch here, rename, delete, set upstream, merge, rebase, delete tag, copy name, copy GitHub link
- **Commit rows** — checkout, cherry-pick, revert, reset (soft / mixed / hard), copy hash, copy GitHub link
- **Files** — stage, unstage, discard, commit, amend the last commit (message, staged changes, or both)
Expand All @@ -126,7 +126,7 @@ The cog at the right end of the tab bar opens font (bundled Ubuntu Mono, your sy
monospace, or your system UI face), text size in four steps from 80% to 140%, the theme, the default diff
view, how many commits each graph request loads (100–1000, default 150), and a toggle for
author avatars — off stops the GitHub and Gravatar lookups megit otherwise makes per commit
author. The same dialog lists every keyboard shortcut below, and the two mouse gestures:
author, and the editor command the toolbar's editor button runs (default `code`). The same dialog lists every keyboard shortcut below, and the two mouse gestures:
double-click a branch chip to check it out, right-click a row for its actions.

### Keyboard
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "megit-app",
"version": "0.14.0",
"version": "0.15.0",
"description": "Git repository viewer in the browser: commit graph with branch lanes, diffs, stashes and WIP",
"license": "MIT",
"author": "Hoang Vuong Vu",
Expand Down
26 changes: 25 additions & 1 deletion server/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { createApp, serveStatic, type Handler } from './http.ts'
import { execFile } from 'node:child_process'
import { execFile, spawn } from 'node:child_process'
import { existsSync, readdirSync, readFileSync } from 'node:fs'
import { readFile, realpath, writeFile } from 'node:fs/promises'
import { homedir } from 'node:os'
Expand Down Expand Up @@ -297,6 +297,30 @@ app.get('/api/worktrees', repoGuard, async (req, res) => {
}
})

// Opens the repo in the user's editor. The command comes from the client's
// settings — no new capability, /api/term already runs anything, and the Host pin
// keeps foreign pages out. No shell: the command splits on whitespace and the repo
// path is its own argv entry, so neither can inject. Answers once the process has
// either spawned or failed, so a missing `code` reaches the user as an error.
// ponytail: whitespace split — an editor path containing spaces needs a PATH entry
// instead. Windows .cmd shims (code.cmd) can't spawn without a shell; unverified there.
app.post('/api/open-editor', repoGuard, (req, res) => {
const argv = typeof req.body.cmd === 'string' ? req.body.cmd.trim().split(/\s+/).filter(Boolean) : []
if (!argv.length) {
res.status(400).json({ error: 'no editor command set' })
return
}
const child = spawn(argv[0], [...argv.slice(1), String(req.query.repo)], { detached: true, stdio: 'ignore' })
child.once('spawn', () => {
child.unref()
res.json({ ok: true })
})
child.once('error', e => {
const notFound = (e as NodeJS.ErrnoException).code === 'ENOENT'
res.status(notFound ? 404 : 500).json({ error: notFound ? `"${argv[0]}" not found — set your editor in Settings` : e.message })
})
})

// Removes a linked worktree. The path is allow-listed against git's own list, minus
// [0] (the main worktree, which git can't remove). Without force, git refuses a
// worktree with uncommitted or untracked files — the client only sends force after
Expand Down
12 changes: 11 additions & 1 deletion src/RepoView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import type { Worktree } from '../server/worktrees.ts'
import WorktreeStrip from './WorktreeStrip'
import { label, matchLocal, stepMatch } from './search'
import { toastErr } from './Toast'
import { useSetting } from './settingsStore'
import { getSettings, useSetting } from './settingsStore'
import { tilde } from './paths'

// diff2html + highlight.js (~1 MB, 82% of the old main bundle) stay out until a
Expand Down Expand Up @@ -442,6 +442,16 @@ export default function RepoView({ repo, home, linked, onOpen, onRemove, hasTerm
<GithubIcon size={14} />
</a>
)}
<button
className="editor-btn"
onClick={() => api(`/api/open-editor?${q}`, jsonInit('POST', { cmd: getSettings().editor })).catch(e => toastErr(e.message))}
title="Open in editor"
aria-label="Open in editor"
>
<svg viewBox="0 0 24 24" width="14" height="14" fill="none" stroke="currentColor" strokeWidth="2.2" strokeLinecap="round" strokeLinejoin="round" aria-hidden="true">
<path d="M8 6l-6 6 6 6M16 6l6 6-6 6" />
</svg>
</button>
<button className="refresh-btn" onClick={() => refresh()} title="Fetch & refresh (r)" aria-label="Fetch and refresh">
<svg className={spinning ? 'spin' : undefined} onAnimationIteration={() => { if (!inflight.current) setSpinning(false) }} viewBox="0 0 24 24" width="13" height="13" fill="none" stroke="currentColor" strokeWidth="2.5" strokeLinecap="round" strokeLinejoin="round">
<path d="M3 12a9 9 0 0 1 9-9 9.75 9.75 0 0 1 6.74 2.74L21 8" />
Expand Down
17 changes: 17 additions & 0 deletions src/SettingsDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,23 @@ export default function Settings({ onClose }: { onClose: () => void }) {
while scrolling, and a slower first paint on a big repository. Search matches only the
commits already loaded — “Search all history” in the search bar reaches past them.
</div>
<div className="settings-row">
<label htmlFor="set-editor">Editor command</label>
<input
id="set-editor"
type="text"
spellCheck={false}
autoComplete="off"
placeholder={DEFAULTS.editor}
value={s.editor}
onChange={e => setSetting('editor', e.target.value)}
/>
</div>
<div className="settings-warn">
Run by the toolbar’s editor button with the repository path appended — <code>code</code>,{' '}
<code>cursor</code>, <code>zed</code>, <code>subl</code>. Must be on the PATH of the shell
that started megit.
</div>
<div className="settings-row">
{/* The label is no longer a control's label, so it needs an id the
group points back to — a bare <label> beside a button pair
Expand Down
6 changes: 6 additions & 0 deletions src/settings.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,12 @@ describe('parse', () => {
expect(parse('{"pageSize":"200"}', DEFAULTS).pageSize).toBe(DEFAULTS.pageSize)
})

it('keeps a stored editor command and falls back for a blank one', () => {
expect(parse('{"editor":"cursor -n"}', DEFAULTS).editor).toBe('cursor -n')
expect(parse('{"editor":" "}', DEFAULTS).editor).toBe('code')
expect(parse('{"editor":3}', DEFAULTS).editor).toBe('code')
})

it('honours a caller-supplied default, for the diff-split migration', () => {
const migrated = { ...DEFAULTS, diffSplit: true }
expect(parse(null, migrated).diffSplit).toBe(true)
Expand Down
3 changes: 3 additions & 0 deletions src/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ export type Settings = {
avatars: boolean
diffSplit: boolean
pageSize: number // commits fetched per /api/graph request
editor: string // command the toolbar's editor button runs with the repo path appended
}

export const ZOOM_MIN = 0.8
Expand Down Expand Up @@ -36,6 +37,7 @@ export const DEFAULTS: Settings = {
avatars: true,
diffSplit: false,
pageSize: 150,
editor: 'code',
}

// Snap before clamping so a float that arrived from repeated += 0.1 lands on a
Expand All @@ -62,6 +64,7 @@ export function parse(raw: string | null, defaults: Settings): Settings {
// Allow-list rather than a clamp: an arbitrary stored number would light no
// option in the dialog and could ask the server for a page it caps anyway.
pageSize: PAGE_SIZES.includes(o.pageSize as (typeof PAGE_SIZES)[number]) ? o.pageSize! : defaults.pageSize,
editor: typeof o.editor === 'string' && o.editor.trim() ? o.editor : defaults.editor,
}
}

Expand Down
7 changes: 5 additions & 2 deletions src/styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -235,8 +235,11 @@ button:hover { background: var(--border); }
.tb-btn:disabled { opacity: .4; cursor: default; }
.tb-badge { min-width: 15px; padding: 0 4px; border-radius: 7px; background: var(--bg-selected); color: var(--fg); font-size: 11px; line-height: 15px; text-align: center; }
.repo-path { min-width: 0; color: var(--fg-dim); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.github-link { display: inline-flex; align-items: center; color: var(--fg-dim); flex-shrink: 0; }
.github-link:hover { color: var(--fg); }
.github-link { display: inline-flex; align-items: center; padding: 3px 4px; border-radius: 4px; color: var(--fg-dim); flex-shrink: 0; }
/* .toolbar-scoped to outrank `.toolbar button` padding and `button:hover` fill, so
the editor button and the GitHub link share one look */
.toolbar .editor-btn { display: inline-flex; align-items: center; padding: 3px 4px; color: var(--fg-dim); background: none; border-color: transparent; flex-shrink: 0; }
.github-link:hover, .toolbar .editor-btn:hover { color: var(--fg); background: var(--bg-hover); }
.term-btn { display: inline-flex; align-items: center; padding: 3px 5px; color: var(--fg-dim); }
.term-btn:hover { color: var(--fg); }
.term-btn.active { color: var(--fg); background: var(--bg-selected); }
Expand Down
Loading