Skip to content

Commit 150be89

Browse files
igorcostaAutohand Evolve
andauthored
Keep Git initialization explicit in work folders (#748)
Allow chat and file work in ordinary folders without automatic Git initialization. Retain existing repository and branch detection; Git tools remain available when explicitly chosen. Validated through the startup regressions, actual-composer terminal coverage, and the executed unit, terminal and platform build CI checks. Co-authored-by: Autohand Evolve <code-noreply@autohand.ai>
1 parent 9d10d59 commit 150be89

7 files changed

Lines changed: 111 additions & 97 deletions

File tree

‎CHANGELOG.md‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22

33
## Unreleased
44

5+
### Fixed
6+
7+
- Start chat and file work in ordinary folders without initializing Git or creating an ignore file. Existing repositories still show their branch; initialize Git only when you choose to use it.
8+
59
## 0.9.10 - 2026-11-04
610

711
### Added
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
# Startup observes Git; repository creation is explicit
2+
3+
## Context
4+
5+
Squad reported failed Git initialization when a conversation used an empty
6+
default folder. Not every workspace is a source repository. Startup checks
7+
considered hidden files insignificant and ran `git init` for an otherwise empty
8+
directory, also creating a macOS `.gitignore`. That happened before the composer on normal terminal/direct-CLI startup.
9+
The first cross-repository diagnosis overgeneralized this to RPC: current
10+
protocol launches route before these checks, so the branch alone is not evidence
11+
that RPC startup initializes Git. Disabling all startup with bare mode would also
12+
disable unrelated instructions, hooks and integrations.
13+
14+
The previous tests explicitly expected automatic initialization. Updated tests
15+
failed in five cases before the source change: empty and hidden-file-only
16+
folders, repeated startup, Git being optional, and a folder containing only an
17+
existing ignore file.
18+
19+
## Decision
20+
21+
Remove the empty-directory initialization branch. Startup still checks access,
22+
detects existing Git metadata and reads branches; it never creates `.git` or
23+
`.gitignore`. Git is optional for general chat and file work. Git operations
24+
still require the executable and an explicitly chosen repository. Keep the
25+
legacy `workspace.initialized` result field as false for callers that read it.
26+
27+
Repository creation is a separate explicit user request, through Git itself or
28+
the agent's normal tool approval path. No new startup flag or blanket bare-mode
29+
override is introduced.
30+
31+
## Evidence
32+
33+
The updated startup suite and branding suite pass together (26 tests). The
34+
built CLI Tuistory case reaches the actual composer in an empty non-Git folder,
35+
confirms no `.git` or `.gitignore` was created, and exits interactively. This
36+
test does not call a live model provider. Build succeeds. Aggregate lint/proof
37+
results are recorded with the change's validation receipt.
38+
39+
The complete `bun run proof` ran on Node 26.7.0: lint/type checking and the
40+
unit stage passed (963 files, 13,779 tests; 6 files and 80 tests skipped).
41+
The terminal stage finished with 106 files passing and three failures among
42+
536 tests: mouse/scroll exit, slash-command browsing and Console connectors.
43+
A focused retry passed the first two (27 tests across those files); the
44+
connector case still timed out waiting for tools/list. The same connector
45+
test also fails at that assertion in an unmodified worktree at base commit
46+
9d10d59d51442bd60ca35ee04234da63ae83370e. This establishes that connector
47+
failure separately from the startup patch; it does not make aggregate proof
48+
green. CI uses its own pinned runtime and remains an independent check.
49+
50+
## Consequences
51+
52+
New empty folders no longer acquire version control automatically. People who
53+
want Git must explicitly initialize it. Existing repositories keep their branch
54+
display; non-Git folders keep file work and chat. Features that require Git may
55+
report that a repository is needed when invoked. This does not prohibit Git
56+
tools or erase existing repositories, and it does not make unrelated runtime
57+
startup read-only: the ordinary workspace/session infrastructure still runs.

‎docs/config-reference.md‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,15 @@ The flag skips trace-daemon reconciliation, settings sync, pings, account pollin
174174

175175
`/new` archives the current session and starts a new session ID with fresh conversation and accounting state. It does not wait for an inference or memory-extraction call.
176176

177+
## Project folders and Git
178+
179+
A workspace can be an ordinary folder. Starting Autohand does not initialize
180+
Git or create `.gitignore`, including in empty folders. Existing repositories
181+
are detected for branch information. Git is optional for chat and file work;
182+
Git operations require Git to be installed and a repository chosen by you.
183+
Initialize a repository only when you want version control, for example by
184+
explicitly asking the agent to run `git init` or running it yourself.
185+
177186
## Bare Mode
178187

179188
Bare mode starts Autohand with only explicitly requested context and runtime integrations. Enable it with either:

‎src/index.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2001,7 +2001,7 @@ async function runCLI(options: InternalCLIOptions): Promise<void> {
20012001
}
20022002

20032003
// Run startup checks synchronously before prompt to prevent output racing.
2004-
// git init, tool checks etc. must finish printing BEFORE the prompt renders.
2004+
// Read-only repository and tool checks finish before the prompt renders.
20052005
if (!options.bare) {
20062006
try {
20072007
const checkResults = await awaitCliLifecycleStep(

‎src/startup/checks.ts‎

Lines changed: 5 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ import fs from 'fs-extra';
1313
import { resolveRipgrepCommand } from '../utils/ripgrep.js';
1414

1515
const GIT_COMMAND_TIMEOUT_MS = 5_000;
16-
const GIT_INIT_TIMEOUT_MS = 15_000;
1716
let toolCheckResultsPromise: Promise<CheckResult[]> | undefined;
1817

1918
function getCurrentBunVersion(): string | undefined {
@@ -51,8 +50,8 @@ const REQUIRED_TOOLS: ToolCheck[] = [
5150
name: 'git',
5251
command: 'git',
5352
versionFlag: '--version',
54-
required: true,
55-
description: 'Version control (required for file tracking, undo, and git operations)',
53+
required: false,
54+
description: 'Version control (optional; needed for Git operations)',
5655
installHints: {
5756
darwin: 'brew install git',
5857
linux: 'sudo apt install git # or: sudo dnf install git',
@@ -245,20 +244,6 @@ export async function validateWorkspacePath(
245244
}
246245
}
247246

248-
/**
249-
* Check if a directory is empty (no significant files)
250-
* Hidden files like .DS_Store are ignored, but .git counts as significant
251-
*/
252-
function isEmptyDirectory(dir: string): boolean {
253-
try {
254-
const entries = fs.readdirSync(dir);
255-
const significantEntries = entries.filter(e => !e.startsWith('.') || e === '.git');
256-
return significantEntries.length === 0;
257-
} catch {
258-
return false;
259-
}
260-
}
261-
262247
/**
263248
* Run a git command and return trimmed stdout, or undefined on failure
264249
*/
@@ -314,7 +299,7 @@ function readGitHeadBranch(workspaceRoot: string): string | undefined {
314299

315300
/**
316301
* Check if inside a git repository
317-
* If directory is empty and not a git repo, auto-initialize git
302+
* Repository detection never initializes or edits the workspace.
318303
*/
319304
async function checkGitRepo(workspaceRoot: string): Promise<{ isGitRepo: boolean; branch?: string; initialized?: boolean }> {
320305
// First check if .git directory exists (works even with no commits)
@@ -333,34 +318,6 @@ async function checkGitRepo(workspaceRoot: string): Promise<{ isGitRepo: boolean
333318
};
334319
}
335320

336-
// Not a git repo - check if empty and auto-init
337-
if (isEmptyDirectory(workspaceRoot)) {
338-
const initResult = await runGitCommand(['init'], workspaceRoot, GIT_INIT_TIMEOUT_MS);
339-
340-
if (initResult !== undefined || fs.existsSync(`${workspaceRoot}/.git/HEAD`)) {
341-
// On macOS, create .gitignore with .DS_Store
342-
if (os.platform() === 'darwin') {
343-
try {
344-
const gitignorePath = `${workspaceRoot}/.gitignore`;
345-
if (!fs.existsSync(gitignorePath)) {
346-
fs.writeFileSync(gitignorePath, '.DS_Store\n');
347-
}
348-
} catch {
349-
// Ignore errors creating .gitignore
350-
}
351-
}
352-
353-
// Get the default branch name
354-
const branch = await getGitBranch(workspaceRoot) || 'main';
355-
356-
return {
357-
isGitRepo: true,
358-
branch,
359-
initialized: true
360-
};
361-
}
362-
}
363-
364321
return { isGitRepo: false };
365322
}
366323

@@ -389,7 +346,7 @@ export interface StartupCheckResults {
389346
writable: boolean;
390347
isGitRepo: boolean;
391348
branch?: string;
392-
/** True if git was auto-initialized for an empty directory */
349+
/** Legacy result field; startup no longer initializes repositories. */
393350
initialized?: boolean;
394351
error?: string;
395352
};
@@ -433,7 +390,7 @@ export async function runStartupChecks(workspaceRoot: string): Promise<StartupCh
433390
writable: workspaceCheck.writable,
434391
isGitRepo: gitCheck.isGitRepo,
435392
branch: gitCheck.branch,
436-
initialized: gitCheck.initialized,
393+
initialized: false,
437394
error: workspaceCheck.error
438395
},
439396
allRequiredMet,
@@ -448,12 +405,6 @@ export function printStartupCheckResults(results: StartupCheckResults, verbose =
448405
const missingRequired = results.tools.filter(t => t.required && !t.installed);
449406
const missingOptional = results.tools.filter(t => !t.required && !t.installed);
450407

451-
// Show git initialization message if it happened
452-
if (results.workspace.initialized) {
453-
console.log(chalk.green('✓ Initialized git repository'));
454-
console.log();
455-
}
456-
457408
// Only print tool issues if there are problems or verbose mode
458409
if (missingRequired.length === 0 && !verbose) {
459410
return;

‎tests/startupGitInit.spec.ts‎

Lines changed: 31 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,10 @@ import { describe, it, expect, beforeEach, afterEach } from 'vitest';
77
import fs from 'fs-extra';
88
import path from 'path';
99
import os from 'os';
10+
import { execFileSync } from 'node:child_process';
1011
import { runStartupChecks, validateWorkspacePath } from '../src/startup/checks.js';
1112

12-
describe('Git Auto-Init for Empty Directories', () => {
13+
describe('Optional Git at startup', () => {
1314
let tempDir: string;
1415

1516
beforeEach(async () => {
@@ -27,25 +28,25 @@ describe('Git Auto-Init for Empty Directories', () => {
2728
}
2829
});
2930

30-
describe('isEmptyDirectory detection', () => {
31-
it('treats directory with no files as empty', async () => {
31+
describe('read-only repository detection', () => {
32+
it('starts an empty workspace without initializing Git', async () => {
3233
// tempDir is empty by default
3334
const result = await runStartupChecks(tempDir);
3435

35-
// Should have auto-initialized git
36-
expect(result.workspace.isGitRepo).toBe(true);
37-
expect(result.workspace.initialized).toBe(true);
36+
expect(result.workspace.isGitRepo).toBe(false);
37+
expect(result.workspace.initialized).toBeFalsy();
38+
expect(await fs.readdir(tempDir)).toEqual([]);
3839
});
3940

40-
it('treats directory with only hidden files (like .DS_Store) as empty', async () => {
41+
it('preserves hidden files without creating a repository', async () => {
4142
// Add a hidden file that should be ignored
4243
await fs.writeFile(path.join(tempDir, '.DS_Store'), 'test');
4344

4445
const result = await runStartupChecks(tempDir);
4546

46-
// Should still auto-initialize git
47-
expect(result.workspace.isGitRepo).toBe(true);
48-
expect(result.workspace.initialized).toBe(true);
47+
expect(result.workspace.isGitRepo).toBe(false);
48+
expect(result.workspace.initialized).toBeFalsy();
49+
expect(await fs.readdir(tempDir)).toEqual(['.DS_Store']);
4950
});
5051

5152
it('does NOT treat directory with .git as empty', async () => {
@@ -95,44 +96,35 @@ describe('Git Auto-Init for Empty Directories', () => {
9596
});
9697
});
9798

98-
describe('git initialization behavior', () => {
99-
it('creates .git directory when initializing', async () => {
100-
const result = await runStartupChecks(tempDir);
101-
102-
expect(result.workspace.initialized).toBe(true);
103-
expect(await fs.pathExists(path.join(tempDir, '.git'))).toBe(true);
99+
describe('Git is an explicit project choice', () => {
100+
it('does not create a Git directory or ignore file after repeated startup checks', async () => {
101+
await runStartupChecks(tempDir);
102+
await runStartupChecks(tempDir);
103+
expect(await fs.pathExists(path.join(tempDir, '.git'))).toBe(false);
104+
expect(await fs.pathExists(path.join(tempDir, '.gitignore'))).toBe(false);
104105
});
105106

106-
it('sets branch name after initialization', async () => {
107+
it('keeps a non-Git project writable and Git tooling optional', async () => {
107108
const result = await runStartupChecks(tempDir);
108-
109-
expect(result.workspace.initialized).toBe(true);
110-
expect(result.workspace.branch).toBeDefined();
111-
// Branch should be 'main' or 'master' depending on git config
112-
expect(['main', 'master']).toContain(result.workspace.branch);
109+
expect(result.workspace.writable).toBe(true);
110+
expect(result.workspace.isGitRepo).toBe(false);
111+
expect(result.workspace.branch).toBeUndefined();
112+
expect(result.tools.find(tool => tool.name === 'git')?.required).toBe(false);
113113
});
114114

115-
it('creates .gitignore with .DS_Store on macOS', async () => {
116-
const result = await runStartupChecks(tempDir);
117-
118-
expect(result.workspace.initialized).toBe(true);
119-
120-
// Only check for .gitignore on macOS
121-
if (process.platform === 'darwin') {
122-
const gitignorePath = path.join(tempDir, '.gitignore');
123-
expect(await fs.pathExists(gitignorePath)).toBe(true);
124-
125-
const content = await fs.readFile(gitignorePath, 'utf8');
126-
expect(content).toContain('.DS_Store');
127-
}
115+
it('preserves an existing ignore file', async () => {
116+
await fs.writeFile(path.join(tempDir, '.gitignore'), 'private-files/\n');
117+
await runStartupChecks(tempDir);
118+
expect(await fs.readFile(path.join(tempDir, '.gitignore'), 'utf8')).toBe('private-files/\n');
119+
expect(await fs.pathExists(path.join(tempDir, '.git'))).toBe(false);
128120
});
129121
});
130122

131123
describe('existing git repo detection', () => {
132124
it('detects existing git repo and does NOT re-initialize', async () => {
133-
// First call initializes git
125+
execFileSync('git', ['init', '-b', 'chosen-branch'], { cwd: tempDir, stdio: 'ignore' });
134126
const firstResult = await runStartupChecks(tempDir);
135-
expect(firstResult.workspace.initialized).toBe(true);
127+
expect(firstResult.workspace.initialized).toBeFalsy();
136128

137129
// Second call should detect existing repo, not initialize again
138130
const secondResult = await runStartupChecks(tempDir);
@@ -141,12 +133,11 @@ describe('Git Auto-Init for Empty Directories', () => {
141133
});
142134

143135
it('detects branch in existing repo', async () => {
144-
// Initialize git
145-
await runStartupChecks(tempDir);
136+
execFileSync('git', ['init', '-b', 'chosen-branch'], { cwd: tempDir, stdio: 'ignore' });
146137

147138
// Run again and check branch detection
148139
const result = await runStartupChecks(tempDir);
149-
expect(result.workspace.branch).toBeDefined();
140+
expect(result.workspace.branch).toBe('chosen-branch');
150141
});
151142

152143
it('detects branch directly from git HEAD when git commands are unavailable', async () => {

‎tests/tuistory/built-cli-commands.tuistory.test.ts‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -482,7 +482,7 @@ describe('interactive built CLI Tuistory tests: steering, caret, slash commands,
482482
expect(rawOutput.lastIndexOf('\u001b[<u')).toBeGreaterThan(rawOutput.indexOf('\u001b[>1u'));
483483
});
484484

485-
it('auto-initializes git for an empty workspace before rendering the composer', async () => {
485+
it('starts an empty non-Git workspace without initializing Git', async () => {
486486
const state = await createTempAutohandHome({
487487
initializeGit: false,
488488
writePackageJson: false,
@@ -498,7 +498,9 @@ describe('interactive built CLI Tuistory tests: steering, caret, slash commands,
498498

499499
await waitForComposer(session);
500500

501-
expect(await fs.pathExists(path.join(state.workspaceRoot, '.git'))).toBe(true);
501+
expect(await fs.pathExists(path.join(state.workspaceRoot, '.git'))).toBe(false);
502+
expect(await fs.pathExists(path.join(state.workspaceRoot, '.gitignore'))).toBe(false);
503+
expect(session.readAll()).not.toContain('Initialized git repository');
502504

503505
await exitInteractive(session);
504506
});

0 commit comments

Comments
 (0)