Skip to content

feat: allow changing or removing the git remote#149

Merged
erictli merged 6 commits into
mainfrom
feat/change-git-remote
May 5, 2026
Merged

feat: allow changing or removing the git remote#149
erictli merged 6 commits into
mainfrom
feat/change-git-remote

Conversation

@erictli
Copy link
Copy Markdown
Owner

@erictli erictli commented May 5, 2026

Summary

  • Adds Change and Remove controls next to the configured remote in Version Control settings
  • New Tauri commands git_set_remote_url (git remote set-url origin <url>) and git_remove_remote (git remote remove origin) — both preserve local history
  • Fixes How to change the branch in version control #147: a user who added the wrong remote URL can now fix it without disconnecting/reiniting the repo

Behavior

  • Display mode: "Change" button appears inline next to the remote URL
  • Edit mode: input pre-filled with current URL; Save / Cancel / Remove buttons. Save is disabled when unchanged or empty. Enter saves, Escape cancels.

Test plan

  • Settings → Version Control with a remote configured shows "Change" next to the URL
  • Clicking Change opens an input pre-filled with the current URL; editing + Save updates the remote (verify with git remote -v)
  • Save is disabled when the URL is unchanged or empty
  • Cancel / Escape exit edit mode without changes
  • Remove deletes the origin remote and the UI returns to the "Not connected / Add Remote" state
  • Invalid URL (e.g. foo) surfaces the validation error
  • Tracking row hides correctly after remove (no stale origin/<branch>)

🤖 Generated with Claude Code

Summary by CodeRabbit

  • New Features

    • Edit and update the configured Git remote URL from Settings with an edit flow (Change → Save/Cancel).
    • Remove the configured Git remote from Settings; removal is idempotent if already absent.
    • Enter/Escape keyboard shortcuts and parsed remote link to open the web URL.
  • UI / Bug Fixes

    • Status shows a single “Status / An error occurred” row when there’s an error and refreshes after remote changes.
    • Hide file-changed count in the footer when an error is present; error indicator styling updated.

Adds Change/Remove controls next to the configured remote in Version
Control settings, backed by new git_set_remote_url and git_remove_remote
Tauri commands. Resolves #147 — users who added the wrong remote URL
can now fix it without losing local history.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 5, 2026

Important

Review skipped

This PR was authored by the user configured for CodeRabbit reviews. CodeRabbit does not review PRs authored by this user. It's recommended to use a dedicated user account to post CodeRabbit review feedback.

⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: d1c29f0a-171c-43e2-b053-b05928b1b588

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • ✅ Review completed - (🔄 Check again to review again)
📝 Walkthrough

Walkthrough

Adds end-to-end Git remote management: backend helpers to set/remove the origin remote, Tauri commands exposing them, frontend service wrappers and context actions, UI to edit/remove the remote in settings, and minor footer indicator/error styling tweaks.

Changes

Git Remote Management

Layer / File(s) Summary
Data / Backend Git ops
src-tauri/src/git.rs
Added set_remote_url(path, url) (trims & validates URL, runs git remote set-url origin <url>, returns GitResult, maps "No such remote" stderr to a clear error) and remove_remote(path) (runs git remote remove origin, treats "No such remote" as idempotent success).
Tauri Command Handlers
src-tauri/src/lib.rs
Added #[tauri::command] handlers git_set_remote_url and git_remove_remote that read app_config.notes_folder, call the backend helpers in blocking tasks, and registered them in the invoke handler.
Frontend Service Layer
src/services/git.ts
Exported setRemoteUrl(url) and removeRemote() which invoke git_set_remote_url / git_remove_remote and return GitResult.
Context Layer
src/context/GitContext.tsx
GitContextValue gains setRemoteUrl and removeRemote; GitProvider implements them (manage isAddingRemote/lastError, call gitService, call refreshStatus() on success) and updated useMemo wiring.
UI Component & State
src/components/settings/GeneralSettingsSection.tsx
Added isEditingRemote state and handlers (handleStartEditRemote, handleCancelEditRemote, handleSaveRemoteUrl, handleRemoveRemote); remote section now toggles between read-only display and inline edit form (Save/Cancel/Remove + Enter/Escape handling); disabling Git clears edit mode; stats area shows a single error row when lastError exists.
Small UI Tweak
src/components/layout/Footer.tsx
“Files changed” indicator now hides when lastError exists; error indicator text hover color changed to red variants.

Sequence Diagram

sequenceDiagram
    participant User
    participant UI as Settings UI
    participant Context as Git Context
    participant Service as Git Service
    participant Tauri as Tauri Command
    participant Git as Git Backend

    User->>UI: Open edit / change remote
    UI->>Context: setRemoteUrl(newUrl) or removeRemote()
    Context->>Service: setRemoteUrl(newUrl) / removeRemote()
    Service->>Tauri: invoke("git_set_remote_url",{url:newUrl}) / invoke("git_remove_remote")
    Tauri->>Git: run `git remote set-url origin <newUrl>` / `git remote remove origin`
    Git-->>Tauri: success or stderr (may contain "No such remote")
    Tauri-->>Service: GitResult
    Service-->>Context: GitResult
    Context->>Context: refreshStatus() on success
    Context-->>UI: updated status or error
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

  • erictli/scratch#8: Modifies src/context/GitContext.tsx and refactors refreshStatus; related because this PR adds setRemoteUrl/removeRemote callbacks that invoke refreshStatus().

Poem

🐰 I nudge the origin with a twitch of paw,
A URL trimmed neat, no need to gnaw.
From UI click to Tauri call,
Set or remove — I handle all.
Happy repo hops, hooray, hurrah!

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 56.25% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the main change—adding functionality to change or remove git remotes—and aligns with the core objective of resolving issue #147.
Linked Issues check ✅ Passed The PR implements all coding requirements from issue #147: new backend commands (git_set_remote_url, git_remove_remote) and frontend UI controls to change or remove the configured remote while preserving repository state and history.
Out of Scope Changes check ✅ Passed All changes are directly scoped to enabling remote URL management and removal. The error display styling adjustments (red text, error row suppression) are supporting changes that enhance the UX for remote operation feedback.

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


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

Copy link
Copy Markdown

@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.

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src-tauri/src/git.rs`:
- Around line 470-476: The removal routine currently returns an error when
stderr contains "No such remote"; update the branch in git.rs that checks stderr
(the block creating GitResult with error Some("No 'origin' remote configured"))
to treat this case as a success (set success: true and error: None) so removing
an already-missing 'origin' is idempotent and the frontend can converge to "not
connected" (you can keep or set message to a neutral value like None or a short
informational string). Ensure this change is applied in the function handling
the remote removal output where output.stderr is parsed.
- Around line 407-419: Trim and normalize the incoming url once in
set_remote_url (e.g., let normalized = url.trim()) then use that normalized
value for both validation and the git command invocation; call
is_valid_remote_url(&normalized) instead of is_valid_remote_url(url) and pass
normalized to git_cmd().args([... , "origin", &normalized]) so whitespace-padded
URLs aren't written to git.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: c9c5289c-5f49-4361-bb07-8af5890b0df4

📥 Commits

Reviewing files that changed from the base of the PR and between 97994b8 and 8f3473c.

📒 Files selected for processing (5)
  • src-tauri/src/git.rs
  • src-tauri/src/lib.rs
  • src/components/settings/GeneralSettingsSection.tsx
  • src/context/GitContext.tsx
  • src/services/git.ts

Comment thread src-tauri/src/git.rs
Comment thread src-tauri/src/git.rs
erictli and others added 5 commits May 4, 2026 21:24
Replaces the changes/commits-to-push/commits-to-pull rows with a single
"An error occurred" row when status.error is set, so we don't display
counts that may be incorrect alongside the error message.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
- Use a plain text button for Change, matching the Install link in
  integrations, instead of a ghost-variant Button.
- Hide stats whenever lastError is set (not just status.error), so
  action errors like a failed push also collapse the stale counts.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
The footer was rendering both 'Files changed' and 'An error occurred'
side-by-side. Gate the changes indicator on !lastError so the count
isn't shown alongside an error message.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
…talize

- remove_remote: treat 'No such remote' as success so removing an
  already-missing origin converges to 'not connected' on the frontend.
- set_remote_url: trim+normalize the incoming URL once and use the
  normalized value for both validation and the git invocation, so
  whitespace-padded URLs aren't written to git config.
- Settings error block: switch capitalize → first-letter:capitalize so
  only the first character is uppercased (preserves casing in URLs,
  hashes, branch names).

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@erictli erictli merged commit a638f02 into main May 5, 2026
2 checks passed
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.

How to change the branch in version control

1 participant