Skip to content
Open
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
2 changes: 2 additions & 0 deletions docs/site/content/docs/review/commit-push.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ Amending is explicit — **Commit → Amend**. Orca won't amend commits that hav

The sidebar **Source Control** panel exposes the same actions without leaving your current view: stage and discard files, write a commit message, and run **Commit**, **Push**, **Pull**, or **Sync** as one-click actions. Paths render as UTF-8 even when they contain non-ASCII characters.

Discarding unstaged changes restores tracked files to their staged contents and removes only the selected untracked paths; it does not unstage changes. On macOS, Linux, and POSIX SSH hosts, a backslash is a literal filename character: `docs\file.txt` and `docs/file.txt` remain separate discard targets.

The branch context row at the top shows the current branch (or detached HEAD) stacked above the compare base (`branch → base`) so Create PR and remote actions never hide which branch you're on. When the branch has a usable merge base, a compact chip shows total lines added and removed against that fork point (one ranged diff, not a sum of staged/unstaged areas). Hover the chip for a **Code breakdown** when the host publishes splits: **Source**, **Tests**, and **Generated** (generated only when non-zero) — path heuristics only, not content analysis. Long branch names truncate so they do not cover the chip.

**Committed on Branch** shows changes since the common ancestor with the selected base. Changes made only on the base branch are excluded. If an untracked file overlaps a file deleted or renamed from that ancestor, the line-total chip clears any previously shown number until an exact total is available again. Staging the file restores an exact total.
Expand Down
118 changes: 118 additions & 0 deletions src/main/git/source-control/discard-backslash-paths.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
import { mkdtemp, mkdir, readFile, rm, writeFile } from 'node:fs/promises'
import { tmpdir } from 'node:os'
import * as path from 'node:path'
import { afterEach, beforeEach, describe, expect, it } from 'vitest'
import { runProcess } from '@orca/process-host'
import { createGlobalSettingsFixture } from '../../../shared/global-settings-test-fixture'
import { RuntimeGitStagingCommands } from '../../runtime/integrations/git/runtime-git-staging-commands'
import { bulkDiscardChanges } from './discard-changes'

// Windows filenames cannot contain literal backslashes.
describe.skipIf(process.platform === 'win32')('discard preserves POSIX path identity', () => {
let repo: string
let commands: RuntimeGitStagingCommands

async function git(args: string[]): Promise<string> {
const result = await runProcess({
program: 'git',
args: ['-c', 'commit.gpgsign=false', ...args],
cwd: repo,
env: {
...process.env,
GIT_AUTHOR_NAME: 'Test User',
GIT_AUTHOR_EMAIL: 'test@example.com',
GIT_COMMITTER_NAME: 'Test User',
GIT_COMMITTER_EMAIL: 'test@example.com'
}
})
expect(result.code, result.stderr).toBe(0)
return result.stdout
}

beforeEach(async () => {
repo = await mkdtemp(path.join(tmpdir(), 'orca-discard-paths-'))
await git(['init'])
const gitInfo = {
path: repo,
head: 'a'.repeat(40),
branch: 'main',
isBare: false,
isMainWorktree: true
}
commands = new RuntimeGitStagingCommands({
resolveRuntimeGitTarget: async () => ({
executionHostId: 'local',
worktree: {
...gitInfo,
git: gitInfo,
id: 'wt-1',
repoId: 'repo-1',
displayName: 'Test repository',
comment: '',
linkedIssue: null,
linkedPR: null,
linkedLinearIssue: null,
isArchived: false,
isUnread: false,
isPinned: false,
sortOrder: 0,
lastActivityAt: 0
}
}),
getRuntimeSettings: () => createGlobalSettingsFixture()
})
})

afterEach(async () => {
await rm(repo, { recursive: true, force: true })
})

for (const host of ['native', 'runtime'] as const) {
it.each([
{ tracked: 'docs/file.txt', untracked: 'docs\\file.txt', untrackedFile: 'docs\\file.txt' },
{ tracked: 'docs\\file.txt', untracked: 'docs/file.txt', untrackedFile: 'docs/file.txt' },
{ tracked: 'docs\\file.txt', untracked: 'docs', untrackedFile: 'docs/scratch.txt' }
])(`discards $untracked separately from tracked $tracked on ${host}`, async (fixture) => {
const trackedFile = path.join(repo, fixture.tracked)
await mkdir(path.dirname(trackedFile), { recursive: true })
await writeFile(trackedFile, 'committed\n')
await git(['add', '.'])
await git(['commit', '-m', 'initial'])
await writeFile(trackedFile, 'staged\n')
await git(['add', '--', `:(literal)${fixture.tracked}`])
await writeFile(trackedFile, 'modified\n')

const untrackedFile = path.join(repo, fixture.untrackedFile)
await mkdir(path.dirname(untrackedFile), { recursive: true })
await writeFile(untrackedFile, 'untracked\n')
await writeFile(path.join(repo, 'leave.txt'), 'unselected\n')

const filePaths = [fixture.tracked, fixture.untracked]
await (host === 'native'
? bulkDiscardChanges(repo, filePaths)
: commands.bulkDiscardRuntimeGitPaths('id:wt-1', filePaths))

expect(await readFile(trackedFile, 'utf8')).toBe('staged\n')
expect(await git(['show', `:${fixture.tracked}`])).toBe('staged\n')
await expect(readFile(untrackedFile, 'utf8')).rejects.toMatchObject({ code: 'ENOENT' })
expect(await readFile(path.join(repo, 'leave.txt'), 'utf8')).toBe('unselected\n')
})
}

it('discards a literal-backslash file without touching its slash-named neighbor on runtime', async () => {
await mkdir(path.join(repo, 'docs'))
await writeFile(path.join(repo, 'docs/file.txt'), 'keep\n')
await writeFile(path.join(repo, 'docs\\file.txt'), 'committed\n')
await git(['add', '.'])
await git(['commit', '-m', 'initial'])
await writeFile(path.join(repo, 'docs/file.txt'), 'unselected modification\n')
await writeFile(path.join(repo, 'docs\\file.txt'), 'selected modification\n')

await commands.discardRuntimeGitPath('id:wt-1', 'docs\\file.txt')

expect(await readFile(path.join(repo, 'docs\\file.txt'), 'utf8')).toBe('committed\n')
expect(await readFile(path.join(repo, 'docs/file.txt'), 'utf8')).toBe(
'unselected modification\n'
)
})
})
6 changes: 5 additions & 1 deletion src/main/git/source-control/discard-changes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,11 @@ export async function bulkDiscardChanges(
}

const trackedPathSpecs = await listTrackedPathSpecs(worktreePath, filePaths, options)
const { trackedPaths, untrackedPaths } = partitionTrackedPathSpecs(filePaths, trackedPathSpecs)
const { trackedPaths, untrackedPaths } = partitionTrackedPathSpecs(
filePaths,
trackedPathSpecs,
process.platform === 'win32' || Boolean(options.wslDistro)
)
await removeSafeUntrackedDiscardTargets(
worktreePath,
untrackedPaths,
Expand Down
7 changes: 5 additions & 2 deletions src/main/git/source-control/git-blob-read.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { readFile, stat } from 'node:fs/promises'
import { isBinaryBuffer } from '../../../shared/file-preview/binary-buffer'
import { isWindowsAbsolutePathLike } from '../../../shared/cross-platform-path'
import { isMissingGitBlobPath } from '../../../shared/git/diff/git-blob-absence'
import { readGitCommandFailureStderr } from '../../../shared/git/commands/git-command-failure-text'
import type { GitRuntimeOptions } from '../git-runtime-options'
Expand Down Expand Up @@ -84,8 +85,10 @@ async function readGitBlob(
options: GitRuntimeOptions,
conversion: BlobConversion | undefined
): Promise<GitBlobReadResult> {
// Git blob syntax requires forward slashes, including on Windows.
const gitPath = filePath.replace(/\\/g, '/')
const gitPath =
isWindowsAbsolutePathLike(worktreePath) || options.wslDistro
? filePath.replace(/\\/g, '/')
: filePath
const spec = `${oid ?? ''}:${gitPath}`
const readOptions = {
...gitReadOptionsForWorktree(worktreePath, options),
Expand Down
11 changes: 9 additions & 2 deletions src/main/runtime/integrations/git/runtime-git-command-target.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,15 @@ export function localGitOptionsForTarget(target: RuntimeGitTarget): GitRuntimeOp
return target.executionHostId === LOCAL_EXECUTION_HOST_ID ? (target.localGitOptions ?? {}) : {}
}

export function normalizeRuntimeGitRelativePath(filePath: string): string {
const relativePath = normalizeRuntimeRelativePath(filePath)
export function normalizeRuntimeGitRelativePath(
filePath: string,
target: RuntimeGitTarget
): string {
const rootPath =
target.executionHostId === LOCAL_EXECUTION_HOST_ID && target.localGitOptions?.wslDistro
? undefined
: target.worktree.path
const relativePath = normalizeRuntimeRelativePath(filePath, rootPath)
if (relativePath === '') {
// Why: an empty Git pathspec can mutate the whole worktree.
throw new Error('invalid_relative_path')
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
import { mkdir, mkdtemp, rename, rm, writeFile } from 'node:fs/promises'
import { tmpdir } from 'node:os'
import * as path from 'node:path'
import { runProcess } from '@orca/process-host'
import { afterEach, describe, expect, it } from 'vitest'
import { createGlobalSettingsFixture } from '../../../../shared/global-settings-test-fixture'
import type { RuntimeGitTarget } from './runtime-git-command-target'
import { RuntimeGitDiffCommands } from './runtime-git-diff-commands'

function commands(root: string, localGitOptions?: RuntimeGitTarget['localGitOptions']) {
const gitInfo = {
path: root,
head: 'a'.repeat(40),
branch: 'main',
isBare: false,
isMainWorktree: true
}
return new RuntimeGitDiffCommands({
resolveRuntimeGitTarget: async () => ({
executionHostId: 'local',
localGitOptions,
worktree: {
...gitInfo,
git: gitInfo,
id: 'wt-1',
repoId: 'repo-1',
displayName: 'Test repository',
comment: '',
linkedIssue: null,
linkedPR: null,
linkedLinearIssue: null,
isArchived: false,
isUnread: false,
isPinned: false,
sortOrder: 0,
lastActivityAt: 0
}
}),
getRuntimeSettings: () => createGlobalSettingsFixture()
})
}

describe.skipIf(process.platform === 'win32')('runtime commit diff POSIX path identity', () => {
let repo: string | undefined

afterEach(async () => {
if (repo) {
await rm(repo, { recursive: true, force: true })
}
})

it.each([false, true])('reads literal backslashes with rename=%s', async (renamed) => {
repo = await mkdtemp(path.join(tmpdir(), 'orca-commit-diff-paths-'))
const root = repo
const git = async (args: string[]): Promise<string> => {
const result = await runProcess({
program: 'git',
args,
cwd: root,
env: {
...process.env,
GIT_AUTHOR_NAME: 'Test User',
GIT_AUTHOR_EMAIL: 'test@example.com',
GIT_COMMITTER_NAME: 'Test User',
GIT_COMMITTER_EMAIL: 'test@example.com'
}
})
expect(result.code, result.stderr).toBe(0)
return result.stdout.trim()
}
const filePath = 'docs\\file.txt'
const oldPath = renamed ? 'docs\\old-file.txt' : filePath
await git(['init'])
await mkdir(path.join(root, 'docs'))
await writeFile(path.join(root, 'docs/file.txt'), 'nested current\n')
await writeFile(path.join(root, 'docs/old-file.txt'), 'nested previous\n')
await writeFile(path.join(root, oldPath), 'literal original\n')
await git(['add', '.'])
await git(['-c', 'commit.gpgsign=false', 'commit', '-m', 'initial'])
const parentOid = await git(['rev-parse', 'HEAD'])
if (renamed) {
await rename(path.join(root, oldPath), path.join(root, filePath))
}
await writeFile(path.join(root, filePath), 'literal modified\n')
await git(['add', '.'])
await git(['-c', 'commit.gpgsign=false', 'commit', '-m', 'update'])
const commitOid = await git(['rev-parse', 'HEAD'])

await expect(
commands(root).getRuntimeGitCommitDiff('id:wt-1', {
commitOid,
parentOid,
filePath,
...(renamed ? { oldPath } : {})
})
).resolves.toMatchObject({
kind: 'text',
originalContent: 'literal original\n',
modifiedContent: 'literal modified\n'
})
})
})
17 changes: 9 additions & 8 deletions src/main/runtime/integrations/git/runtime-git-diff-commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import type {
import { assertGitDiffWithinTransportBudget } from '../../../../shared/git/diff/git-diff-transport-budget'
import { getBranchDiff } from '../../../git/source-control/branch-diff'
import type { GitAdmissionTier } from '../../../../shared/rpc-contract/git-admission-tier-params'
import { normalizeRuntimeRelativePath } from '../../files/paths/runtime-relative-paths'
import {
localGitOptionsForTarget,
normalizeRuntimeGitRelativePath,
Expand All @@ -28,8 +27,8 @@ export class RuntimeGitDiffCommands {
oldPath?: string
): Promise<GitDiffResult> {
const target = await this.host.resolveRuntimeGitTarget(worktreeSelector)
const relativePath = normalizeRuntimeGitRelativePath(filePath)
const oldRelativePath = oldPath ? normalizeRuntimeGitRelativePath(oldPath) : undefined
const relativePath = normalizeRuntimeGitRelativePath(filePath, target)
const oldRelativePath = oldPath ? normalizeRuntimeGitRelativePath(oldPath, target) : undefined
return assertGitDiffWithinTransportBudget(
await requireRuntimeGitProvider(target).getDiff(
target.worktree.path,
Expand Down Expand Up @@ -69,8 +68,8 @@ export class RuntimeGitDiffCommands {
maxContentBytes?: number
): Promise<GitDiffResult> {
const target = await this.host.resolveRuntimeGitTarget(worktreeSelector)
const relativePath = normalizeRuntimeGitRelativePath(filePath)
const oldRelativePath = oldPath ? normalizeRuntimeGitRelativePath(oldPath) : undefined
const relativePath = normalizeRuntimeGitRelativePath(filePath, target)
const oldRelativePath = oldPath ? normalizeRuntimeGitRelativePath(oldPath, target) : undefined
requireLocalRuntimeGitRoute(target)
return assertGitDiffWithinTransportBudget(
await getBranchDiff(
Expand All @@ -96,8 +95,10 @@ export class RuntimeGitDiffCommands {
maxContentBytes?: number
): Promise<GitDiffResult> {
const target = await this.host.resolveRuntimeGitTarget(worktreeSelector)
const relativePath = normalizeRuntimeRelativePath(args.filePath)
const oldRelativePath = args.oldPath ? normalizeRuntimeRelativePath(args.oldPath) : undefined
const relativePath = normalizeRuntimeGitRelativePath(args.filePath, target)
const oldRelativePath = args.oldPath
? normalizeRuntimeGitRelativePath(args.oldPath, target)
: undefined
return assertGitDiffWithinTransportBudget(
await requireRuntimeGitProvider(target).getCommitDiff(target.worktree.path, {
commitOid: args.commitOid,
Expand All @@ -116,7 +117,7 @@ export class RuntimeGitDiffCommands {
endLine?: number
): Promise<string | null> {
const target = await this.host.resolveRuntimeGitTarget(worktreeSelector)
const normalizedRelativePath = normalizeRuntimeGitRelativePath(relativePath)
const normalizedRelativePath = normalizeRuntimeGitRelativePath(relativePath, target)
return requireRuntimeGitProvider(target).getRemoteFileUrl(
target.worktree.path,
normalizedRelativePath,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export class RuntimeGitStagingCommands {

async stageRuntimeGitPath(worktreeSelector: string, filePath: string): Promise<{ ok: true }> {
const target = await this.host.resolveRuntimeGitTarget(worktreeSelector)
const relativePath = normalizeRuntimeGitRelativePath(filePath)
const relativePath = normalizeRuntimeGitRelativePath(filePath, target)
await requireRuntimeGitProvider(target).stageFile(target.worktree.path, relativePath)
return { ok: true }
}
Expand All @@ -25,7 +25,7 @@ export class RuntimeGitStagingCommands {
resolution: ConflictResolution
): Promise<{ ok: true }> {
const target = await this.host.resolveRuntimeGitTarget(worktreeSelector)
const relativePath = normalizeRuntimeGitRelativePath(filePath)
const relativePath = normalizeRuntimeGitRelativePath(filePath, target)
await requireRuntimeGitProvider(target).resolveConflict(
target.worktree.path,
relativePath,
Expand All @@ -36,7 +36,7 @@ export class RuntimeGitStagingCommands {

async unstageRuntimeGitPath(worktreeSelector: string, filePath: string): Promise<{ ok: true }> {
const target = await this.host.resolveRuntimeGitTarget(worktreeSelector)
const relativePath = normalizeRuntimeGitRelativePath(filePath)
const relativePath = normalizeRuntimeGitRelativePath(filePath, target)
await requireRuntimeGitProvider(target).unstageFile(target.worktree.path, relativePath)
return { ok: true }
}
Expand All @@ -47,7 +47,7 @@ export class RuntimeGitStagingCommands {
scope?: GitStageWorktreeScope
): Promise<{ ok: true } & Partial<GitStageWorktreeScopeReceipt>> {
const target = await this.host.resolveRuntimeGitTarget(worktreeSelector)
const relativePaths = filePaths.map((path) => normalizeRuntimeGitRelativePath(path))
const relativePaths = filePaths.map((path) => normalizeRuntimeGitRelativePath(path, target))
// Why: every provider throws when its host did not run the scoped stage, so success is a receipt.
await requireRuntimeGitProvider(target).bulkStageFiles(
target.worktree.path,
Expand All @@ -62,7 +62,7 @@ export class RuntimeGitStagingCommands {
filePaths: string[]
): Promise<{ ok: true }> {
const target = await this.host.resolveRuntimeGitTarget(worktreeSelector)
const relativePaths = filePaths.map((path) => normalizeRuntimeGitRelativePath(path))
const relativePaths = filePaths.map((path) => normalizeRuntimeGitRelativePath(path, target))
await requireRuntimeGitProvider(target).bulkUnstageFiles(target.worktree.path, relativePaths)
return { ok: true }
}
Expand All @@ -72,14 +72,14 @@ export class RuntimeGitStagingCommands {
filePaths: string[]
): Promise<{ ok: true }> {
const target = await this.host.resolveRuntimeGitTarget(worktreeSelector)
const relativePaths = filePaths.map((path) => normalizeRuntimeGitRelativePath(path))
const relativePaths = filePaths.map((path) => normalizeRuntimeGitRelativePath(path, target))
await requireRuntimeGitProvider(target).bulkDiscardChanges(target.worktree.path, relativePaths)
return { ok: true }
}

async discardRuntimeGitPath(worktreeSelector: string, filePath: string): Promise<{ ok: true }> {
const target = await this.host.resolveRuntimeGitTarget(worktreeSelector)
const relativePath = normalizeRuntimeGitRelativePath(filePath)
const relativePath = normalizeRuntimeGitRelativePath(filePath, target)
await requireRuntimeGitProvider(target).discardChanges(target.worktree.path, relativePath)
return { ok: true }
}
Expand Down
Loading