Skip to content

fix(host-service): read remote URLs from git config, not git remote -v#4065

Merged
Kitenite merged 2 commits into
mainfrom
fix-remote-url-via-git-config
May 5, 2026
Merged

fix(host-service): read remote URLs from git config, not git remote -v#4065
Kitenite merged 2 commits into
mainfrom
fix-remote-url-via-git-config

Conversation

@Kitenite
Copy link
Copy Markdown
Collaborator

@Kitenite Kitenite commented May 4, 2026

Summary

  • git remote -v appends partial-clone markers ([blob:none], [treeless], …) after (fetch) whenever remote.<name>.promisor is set. The parser anchored on (fetch)$ silently dropped those lines, and resolveLocalRepo fell back to the alphabetically-first remote — e.g. origin: superset-sh/superset was dropped, leaving andreasasprou/superset to win for users who cloned with --filter=blob:none.
  • Fix: read remotes from git config --get-regexp '^remote\..*\.url$' instead. The format is rigid and machine-stable (<key> <value> per line, no human-readable suffix), which kills the entire class of git remote -v format-drift bugs at the source rather than patching the regex.
  • Alternative considered: tightening the existing regex to tolerate [blob:none] (fix(host-service): tolerate [blob:none] suffix in git remote -v #4064). That works for the reported bug but leaves the parser dependent on git remote -v's human-readable format — any future cosmetic addition resurfaces the same class. This PR supersedes that approach.

Test plan

  • bun test packages/host-service/src/trpc/router/project/utils/resolve-repo.test.ts — 24 pass (includes new regression test for --filter=blob:none + alphabetically-earlier sibling remote)
  • bun test host-service full suite — 489 pass / 0 fail
  • bun run typecheck host-service — clean
  • bun run lint — clean
  • End-to-end against a real partial-clone repo with aaa (alphabetical first) + originresolveLocalRepo correctly returns origin → superset-sh/superset
  • Manually re-add a --filter=blob:none clone in the v2 desktop UI and confirm origin is detected

Summary by cubic

Read Git remote URLs from git config instead of git remote -v to make detection stable and fix wrong remote selection in partial clones. Ensures resolveLocalRepo picks origin when present.

  • Bug Fixes
    • Use git config --get-regexp '^remote\..*\.url$' instead of parsing git remote -v.
    • Handle partial-clone markers like [blob:none] so origin is not skipped; adds a regression test and minor cleanup in getAllRemoteUrls.

Written for commit f012f70. Summary will update on new commits.

Summary by CodeRabbit

  • Bug Fixes

    • Fixed remote URL parsing so the correct repository remote (e.g., origin) is chosen even when partial-clone filters are configured.
  • Tests

    • Added an integration test to verify remote selection and parsing when remotes use partial-clone settings.

`git remote -v` appends partial-clone markers like `[blob:none]` after
`(fetch)` whenever `remote.<name>.promisor` is set, so a parser anchored
on `(fetch)$` silently dropped those lines and `resolveLocalRepo` fell
back to the alphabetically-first remote. For users who cloned with
`--filter=blob:none` (common for monorepos), the v2 add-folder flow
detected the wrong remote — e.g. `origin: superset-sh/superset` was
dropped, leaving `andreasasprou/superset` to win.

Read remotes from `git config --get-regexp '^remote\..*\.url$'` instead.
The format is rigid and machine-stable (`<key> <value>` per line, no
human-readable suffixes), so this kills the entire format-fragility
class — partial-clone markers and any future `git remote -v` cosmetic
drift across git versions are no longer load-bearing.

Includes a regression test for the partial-clone case with an
alphabetically-earlier sibling remote.
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 4, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 465bc862-33ee-42c4-8283-5e0dffcd2e73

📥 Commits

Reviewing files that changed from the base of the PR and between b4f9276 and f012f70.

📒 Files selected for processing (1)
  • packages/host-service/src/trpc/router/project/utils/git-remote.ts
🚧 Files skipped from review as they are similar to previous changes (1)
  • packages/host-service/src/trpc/router/project/utils/git-remote.ts

📝 Walkthrough

Walkthrough

getAllRemoteUrls now reads remote URLs from git config keys (git config --get-regexp ^remote\..*\.url$) and extracts remote.<name>.url entries; a regression test ensures origin is chosen when configured as a partial clone (e.g., remote.origin.partialclonefilter=blob:none).

Changes

Remote URL Parsing & Partial Clone Support

Layer / File(s) Summary
Core Implementation
packages/host-service/src/trpc/router/project/utils/git-remote.ts
Replaced parsing of git remote -v with git config --get-regexp ^remote\..*\.url$. Splits each config line at first space, extracts remote name via ^remote\.(.+)\.url$, and populates the name→URL map only when both are non-empty.
Documentation Update
packages/host-service/src/trpc/router/project/utils/git-remote.ts
Updated module comments to describe reading remote URLs from git config to avoid partial-clone markers present in git remote -v output.
Regression Test
packages/host-service/src/trpc/router/project/utils/resolve-repo.test.ts
Added test verifying origin is selected and parsed correctly when configured as a partial clone (remote.origin.promisor=true, remote.origin.partialclonefilter=blob:none).

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

🐰 I nibble config keys at night,
parsing remotes with gentle bite.
No stray “[blob:none]” to mar the view,
origin found — the map is true.
Hooray — the remotes are right!

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and specifically describes the main change: switching from parsing git remote output to reading from git config for remote URL detection.
Description check ✅ Passed The description includes all critical sections: problem statement with context, solution rationale, alternative considered, and comprehensive testing details matching the template structure.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix-remote-url-via-git-config

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@greptile-apps
Copy link
Copy Markdown

greptile-apps Bot commented May 4, 2026

Greptile Summary

This PR replaces the git remote -v parsing approach in getAllRemoteUrls with git config --get-regexp '^remote\\..*\\.url$', fixing a regression where partial clones (using --filter=blob:none) caused the origin remote to be silently dropped because the old (fetch)$ anchor didn't tolerate the appended [blob:none] marker. A targeted regression test is added to verify the correct remote wins over an alphabetically-earlier sibling.

Confidence Score: 5/5

Safe to merge — targeted bug fix with full test coverage and no regressions introduced.

No P0 or P1 findings. The new parsing approach is strictly more correct than the previous one: it uses a machine-stable format, handles partial-clone markers naturally, and the .catch(() => '') + spaceIdx <= 0 guards cover the empty-output and no-remotes cases. The greedy regex for dotted remote names is intentional and correct. The regression test exercises exactly the reported failure scenario.

No files require special attention.

Important Files Changed

Filename Overview
packages/host-service/src/trpc/router/project/utils/git-remote.ts Replaces git remote -v parsing with git config --get-regexp for machine-stable remote URL extraction; logic is correct and edge cases (empty output, exit-code 1, dotted remote names) are all handled.
packages/host-service/src/trpc/router/project/utils/resolve-repo.test.ts Adds a well-scoped regression test for the partial-clone scenario with an alphabetically-earlier competing remote; test structure matches the existing suite style.

Sequence Diagram

sequenceDiagram
    participant C as Caller (resolveLocalRepo)
    participant G as getAllRemoteUrls
    participant S as SimpleGit

    C->>G: getAllRemoteUrls(git)
    G->>S: git.raw([config, --get-regexp, ^remote\..*\.url$])
    alt No remotes / exit code 1
        S-->>G: throws, caught, returns empty string
        G-->>C: empty Map
    else Has remotes
        S-->>G: remote.origin.url https://github.com/Acme/App.git
        loop each output line
            G->>G: split on first space to get key and url
            G->>G: key.match to extract remoteName
            G->>G: remotes.set(remoteName, url)
        end
        G-->>C: Map of remoteName to URL
    end
Loading

Reviews (1): Last reviewed commit: "fix(host-service): read remote URLs from..." | Re-trigger Greptile

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 5, 2026

🧹 Preview Cleanup Complete

The following preview resources have been cleaned up:

  • ✅ Neon database branch

Thank you for your contribution! 🎉

@Kitenite Kitenite merged commit 9cc8286 into main May 5, 2026
15 checks passed
@Kitenite Kitenite deleted the fix-remote-url-via-git-config branch May 5, 2026 00:58
@saddlepaddle saddlepaddle mentioned this pull request May 5, 2026
3 tasks
saddlepaddle added a commit that referenced this pull request May 5, 2026
Three fixes since v0.2.6:
- relay tunnel: carry binary WS frames as base64 so PTY output renders
  through cross-host workspaces (no more `[terminal] invalid server
  payload`) (#4066)
- host-service: read remote URLs from git config instead of `git remote
  -v` (#4065)
- cli: auto-refresh OAuth access token using the refresh token (#4069)

Push cli-v0.2.7 after this lands to fire the release pipeline.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant