Add Windows Electron desktop support (#1093)
* fix: make upstream sync actions target the selected remote Ensure fetch and pull actually honor upstream selection so fork maintenance works from the Git sidebar, and surface upstream branch status alongside the primary origin-tracking indicators. * feat: add Windows Electron desktop foundation * fix(electron): stabilize Windows desktop packaging * fix(electron): stabilize Windows desktop chrome Use native Windows titlebar behavior with an Alt-accessible hidden menu, and harden Windows dev command launching so the desktop app follows platform conventions. * fix(electron): stabilize Windows dev startup * fix(electron): clarify desktop artifact names * fix(electron): harden Windows desktop release and launch * fix(electron): address Windows release review * fix(electron): point updater and release links to org repo * Fix Windows settings persistence fallback * Fix Windows Electron dev startup * Add Windows Electron window controls * Fix Windows Electron install and opencode launch * fix: resolve git status for repositories without upstream Fixes repository detection stuck on Checking repository Handles git status when no upstream is configured Adds regression coverage for git status loading * Add Windows app menu button * fix: preserve file editor line endings * ci: add desktop release smoke workflow --------- Co-authored-by: Bohdan Triapitsyn <artmore@protonmail.com>
This commit is contained in:
committed by
GitHub
co-authored by
Bohdan Triapitsyn
parent
cc7969ac00
commit
becd240168
@@ -101,6 +101,7 @@ The following functions are internal helpers used by exported functions:
|
||||
- `tracking`: Upstream branch (e.g., 'origin/main').
|
||||
- `ahead`: Number of commits ahead of upstream.
|
||||
- `behind`: Number of commits behind upstream.
|
||||
- `upstreamComparison`: Optional comparison against `upstream/<current-branch>`, with `{ remote, branch, ahead, behind }`.
|
||||
- `files`: Array of file objects with `path`, `index`, `working_dir` status codes.
|
||||
- `isClean`: Boolean indicating if working tree is clean.
|
||||
- `diffStats`: Object mapping file paths to `{ insertions, deletions }`.
|
||||
|
||||
@@ -12,6 +12,10 @@ const execFileAsync = promisify(execFile);
|
||||
const gpgconfCandidates = ['gpgconf', '/opt/homebrew/bin/gpgconf', '/usr/local/bin/gpgconf'];
|
||||
let resolvedGitBinary = null;
|
||||
const worktreeBootstrapState = new Map();
|
||||
const remoteExistenceCache = new Map();
|
||||
const SIMPLE_GIT_SAFE_BINARY_PATTERN = /^([a-z]:)?([a-z0-9/.\\_~-]+)$/i;
|
||||
const SIMPLE_GIT_UNSAFE_BINARY_WARNING = 'Invalid value supplied for custom binary, restricted characters must be removed';
|
||||
const REMOTE_EXISTENCE_CACHE_TTL_MS = 30_000;
|
||||
const gitIndexMutationQueues = new Map();
|
||||
|
||||
const WORKTREE_BOOTSTRAP_PENDING = 'pending';
|
||||
@@ -86,6 +90,30 @@ const normalizeGitExecutableCandidate = (candidate) => {
|
||||
return trimmed;
|
||||
};
|
||||
|
||||
const isSafeSimpleGitBinary = (candidate) => (
|
||||
typeof candidate === 'string' && SIMPLE_GIT_SAFE_BINARY_PATTERN.test(candidate)
|
||||
);
|
||||
|
||||
const createSimpleGit = (options) => {
|
||||
if (!options?.unsafe?.allowUnsafeCustomBinary) {
|
||||
return simpleGit(options);
|
||||
}
|
||||
|
||||
const originalWarn = console.warn;
|
||||
console.warn = (...args) => {
|
||||
if (String(args[0] || '').includes(SIMPLE_GIT_UNSAFE_BINARY_WARNING)) {
|
||||
return;
|
||||
}
|
||||
originalWarn(...args);
|
||||
};
|
||||
|
||||
try {
|
||||
return simpleGit(options);
|
||||
} finally {
|
||||
console.warn = originalWarn;
|
||||
}
|
||||
};
|
||||
|
||||
const listPathExecutableCandidates = (binaryName) => {
|
||||
const currentPath = process.env.PATH || '';
|
||||
const seen = new Set();
|
||||
@@ -133,22 +161,34 @@ const resolveGitBinary = () => {
|
||||
.map((value) => (typeof value === 'string' ? value.trim() : ''))
|
||||
.filter(Boolean);
|
||||
for (const candidate of explicit) {
|
||||
if (isExecutableFile(candidate)) {
|
||||
resolvedGitBinary = candidate;
|
||||
const normalized = normalizeGitExecutableCandidate(candidate);
|
||||
if (isExecutableFile(normalized)) {
|
||||
resolvedGitBinary = normalized;
|
||||
return resolvedGitBinary;
|
||||
}
|
||||
}
|
||||
|
||||
const discovered = [
|
||||
const pathDiscovered = [
|
||||
...listPathExecutableCandidates('git.exe'),
|
||||
...listPathExecutableCandidates('git'),
|
||||
]
|
||||
.map(normalizeGitExecutableCandidate)
|
||||
.filter(Boolean)
|
||||
.filter((candidate) => isExecutableFile(candidate));
|
||||
if (pathDiscovered.length > 0) {
|
||||
resolvedGitBinary = 'git';
|
||||
return resolvedGitBinary;
|
||||
}
|
||||
|
||||
const discovered = [
|
||||
...listWindowsGitInstallCandidates(),
|
||||
]
|
||||
.map(normalizeGitExecutableCandidate)
|
||||
.filter(Boolean)
|
||||
.filter((candidate) => isExecutableFile(candidate));
|
||||
|
||||
const preferredExe = discovered.find((candidate) => candidate.toLowerCase().endsWith('.exe'));
|
||||
const preferredExe = discovered.find((candidate) => isSafeSimpleGitBinary(candidate) && candidate.toLowerCase().endsWith('.exe'))
|
||||
|| discovered.find((candidate) => candidate.toLowerCase().endsWith('.exe'));
|
||||
resolvedGitBinary = preferredExe || discovered[0] || 'git.exe';
|
||||
return resolvedGitBinary;
|
||||
};
|
||||
@@ -276,9 +316,9 @@ const createGit = async (directory) => {
|
||||
const hasCustomBinary = typeof binary === 'string' && binary.trim() && binary !== 'git' && binary !== 'git.exe';
|
||||
const unsafe = hasCustomBinary ? { allowUnsafeCustomBinary: true } : undefined;
|
||||
if (!directory) {
|
||||
return simpleGit({ env, spawnOptions, binary, unsafe });
|
||||
return createSimpleGit({ env, spawnOptions, binary, unsafe });
|
||||
}
|
||||
return simpleGit({
|
||||
return createSimpleGit({
|
||||
baseDir: normalizeDirectoryPath(directory),
|
||||
env,
|
||||
spawnOptions,
|
||||
@@ -677,6 +717,96 @@ const parseGitErrorText = (error) => {
|
||||
.trim();
|
||||
};
|
||||
|
||||
const parseAheadBehindCounts = (value) => {
|
||||
const [aheadRaw, behindRaw] = String(value || '').trim().split(/\s+/);
|
||||
const ahead = parseInt(aheadRaw, 10);
|
||||
const behind = parseInt(behindRaw, 10);
|
||||
if (!Number.isFinite(ahead) || !Number.isFinite(behind)) {
|
||||
return null;
|
||||
}
|
||||
return { ahead, behind };
|
||||
};
|
||||
|
||||
const getRemoteExistenceCacheKey = (directory, remoteName) => {
|
||||
const normalizedDirectory = normalizeDirectoryPath(directory) || '';
|
||||
return `${path.resolve(normalizedDirectory)}\0${remoteName}`;
|
||||
};
|
||||
|
||||
const hasRemote = async (git, directory, remoteName) => {
|
||||
const remote = String(remoteName || '').trim();
|
||||
if (!remote) {
|
||||
return false;
|
||||
}
|
||||
|
||||
const key = getRemoteExistenceCacheKey(directory, remote);
|
||||
const cached = remoteExistenceCache.get(key);
|
||||
if (cached && Date.now() - cached.checkedAt < REMOTE_EXISTENCE_CACHE_TTL_MS) {
|
||||
return cached.exists;
|
||||
}
|
||||
|
||||
const exists = await git
|
||||
.raw(['remote', 'get-url', remote])
|
||||
.then((value) => String(value || '').trim().length > 0)
|
||||
.catch(() => false);
|
||||
|
||||
remoteExistenceCache.set(key, { exists, checkedAt: Date.now() });
|
||||
return exists;
|
||||
};
|
||||
|
||||
const buildRawGitOptions = (raw) => {
|
||||
if (Array.isArray(raw)) {
|
||||
return raw.map((value) => String(value || '').trim()).filter(Boolean);
|
||||
}
|
||||
|
||||
if (!raw || typeof raw !== 'object') {
|
||||
return [];
|
||||
}
|
||||
|
||||
return Object.entries(raw).flatMap(([key, value]) => {
|
||||
const option = String(key || '').trim();
|
||||
if (!option || value === false) {
|
||||
return [];
|
||||
}
|
||||
if (value === true || value == null) {
|
||||
return [option];
|
||||
}
|
||||
return [option, String(value)];
|
||||
});
|
||||
};
|
||||
|
||||
const getRemoteBranchComparison = async (git, remoteName, branchName) => {
|
||||
const remote = String(remoteName || '').trim();
|
||||
const branch = String(branchName || '').trim();
|
||||
if (!remote || !branch) {
|
||||
return null;
|
||||
}
|
||||
|
||||
const remoteRef = `refs/remotes/${remote}/${branch}`;
|
||||
const exists = await git
|
||||
.raw(['rev-parse', '--verify', remoteRef])
|
||||
.then((value) => String(value || '').trim())
|
||||
.catch(() => '');
|
||||
if (!exists) {
|
||||
return null;
|
||||
}
|
||||
|
||||
const countsRaw = await git
|
||||
.raw(['rev-list', '--left-right', '--count', `HEAD...${remoteRef}`])
|
||||
.then((value) => String(value || '').trim())
|
||||
.catch(() => '');
|
||||
const counts = parseAheadBehindCounts(countsRaw);
|
||||
if (!counts) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return {
|
||||
remote,
|
||||
branch,
|
||||
ahead: counts.ahead,
|
||||
behind: counts.behind,
|
||||
};
|
||||
};
|
||||
|
||||
const isNotGitRepositoryError = (error) => {
|
||||
const text = parseGitErrorText(error);
|
||||
return /not a git repository/i.test(text);
|
||||
@@ -1342,7 +1472,7 @@ export async function getStatus(directory, options = {}) {
|
||||
const lightMode = options.mode === 'light';
|
||||
|
||||
try {
|
||||
const { repoRoot, git } = await createRepositoryGitContext(directory);
|
||||
const { directoryPath, repoRoot, git } = await createRepositoryGitContext(directory);
|
||||
|
||||
// Use -uall to show all untracked files individually, not just directories
|
||||
const status = await git.status(['-uall']);
|
||||
@@ -1495,6 +1625,7 @@ export async function getStatus(directory, options = {}) {
|
||||
let tracking = status.tracking || null;
|
||||
let ahead = status.ahead;
|
||||
let behind = status.behind;
|
||||
let upstreamComparison;
|
||||
|
||||
// When no upstream is configured (common for new worktree branches), Git doesn't report ahead/behind.
|
||||
// We still want to show the number of unpublished commits to the user.
|
||||
@@ -1514,6 +1645,15 @@ export async function getStatus(directory, options = {}) {
|
||||
}
|
||||
}
|
||||
|
||||
if (
|
||||
!lightMode
|
||||
&& status.current
|
||||
&& (!tracking || !tracking.startsWith('upstream/'))
|
||||
&& await hasRemote(git, directoryPath, 'upstream')
|
||||
) {
|
||||
upstreamComparison = await getRemoteBranchComparison(git, 'upstream', status.current);
|
||||
}
|
||||
|
||||
// Check for in-progress operations
|
||||
let mergeInProgress = null;
|
||||
let rebaseInProgress = null;
|
||||
@@ -1574,6 +1714,7 @@ export async function getStatus(directory, options = {}) {
|
||||
tracking,
|
||||
ahead,
|
||||
behind,
|
||||
upstreamComparison,
|
||||
files: status.files.map((f) => ({
|
||||
path: f.path,
|
||||
index: f.index,
|
||||
@@ -1984,9 +2125,20 @@ export async function pull(directory, options = {}) {
|
||||
: options.options || {};
|
||||
|
||||
try {
|
||||
const remote = String(options.remote || '').trim();
|
||||
const requestedBranch = String(options.branch || '').trim();
|
||||
let branch = requestedBranch;
|
||||
|
||||
if (remote && !branch) {
|
||||
// simple-git only includes the remote when both remote and branch are provided.
|
||||
// Resolve the current branch so selecting a remote in the UI really runs `git pull <remote> <branch>`.
|
||||
const status = await git.status();
|
||||
branch = String(status.current || '').trim();
|
||||
}
|
||||
|
||||
const result = await git.pull(
|
||||
options.remote || 'origin',
|
||||
options.branch,
|
||||
remote || 'origin',
|
||||
branch || undefined,
|
||||
pullOptions
|
||||
);
|
||||
|
||||
@@ -2240,11 +2392,20 @@ export async function fetch(directory, options = {}) {
|
||||
const { git } = await createRepositoryGitContext(directory);
|
||||
|
||||
try {
|
||||
await git.fetch(
|
||||
options.remote || 'origin',
|
||||
options.branch,
|
||||
options.options || {}
|
||||
);
|
||||
const remote = String(options.remote || '').trim();
|
||||
const branch = String(options.branch || '').trim();
|
||||
const fetchOptions = options.options || {};
|
||||
|
||||
if (remote && !branch) {
|
||||
// simple-git drops the remote when branch is omitted, so use raw to preserve `git fetch <remote>`.
|
||||
await git.raw(['fetch', ...buildRawGitOptions(fetchOptions), remote]);
|
||||
} else {
|
||||
await git.fetch(
|
||||
remote || 'origin',
|
||||
branch || undefined,
|
||||
fetchOptions
|
||||
);
|
||||
}
|
||||
|
||||
return { success: true };
|
||||
} catch (error) {
|
||||
|
||||
@@ -1,6 +1,39 @@
|
||||
import { describe, expect, it } from 'vitest';
|
||||
import { execFileSync } from 'node:child_process';
|
||||
import fs from 'node:fs';
|
||||
import os from 'node:os';
|
||||
import path from 'node:path';
|
||||
import { afterEach, describe, expect, it } from 'vitest';
|
||||
|
||||
import { resolveBaseRefForLog, stageFiles, unstageFiles } from './service.js';
|
||||
import { getStatus, resolveBaseRefForLog, stageFiles, unstageFiles } from './service.js';
|
||||
|
||||
const tempDirs = [];
|
||||
|
||||
const createTempDir = () => {
|
||||
const dir = fs.mkdtempSync(path.join(os.tmpdir(), 'openchamber-git-service-'));
|
||||
tempDirs.push(dir);
|
||||
return dir;
|
||||
};
|
||||
|
||||
const runGit = (cwd, args) => execFileSync('git', args, {
|
||||
cwd,
|
||||
encoding: 'utf8',
|
||||
stdio: ['ignore', 'pipe', 'pipe'],
|
||||
});
|
||||
|
||||
const canRunGit = () => {
|
||||
try {
|
||||
execFileSync('git', ['--version'], { stdio: 'ignore' });
|
||||
return true;
|
||||
} catch {
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
afterEach(() => {
|
||||
for (const dir of tempDirs.splice(0)) {
|
||||
fs.rmSync(dir, { recursive: true, force: true });
|
||||
}
|
||||
});
|
||||
|
||||
describe('resolveBaseRefForLog', () => {
|
||||
it('returns the local ref unchanged when it exists, even if origin also exists', async () => {
|
||||
@@ -47,3 +80,23 @@ describe('git index path validation', () => {
|
||||
await expect(unstageFiles('/repo', ['../secret.txt'])).rejects.toThrow('Path is outside repository: ../secret.txt');
|
||||
});
|
||||
});
|
||||
|
||||
describe('getStatus', () => {
|
||||
it('handles repositories without upstream tracking', async () => {
|
||||
if (!canRunGit()) {
|
||||
return;
|
||||
}
|
||||
|
||||
const repo = createTempDir();
|
||||
runGit(repo, ['init', '-b', 'main']);
|
||||
runGit(repo, ['config', 'user.email', 'test@example.com']);
|
||||
runGit(repo, ['config', 'user.name', 'Test User']);
|
||||
fs.writeFileSync(path.join(repo, 'README.md'), '# Test\n');
|
||||
runGit(repo, ['add', 'README.md']);
|
||||
runGit(repo, ['commit', '-m', 'Initial commit']);
|
||||
|
||||
await expect(getStatus(repo)).resolves.toMatchObject({
|
||||
current: 'main',
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user