fix(git-init): push workspace to GitHub when remote already has main (#256)#288
Open
fix(git-init): push workspace to GitHub when remote already has main (#256)#288
Conversation
…256) `initialize_git_in_container` had two code paths depending on whether the target GitHub repo already had a `main` branch. The empty-repo path ended with `git push -u origin main --force`. The `remote_has_main` path did `git reset origin/main` → `git add .` → `git commit` and then *nothing* — the new commit lived inside the container but never reached GitHub. Result: whenever a user initialized GitHub sync against any repo that had a README or prior content, the UI reported success, the database row was written, but the agent's workspace never actually landed on GitHub. Fix: add `git push -u origin main` to the `remote_has_main` command list. Fast-forward push (not `--force`) since we're one commit ahead of origin/main and want to preserve any history already on the remote. Tests: 4 unit tests in `tests/unit/test_github_init_push.py` covering the empty-remote path (regression pin), the fixed remote-has-main path, command ordering, and the nothing-to-commit edge case. Verified they fail against the pre-fix code and pass against the fix. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #256.
initialize_github_syncsilently succeeded without actually pushing the agent's workspace to GitHub whenever the target repo already had amainbranch (e.g., a README).Root cause
initialize_git_in_containerinservices/git_service.pyhad two code paths depending on whetherorigin/mainexisted:main): ended withgit push -u origin main --force✓main: didgit reset origin/main→git add .→git commit— and then nothing. No push.The commit lived inside the container forever. The DB row was written, the UI reported success, but GitHub never saw the workspace. This triggered in two very common scenarios:
Fix
Added
git push -u origin mainto theremote_has_maincommand list — fast-forward push (not--force), since we're one commit ahead oforigin/mainand want to preserve any history already on the remote. Push runs even on the "nothing to commit" path so upstream tracking still gets set.Test plan
Unit tests (
tests/unit/test_github_init_push.py, 4 new tests)test_empty_remote_force_pushes— regression pin for the previously-working empty-repo pathtest_existing_remote_pushes_after_commit— the fix: push now happens in theremote_has_mainbranchtest_existing_remote_reset_precedes_commit— command order: reset → add → commit → pushtest_existing_remote_nothing_to_commit_still_pushes— push runs even when commit was a no-opVerified that 3 of 4 tests fail against the pre-fix code and all 4 pass with the fix.
Manual end-to-end (verified firsthand against real GitHub)
YOUR_USER/trinity-256-test --add-readme, created a fresh blank Trinity agent, ran Initialize GitHub Sync against it. Confirmed the agent's workspace commit now appears on GitHub on top of the README commit. (Before the fix: the UI reported success but only the README existed remotely.)--add-readme), ran init, confirmed the empty-remote force-push path still produces a singleInitial commit from Trinity Agentonmainwith the workspace contents.Notes / follow-ups (out of scope for this PR)
https://oauth2:{PAT}@github.com/...embeds the PAT in the remote URL. On git errors, git often writes the remote URL to stderr, which then flows into the HTTPException detail and server logs. Blast radius is low (gated onOwnedAgentByName, so the leak is to the PAT owner themselves) but worth fixing separately viagit credential.helper/GIT_ASKPASS."Nothing to commit"string-matching to detect no-op commits is fragile but pre-existing.🤖 Generated with Claude Code