fix(server): Use 'main' as default branch for new git projects#744
fix(server): Use 'main' as default branch for new git projects#744
Conversation
Git initialization now explicitly specifies --initial-branch=main to match GitHub's default branch standard (since October 2020). This prevents the branch name mismatch that caused features to disappear from the UI when pushing to GitHub. Fixes #734 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Summary of ChangesHello @Shironex, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request resolves an issue where newly initialized Git projects by the server would not use 'main' as their default branch, leading to inconsistencies and potential UI problems when interacting with platforms like GitHub. By modifying the Highlights
🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console. Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
📝 WalkthroughWalkthroughThe PR updates git initialization commands across the application and tests to use the Changes
Estimated code review effort🎯 1 (Trivial) | ⏱️ ~3 minutes Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Code Review
This pull request correctly standardizes the default branch to 'main' for new git projects, which is a good improvement. My review focuses on a potential compatibility issue with the chosen implementation. The use of git init --initial-branch=main is not supported on Git versions prior to 2.28.0, which could lead to failures for users with older installations. I have provided suggestions to use a more widely compatible command sequence that achieves the same result, ensuring the feature is robust across different environments.
| await execAsync( | ||
| `git init --initial-branch=main && git commit --allow-empty -m "Initial commit"`, | ||
| { | ||
| cwd: projectPath, | ||
| } | ||
| ); |
There was a problem hiding this comment.
The --initial-branch flag for git init was introduced in Git v2.28.0. This command will fail for users with older versions of Git, breaking the repository initialization feature. For better compatibility, it's safer to use a command sequence that works on older versions as well.
| await execAsync( | |
| `git init --initial-branch=main && git commit --allow-empty -m "Initial commit"`, | |
| { | |
| cwd: projectPath, | |
| } | |
| ); | |
| await execAsync( | |
| `git init && git checkout -b main && git commit --allow-empty -m "Initial commit"`, | |
| { | |
| cwd: projectPath, | |
| } | |
| ); |
| // Initialize git repo | ||
| await execAsync('git init', { cwd: tmpDir }); | ||
| // Initialize git repo with 'main' as the default branch (matching GitHub's standard) | ||
| await execAsync('git init --initial-branch=main', { cwd: tmpDir }); |
There was a problem hiding this comment.
Using git init --initial-branch=main could cause test failures in environments with older Git versions (< 2.28.0). To improve test stability and consistency with the application code, a more compatible approach is recommended.
| await execAsync('git init --initial-branch=main', { cwd: tmpDir }); | |
| await execAsync('git init && git checkout -b main', { cwd: tmpDir }); |
| repoPath = await fs.mkdtemp(path.join(os.tmpdir(), 'automaker-no-commit-')); | ||
| await execAsync('git init', { cwd: repoPath }); | ||
| // Initialize with 'main' as the default branch (matching GitHub's standard) | ||
| await execAsync('git init --initial-branch=main', { cwd: repoPath }); |
There was a problem hiding this comment.
To ensure tests are reliable across different development and CI environments, it's best to avoid commands that depend on a recent Git version. The --initial-branch flag is not universally available and could lead to test failures.
| await execAsync('git init --initial-branch=main', { cwd: repoPath }); | |
| await execAsync('git init && git checkout -b main', { cwd: repoPath }); |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Fix all issues with AI agents
In `@apps/server/src/routes/worktree/routes/init-git.ts`:
- Around line 46-53: The current git init code uses execAsync with
--initial-branch (incompatible with Git <2.28) and bypasses established
patterns; replace this with a delegated service that uses execGitCommand() from
common.ts and the ensureInitialCommit() helper (or fallback to git init + git
branch -M main) to create the initial commit, call isGitRepo() from
`@automaker/git-utils` to verify repository state, and emit progress/events via
createEventEmitter() consistent with create.ts so the route delegates to that
service rather than running raw shell commands.
🧹 Nitpick comments (1)
apps/server/src/routes/worktree/routes/init-git.ts (1)
46-53: Consider extracting git-init into a service and emitting events.This route executes business logic directly and doesn’t emit any events; moving the git-init flow into a service and emitting start/success/failure events would align with the server architecture expectations.
As per coding guidelines, Server business logic should be organized into services in the services/ directory, with Express route handlers in routes/ that delegate to services; and All server operations should emit events using createEventEmitter() from lib/events.ts that stream to the frontend via WebSocket.
| // Initialize git with 'main' as the default branch (matching GitHub's standard since 2020) | ||
| // and create an initial empty commit | ||
| await execAsync( | ||
| `git init --initial-branch=main && git commit --allow-empty -m "Initial commit"`, | ||
| { | ||
| cwd: projectPath, | ||
| } | ||
| ); |
There was a problem hiding this comment.
🧩 Analysis chain
🏁 Script executed:
# First, let's look at the file structure and the specific file mentioned
fd -t f "init-git.ts" --full-pathRepository: AutoMaker-Org/automaker
Length of output: 117
🏁 Script executed:
# Search for documented Git version requirements in the repo
rg -n "minimum git|git>=|git version|git 2\." --type-list | head -20
rg -i "git.*version\|version.*git" . -A 2 -B 2 | head -50Repository: AutoMaker-Org/automaker
Length of output: 456
🏁 Script executed:
# Check if `@automaker/git-utils` package exists and explore the codebase
fd -t d "@automaker" . | head -20Repository: AutoMaker-Org/automaker
Length of output: 49
🏁 Script executed:
# Look for any CI configuration that might specify Git version
fd -t f -e yml -e yaml -e json . | grep -E "(\.github|\.gitlab|azure|workflow|ci|package)" | head -20Repository: AutoMaker-Org/automaker
Length of output: 613
🏁 Script executed:
# Read the specific file to see the full context
cat -n apps/server/src/routes/worktree/routes/init-git.tsRepository: AutoMaker-Org/automaker
Length of output: 2367
🏁 Script executed:
# Check the git-utils module to see what's available
cat libs/git-utils/package.jsonRepository: AutoMaker-Org/automaker
Length of output: 761
🏁 Script executed:
# Look for git-utils index/main exports
fd -t f "index\|main" libs/git-utils --full-path | head -10Repository: AutoMaker-Org/automaker
Length of output: 49
🏁 Script executed:
# Search for Git version constraints in package.json, CI configs
cat package.json | grep -i gitRepository: AutoMaker-Org/automaker
Length of output: 371
🏁 Script executed:
# Check for CI workflows
fd -t f "\.github" . --full-path | head -20Repository: AutoMaker-Org/automaker
Length of output: 49
🏁 Script executed:
# Find git-utils source files
fd -t f . libs/git-utils --full-path | head -20Repository: AutoMaker-Org/automaker
Length of output: 326
🏁 Script executed:
# Check services directory pattern in server
ls -la apps/server/src/ | grep -i service
fd -t d "services" apps/server/src/ --full-pathRepository: AutoMaker-Org/automaker
Length of output: 152
🏁 Script executed:
# Look for event emitter usage in the server
rg "createEventEmitter\|EventEmitter" apps/server/src/ -lRepository: AutoMaker-Org/automaker
Length of output: 49
🏁 Script executed:
# Search for git version constraints in any documentation or code
rg "git.*2\.28\|git.*version" . -i | head -20Repository: AutoMaker-Org/automaker
Length of output: 49
🏁 Script executed:
# Read git-utils index to see available exports
cat libs/git-utils/src/index.tsRepository: AutoMaker-Org/automaker
Length of output: 542
🏁 Script executed:
# List what services exist
ls -la apps/server/src/services/Repository: AutoMaker-Org/automaker
Length of output: 1734
🏁 Script executed:
# Read a service file to understand the pattern
fd -t f . apps/server/src/services/ | head -3Repository: AutoMaker-Org/automaker
Length of output: 203
🏁 Script executed:
# Check git-utils status and diff to understand what it provides
cat libs/git-utils/src/status.ts | head -50Repository: AutoMaker-Org/automaker
Length of output: 1403
🏁 Script executed:
# Check if there's any git init related function in git-utils
rg "init\|branch" libs/git-utils/src/ -iRepository: AutoMaker-Org/automaker
Length of output: 49
🏁 Script executed:
# Look at an example service to understand the pattern
head -100 apps/server/src/services/event-history-service.tsRepository: AutoMaker-Org/automaker
Length of output: 2789
🏁 Script executed:
# Check if there's a lib/events.ts mentioned in guidelines
cat apps/server/src/lib/events.ts 2>/dev/null | head -50Repository: AutoMaker-Org/automaker
Length of output: 1041
🏁 Script executed:
# Check other routes to see the pattern - do they use services?
ls -la apps/server/src/routes/Repository: AutoMaker-Org/automaker
Length of output: 1909
🏁 Script executed:
# Check the git routes structure
ls -la apps/server/src/routes/git/Repository: AutoMaker-Org/automaker
Length of output: 350
🏁 Script executed:
# Check if there's a git service
ls -la apps/server/src/services/git/ 2>/dev/null || echo "No git service found"Repository: AutoMaker-Org/automaker
Length of output: 87
🏁 Script executed:
# Look at how other routes use services - pick a simpler one
cat apps/server/src/routes/health/routes/check.ts | head -50Repository: AutoMaker-Org/automaker
Length of output: 144
🏁 Script executed:
# Check if worktree routes use services
ls -la apps/server/src/routes/worktree/Repository: AutoMaker-Org/automaker
Length of output: 420
🏁 Script executed:
# List worktree routes
ls -la apps/server/src/routes/worktree/routes/Repository: AutoMaker-Org/automaker
Length of output: 2288
🏁 Script executed:
# Check the common.ts file in worktree
cat apps/server/src/routes/worktree/common.tsRepository: AutoMaker-Org/automaker
Length of output: 7047
🏁 Script executed:
# Check another route to see if services are used
cat apps/server/src/routes/worktree/routes/create.ts | head -80Repository: AutoMaker-Org/automaker
Length of output: 2844
🏁 Script executed:
# Search for where createEventEmitter is being used in the codebase
rg "createEventEmitter" apps/server/src/ -A 3 | head -60Repository: AutoMaker-Org/automaker
Length of output: 887
Refactor to follow established patterns and support older Git versions.
This route should follow the architectural patterns established in create.ts:
-
Git version compatibility:
--initial-branchrequires Git >= 2.28. Use theensureInitialCommit()helper fromcommon.ts(which already exists) or implement a fallback withgit init+git branch -M main. -
Code quality: Replace raw
execAsyncshell commands withexecGitCommand()fromcommon.tsfor safe, array-based argument passing (prevents injection). -
Architecture: Following
create.ts, this route should delegate to a service, emit events viacreateEventEmitter(), and use@automaker/git-utilswhere applicable (e.g.,isGitRepo()).
Consider delegating git initialization to a service that emits progress events to the frontend, consistent with other worktree operations.
🤖 Prompt for AI Agents
In `@apps/server/src/routes/worktree/routes/init-git.ts` around lines 46 - 53, The
current git init code uses execAsync with --initial-branch (incompatible with
Git <2.28) and bypasses established patterns; replace this with a delegated
service that uses execGitCommand() from common.ts and the ensureInitialCommit()
helper (or fallback to git init + git branch -M main) to create the initial
commit, call isGitRepo() from `@automaker/git-utils` to verify repository state,
and emit progress/events via createEventEmitter() consistent with create.ts so
the route delegates to that service rather than running raw shell commands.
Git initialization now explicitly specifies --initial-branch=main to match GitHub's default branch standard (since October 2020). This prevents the branch name mismatch that caused features to disappear from the UI when pushing to GitHub.
Fixes #734
Summary by CodeRabbit