feat(git): GitClient.init for the new-project flow (T-487)

clide treats a git repo as the workspace, so creating a new project starts with
`git init`. Add GitClient.init — `git init -b <main>` in workDir, deterministic
default branch, idempotent on an existing repo. The first primitive of the
new-project flow (T-486); the create-dir + scaffold service and the
`clide project new` verb build on it next.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-06-28 08:19:10 +02:00
co-authored by Claude Opus 4.8
parent 6d7b96f115
commit b9fc720f97
5 changed files with 279 additions and 0 deletions
+18
View File
@@ -24,6 +24,24 @@ Future<Directory> _newRepo({String filename = 'file.txt', String contents = 'hel
}
void main() {
group('GitClient — init (T-487)', () {
late Directory dir;
setUp(() async => dir = await Directory.systemTemp.createTemp('clide-git-init-'));
tearDown(() async {
if (dir.existsSync()) dir.deleteSync(recursive: true);
});
test('init creates a repo on the default branch and is idempotent', () async {
final git = GitClient(toolchain: _toolchain(), workDir: dir);
await git.init();
expect(Directory('${dir.path}/.git').existsSync(), isTrue);
expect(await git.currentBranch(), 'main');
// A second init on the existing repo is a no-op, not an error.
await git.init();
expect(Directory('${dir.path}/.git').existsSync(), isTrue);
});
});
group('GitClient — queries', () {
late Directory sandbox;
late GitClient git;