Skip to content

fix(desktop): align tracking remote handling across git calls#2531

Merged
Kitenite merged 1 commit into
superset-sh:mainfrom
Kitenite:kitenite/the-approach-and-i
Mar 17, 2026
Merged

fix(desktop): align tracking remote handling across git calls#2531
Kitenite merged 1 commit into
superset-sh:mainfrom
Kitenite:kitenite/the-approach-and-i

Conversation

@Kitenite
Copy link
Copy Markdown
Collaborator

@Kitenite Kitenite commented Mar 17, 2026

Summary

  • extend tracking-remote resolution in the desktop git router so branch-specific push/fetch/set-upstream flows consistently use the branch's actual upstream remote instead of assuming origin
  • reuse a shared upstream-ref helper and update GitHub PR status branch-exists checks to query the current branch's tracking remote as well
  • keep base-branch comparisons against origin/<defaultBranch> unchanged, and add regression tests for upstream parsing plus remote-specific branch existence

Test plan

  • bun test apps/desktop/src/lib/trpc/routers/changes/git-operations.test.ts apps/desktop/src/lib/trpc/routers/changes/utils/pull-request-url.test.ts apps/desktop/src/lib/trpc/routers/workspaces/utils/upstream-ref.test.ts apps/desktop/src/lib/trpc/routers/workspaces/utils/git.test.ts
  • bunx @biomejs/biome@2.4.2 check apps/desktop/src/lib/trpc/routers/changes/git-operations.ts apps/desktop/src/lib/trpc/routers/changes/utils/pull-request-url.ts apps/desktop/src/lib/trpc/routers/workspaces/utils/git.test.ts apps/desktop/src/lib/trpc/routers/workspaces/utils/git.ts apps/desktop/src/lib/trpc/routers/workspaces/utils/github/github.ts apps/desktop/src/lib/trpc/routers/workspaces/utils/upstream-ref.test.ts apps/desktop/src/lib/trpc/routers/workspaces/utils/upstream-ref.ts

Follow-up to #2517.


Summary by cubic

Make all desktop git operations use the current branch’s tracking remote instead of assuming origin, so fetch/push/set-upstream and PR status checks work correctly with forks and non-origin remotes.

  • Bug Fixes

    • Resolve tracking remote from @{upstream} with a safe fallback to origin and use it for fetch and --set-upstream push.
    • branchExistsOnRemote accepts a remote name; GitHub PR status now checks the branch on the tracking remote.
    • Keep base comparisons against origin/<defaultBranch> unchanged.
  • Refactors

    • Introduced shared upstream-ref utility (parseUpstreamRef, resolveTrackingRemoteName) and reused it in PR URL building and git ops.
    • Added tests for upstream parsing and remote-specific branch existence.

Written for commit 89a8738. Summary will update on new commits.

Summary by CodeRabbit

Release Notes

  • Bug Fixes

    • Improved handling of git repositories using non-default remotes for branch tracking and push operations.
  • Refactor

    • Consolidated upstream reference utilities for better code organization.
  • Tests

    • Added test coverage for remote branch operations and upstream reference parsing.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Mar 17, 2026

📝 Walkthrough

Walkthrough

This PR introduces remote-aware git operations that support tracking remotes beyond "origin". A new upstream-ref utility module parses and resolves tracking remote names, enabling functions like branch existence checks and push operations to work with worktree-specific remotes. Common logic is refactored into the new module and re-exported from existing APIs.

Changes

Cohort / File(s) Summary
Upstream reference utilities
apps/desktop/src/lib/trpc/routers/workspaces/utils/upstream-ref.ts, apps/desktop/src/lib/trpc/routers/workspaces/utils/upstream-ref.test.ts
New module providing ParsedUpstreamRef interface, parseUpstreamRef() to parse remote/branch format, and resolveTrackingRemoteName() to extract remote names from upstream refs with fallback support.
API consolidation
apps/desktop/src/lib/trpc/routers/changes/utils/pull-request-url.ts
Re-exports ParsedUpstreamRef and parseUpstreamRef from upstream-ref utility module instead of declaring them locally; removes duplicate declarations.
Remote-aware git operations
apps/desktop/src/lib/trpc/routers/workspaces/utils/git.ts, apps/desktop/src/lib/trpc/routers/workspaces/utils/git.test.ts
Extends branchExistsOnRemote() with optional remoteName parameter; adds getTrackingRemoteNameForWorktree() to resolve per-worktree tracking remote; updates categorizeGitError() to accept dynamic remote name instead of hard-coded "origin".
Remote resolution in git operations
apps/desktop/src/lib/trpc/routers/changes/git-operations.ts
Adds getTrackingRemote() helper; updates fetchCurrentBranch() and pushWithSetUpstream() to derive remote via getTrackingRemote() instead of assuming "origin"; extends pushWithSetUpstream signature with optional remote parameter.
Integration with branch checks
apps/desktop/src/lib/trpc/routers/workspaces/utils/github/github.ts
Retrieves per-worktree tracking remote via getTrackingRemoteNameForWorktree() and passes it to branchExistsOnRemote() for accurate branch existence verification.

Sequence Diagram(s)

sequenceDiagram
    participant Client
    participant GitOps as Git Operations
    participant UpstreamRef as Upstream Ref Utils
    participant Git as Git CLI

    rect rgba(100, 200, 150, 0.5)
    Note over Client,Git: Old Flow (Hard-coded Origin)
    Client->>GitOps: pushWithSetUpstream(git, branch)
    GitOps->>Git: push origin branch<br/>(hard-coded "origin")
    Git-->>GitOps: success
    GitOps-->>Client: result
    end

    rect rgba(150, 150, 200, 0.5)
    Note over Client,Git: New Flow (Tracking Remote Resolution)
    Client->>GitOps: pushWithSetUpstream(git, branch, remote?)
    GitOps->>Git: rev-parse @{upstream}
    Git-->>GitOps: upstream ref (e.g., upstream/main)
    GitOps->>UpstreamRef: resolveTrackingRemoteName(upstreamRef)
    UpstreamRef-->>GitOps: resolved remote (e.g., "upstream")
    GitOps->>Git: push [resolved-remote] branch
    Git-->>GitOps: success
    GitOps-->>Client: result
    end
Loading

Estimated Code Review Effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Poem

🐰 A rabbit hops through remotes with glee,
No longer bound to "origin" alone, you see!
Upstream tracking guides each push and pull,
Multiple branches, our quiver is full! 🌿✨

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 8.33% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and specifically summarizes the main objective of the PR: aligning tracking remote handling across git calls, which is the primary focus of all changes.
Description check ✅ Passed The PR description provides a clear summary, addresses related issues (follow-up to #2517), includes a comprehensive test plan with specific commands executed, and covers bug fixes and refactors. However, it lacks explicit selection of the 'Type of Change' checkboxes from the template.

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

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
📝 Coding Plan
  • Generate coding plan for human review comments

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.

Copy link
Copy Markdown
Contributor

@cubic-dev-ai cubic-dev-ai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No issues found across 7 files

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (2)
apps/desktop/src/lib/trpc/routers/changes/git-operations.ts (1)

35-44: Consider consolidating with getTrackingRemoteNameForWorktree.

This function duplicates logic from getTrackingRemoteNameForWorktree in git.ts. The only difference is the input type (SimpleGit vs worktreePath: string). Consider either:

  1. Reusing getTrackingRemoteNameForWorktree by extracting the worktree path from the SimpleGit instance
  2. Exporting a shared helper that both can use

This is a minor duplication concern and could be addressed in a follow-up.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@apps/desktop/src/lib/trpc/routers/changes/git-operations.ts` around lines 35
- 44, The getTrackingRemote function duplicates logic already implemented in
getTrackingRemoteNameForWorktree; update it to reuse shared logic by either
extracting the worktree path from the SimpleGit instance and calling
getTrackingRemoteNameForWorktree(worktreePath), or move the core logic that
calls git.rev-parse and resolveTrackingRemoteName into a new exported helper
(e.g., resolveTrackingRemoteFromRawUpstream) that both getTrackingRemote and
getTrackingRemoteNameForWorktree call; ensure you continue to catch errors and
default to "origin" as the current behavior.
apps/desktop/src/lib/trpc/routers/workspaces/utils/upstream-ref.test.ts (1)

26-30: Consider adding a test for custom fallback parameter.

The resolveTrackingRemoteName function accepts a custom fallback parameter, but this isn't tested. Consider adding a test case to verify this behavior.

💡 Suggested additional test case
test("uses custom fallback when provided", () => {
	expect(resolveTrackingRemoteName("", "upstream")).toBe("upstream");
	expect(resolveTrackingRemoteName(null, "fork")).toBe("fork");
});
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@apps/desktop/src/lib/trpc/routers/workspaces/utils/upstream-ref.test.ts`
around lines 26 - 30, Add a test that verifies resolveTrackingRemoteName
respects its optional fallback parameter: update the test suite in
upstream-ref.test.ts to include a new test (e.g., "uses custom fallback when
provided") that calls resolveTrackingRemoteName with empty string/null and a
custom fallback string (like "upstream" or "fork") and asserts the return equals
that fallback; ensure both empty string and null cases are covered to mirror the
existing fallback tests.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@apps/desktop/src/lib/trpc/routers/changes/git-operations.ts`:
- Around line 35-44: The getTrackingRemote function duplicates logic already
implemented in getTrackingRemoteNameForWorktree; update it to reuse shared logic
by either extracting the worktree path from the SimpleGit instance and calling
getTrackingRemoteNameForWorktree(worktreePath), or move the core logic that
calls git.rev-parse and resolveTrackingRemoteName into a new exported helper
(e.g., resolveTrackingRemoteFromRawUpstream) that both getTrackingRemote and
getTrackingRemoteNameForWorktree call; ensure you continue to catch errors and
default to "origin" as the current behavior.

In `@apps/desktop/src/lib/trpc/routers/workspaces/utils/upstream-ref.test.ts`:
- Around line 26-30: Add a test that verifies resolveTrackingRemoteName respects
its optional fallback parameter: update the test suite in upstream-ref.test.ts
to include a new test (e.g., "uses custom fallback when provided") that calls
resolveTrackingRemoteName with empty string/null and a custom fallback string
(like "upstream" or "fork") and asserts the return equals that fallback; ensure
both empty string and null cases are covered to mirror the existing fallback
tests.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: d317cae6-988e-4a8f-8485-c09b7a4863bf

📥 Commits

Reviewing files that changed from the base of the PR and between 71df806 and 89a8738.

📒 Files selected for processing (7)
  • apps/desktop/src/lib/trpc/routers/changes/git-operations.ts
  • apps/desktop/src/lib/trpc/routers/changes/utils/pull-request-url.ts
  • apps/desktop/src/lib/trpc/routers/workspaces/utils/git.test.ts
  • apps/desktop/src/lib/trpc/routers/workspaces/utils/git.ts
  • apps/desktop/src/lib/trpc/routers/workspaces/utils/github/github.ts
  • apps/desktop/src/lib/trpc/routers/workspaces/utils/upstream-ref.test.ts
  • apps/desktop/src/lib/trpc/routers/workspaces/utils/upstream-ref.ts

@Kitenite Kitenite merged commit 9fecc36 into superset-sh:main Mar 17, 2026
6 of 7 checks passed
@Kitenite Kitenite deleted the kitenite/the-approach-and-i branch March 17, 2026 09:16
z3thon pushed a commit to z3thon/superset that referenced this pull request Mar 19, 2026
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