Skip to content

Add SSH key support - #16

Merged
letmutex merged 2 commits into
mainfrom
ssh-key-support
Jun 21, 2026
Merged

letmutex merged 2 commits into
mainfrom
ssh-key-support

Conversation

@letmutex

@letmutex letmutex commented Jun 21, 2026 •

Copy link
Copy Markdown
Owner

Add SSH support using git config core.sshCommand "ssh -i SSH_KEY_PATH -o IdentitiesOnly=yes"

Closes #13

Summary by CodeRabbit

  • New Features

    • Added SSH key authentication as an alternative to Token/PAT for adding and editing accounts
    • SSH key selection UI now scans ~/.ssh, with an option to enter a custom key path
    • When using SSH keys, Git is configured to use SSH transport automatically
    • When multiple HTTP remotes exist, the app prompts to select the target remote URL
  • Improvements

    • Token authentication now runs before any Git configuration changes
    • Switch flow enables HTTP path credentials for the selected remote when applicable
  • Bug Fixes

    • Authentication failures now stop the switch and surface the error output
    • “No token found” warnings are now shown only when relevant to the transport mode

@coderabbitai

coderabbitai Bot commented Jun 21, 2026 •

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 043597d6-5f16-495a-897e-4a74d19e26eb

📥 Commits

Reviewing files that changed from the base of the PR and between a709101 and bccec18.

📒 Files selected for processing (1)
  • src/utils.rs
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/utils.rs

📝 Walkthrough

Walkthrough

The PR adds an optional ssh_key field to the Account struct and introduces utilities for HTTP-remote detection, SSH command construction, SSH key scanning from ~/.ssh, and a Result-returning git_credential_approve. These are wired into the add, git, and list commands so SSH keys can be selected during account creation, injected into git invocations, applied or removed during account switching, and edited interactively.

Changes

SSH Key Account Support

Layer / File(s) Summary
Account model, transport utilities, and credential/SSH helpers
src/models.rs, src/utils.rs
Adds ssh_key: Option<String> to Account; introduces Remote struct, HTTP-remote/transport-detection functions, git_ssh_command, and scan_ssh_keys; updates git_credential_approve to return Result<(), String> and captures stderr; adds unit tests.
Add command: auth-type selection and SSH key capture
src/commands/add.rs
Replaces single-path token/host prompting with an auth-type selection menu; Token/PAT branch collects token and host; SSH branch calls scan_ssh_keys and allows manual path entry; browser-login path sets ssh_key: None; Account construction stores both host and ssh_key.
Git command: SSH transport injection and conditional token warning
src/commands/git.rs
Injects -c core.sshCommand=... into git when the account has an ssh_key; suppresses the "no token found" warning when the account has an SSH key and git args do not indicate HTTP transport.
Account switch: credential approval, SSH config, and managed-key detection
src/commands/list.rs
apply_switch authenticates before applying git config: selects target_url from HTTP remotes, calls git_credential_approve and aborts on failure, then sets user.name/user.email, gitas.alias, core.sshCommand, and credential.username; adds current_ssh_command_is_gitas_managed helper.
Account edit: SSH Key field and selection UI
src/commands/list.rs
Adds an "SSH Key" field to the edit menu, a scan-and-select branch for choosing keys, manual path input, and renumbers the "cancel" option.

Sequence Diagram(s)

sequenceDiagram
  participant User
  participant add_command as add (manual flow)
  participant scan_ssh_keys
  participant Account

  User->>add_command: select "SSH Key" auth type
  add_command->>scan_ssh_keys: scan_ssh_keys(username, email)
  scan_ssh_keys-->>add_command: (display_items, key_paths, default_idx)
  add_command->>User: show key selection menu
  User->>add_command: choose key or enter custom path
  add_command->>Account: construct with ssh_key = chosen_path
Loading
sequenceDiagram
  participant gitas_git as gitas git
  participant utils
  participant git_process as git

  gitas_git->>utils: resolve account → ssh_key present?
  alt ssh_key present
    gitas_git->>utils: git_ssh_command(ssh_key)
    utils-->>gitas_git: "ssh -i <key_path>"
    gitas_git->>git_process: git -c core.sshCommand="ssh -i <key_path>" <args>
  else no ssh_key
    gitas_git->>utils: git_args_use_http_transport(args)?
    gitas_git->>git_process: git <args>
  end
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~60 minutes

Poem

🐇 Hop, hop, a key in my paw,
~/.ssh holds secrets galore,
I scan each file with a careful claw,
Switch accounts — one key, one door.
Token or SSH, the choice is yours,
Gitas now guards all your repos! 🔑

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 17.39% 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 'Add SSH key support' directly and concisely describes the main objective of the pull request, which is to add SSH key functionality to the gitas project.
Linked Issues check ✅ Passed The PR successfully implements SSH key support with accounts as requested in issue #13, allowing users to attach SSH keys to Git accounts and switching them conditionally based on the active account.
Out of Scope Changes check ✅ Passed All code changes are directly related to implementing SSH key support across account management, Git configuration, and utilities as specified in the linked issue.

✏️ 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 ssh-key-support

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.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🧹 Nitpick comments (1)
src/commands/git.rs (1)

23-28: 💤 Low value

Consider escaping special characters in SSH key paths.

The git_ssh_command utility wraps the path in double quotes, which handles spaces. However, if a manually-entered path contains embedded double-quote characters, the resulting command string would be malformed. While rare in practice (and low-risk since this is a local CLI tool with user-provided input), you could add basic validation or escaping.

One option: reject paths containing " characters during input, or escape them:

let sanitized = ssh_key.replace('"', r#"\""#);
🤖 Prompt for 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.

In `@src/commands/git.rs` around lines 23 - 28, The SSH key path passed to the
git_ssh_command function in the code block handling account.ssh_key may contain
embedded double-quote characters, which would break the resulting command string
even though spaces are handled. Either validate and reject SSH key paths that
contain double-quote characters during input, or escape those characters in the
ssh_key variable before passing it to git_ssh_command by replacing any
double-quote characters with their escaped equivalent before the format! call is
executed.
🤖 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.

Nitpick comments:
In `@src/commands/git.rs`:
- Around line 23-28: The SSH key path passed to the git_ssh_command function in
the code block handling account.ssh_key may contain embedded double-quote
characters, which would break the resulting command string even though spaces
are handled. Either validate and reject SSH key paths that contain double-quote
characters during input, or escape those characters in the ssh_key variable
before passing it to git_ssh_command by replacing any double-quote characters
with their escaped equivalent before the format! call is executed.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: d3b74a2f-23d7-48a8-99e2-cd5bca827a8d

📥 Commits

Reviewing files that changed from the base of the PR and between 2e37b73 and a709101.

📒 Files selected for processing (5)
  • src/commands/add.rs
  • src/commands/git.rs
  • src/commands/list.rs
  • src/models.rs
  • src/utils.rs

@letmutex
letmutex merged commit 75fe423 into main Jun 21, 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.

Support switching SSH key along with Git username and email

1 participant