Skip to content

feat(cli) - 修复 ensure ssh 过程中出现错误的 loading#298

Merged
zevwings merged 4 commits into
masterfrom
bugfix/fix-ensure-ssh-loading-error
Feb 27, 2026
Merged

feat(cli) - 修复 ensure ssh 过程中出现错误的 loading#298
zevwings merged 4 commits into
masterfrom
bugfix/fix-ensure-ssh-loading-error

Conversation

@zevwings
Copy link
Copy Markdown
Owner

PR Ready

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Refactoring (non-breaking change which does not change functionality)
  • Hotfix (urgent fix for production issues)
  • Chore (maintenance tasks and non-functional changes)

Summary

在关键的分支和 PR 操作前验证 SSH 配置,避免因 SSH 错误导致的拉取失败。

Key Changes

  • 在 branch/create、pr/create/branch、pr/merge 三个命令中加入 ensure_ssh_ready 调用
  • 统一并删除重复的导入语句
  • 保持原有 spinner UI,仅在 SSH 检查通过后执行拉取
  • 显式使用 PullOptions::no_stash() 保持 stash 行为不变

Changes

Features

  • 为分支创建、PR 创建分支、PR 合并命令添加 SSH 就绪检查

Refactors

  • 合并重复导入,统一 import 结构
  • 调整 spinner 包装顺序

Others

  • 更新错误映射以兼容 SSH 检查返回

Impact Analysis

Affected Modules

Module Impact Severity
branch/create 命令 加入 SSH 检查,可能在未配置 SSH 时中止命令,需要在 CI 环境中注意 medium
pr/create/branch 命令 同上,增加前置检查导致非交互式运行需额外配置 medium
pr/merge 命令 同上,合并流程在缺少 SSH 时会提前退出 medium

Risk Assessment

Overall risk: medium

Risk factors:

  • 在非交互式环境(如 CI)中 SSH 检查可能导致命令阻塞或提前退出
  • 错误信息可能对不熟悉 SSH 配置的用户不友好

Mitigation:

  • 提供 --skip-ssh-check 或类似的非交互式标志以在 CI 中绕过检查
  • 在文档和帮助信息中说明新增的 SSH 检查要求

Testing Suggestions

  • 在本地已配置 SSH 的环境下执行 branch/create、pr/create/branch、pr/merge,确认正常拉取
  • 在未配置 SSH 的环境下运行上述命令,验证能够捕获错误并给出提示
  • 在 CI/脚本环境中使用 --skip-ssh-check 标志,确保流程不被阻塞

Statistics

Metric Value
Total files 3
Additions +9
Deletions -6
Net change 3
Added files 0
Modified files 3
Deleted files 0
Renamed files 0

Review Info

  • Complexity: simple
  • Review priority: medium
  • Estimated review time: 15 minutes
  • Tags: feature, ssh, cli

The create branch command imported the same utility symbols twice, which caused unnecessary clutter and could lead to confusion during maintenance.

- Removed the duplicated `use crate::util::{ensure_ssh_ready, safe_pull, PullOptions};` line.
- Kept a single import for those utilities and retained the import block for branch‑related helpers.

This change improves code readability and reduces the risk of accidental divergent imports in the future.
Why:
- Push operations were scattered across many command modules, each handling SSH readiness and progress spinners separately. This caused code duplication, inconsistent error handling, and made future changes error‑prone.

What:
- Updated `util::sync::push::safe_push` to accept an `Option<String>` for the branch name, perform SSH readiness verification, execute the push with a unified spinner, and report success uniformly.
- Added a spinner and success message inside `safe_push` so callers no longer need to wrap the call.
- Adjusted all command callers (`branch::rename`, `commit`, `pr::create`, `pr::update`, `repo::push`) to use the new signature (`safe_push(Some(branch))` or `safe_push(None)`).
- Fixed a bug in `branch::rename` where the wrong overload was called.
- Cleaned up redundant imports and removed duplicated push calls.

How:
- Implemented `ensure_ssh_ready` check at the start of `safe_push`.
- Determined the actual branch to push (provided or current) before invoking the spinner.
- Wrapped the underlying `git_repo.push` call with `spinner!` to show progress.
- Updated each command file to pass `Option<String>` and removed their own spinner handling.
- Adjusted documentation comments to reflect new behavior.

BREAKING CHANGE: `safe_push` signature changed from `fn safe_push(&str, bool)` to `fn safe_push(Option<String>, bool)`. Update any external usages accordingly.
Closes #0
Add explicit SSH readiness checks before any git pull operation.

Why: Users often encounter pull failures when the SSH key is not configured or the SSH agent is not running. By guaranteeing that SSH is ready, the commands become more robust in CI/CD and interactive environments.

What:
- Imported `ensure_ssh_ready` and added calls in `branch::create`, `pr::create::branch`, and `pr::merge` commands.
- Wrapped pull calls with a spinner and used `PullOptions::no_stash` to avoid unintended stash side‑effects.
- Cleaned up duplicate imports across the modified files.
- Updated `util::sync::pull` to keep the spinner logic and preserve error handling.

How: The new helper `ensure_ssh_ready()` validates SSH configuration (or prompts the user) and returns an error on failure. Each command now:
1. Calls `ensure_ssh_ready()` before pulling.
2. Shows a spinner while pulling the latest changes.
3. Executes `safe_pull(..., PullOptions::no_stash())` to fetch without stashing.
This ensures consistent behavior across branch creation, PR creation, and PR merging workflows.
@zevwings zevwings merged commit e5fc2e7 into master Feb 27, 2026
13 checks passed
@zevwings zevwings deleted the bugfix/fix-ensure-ssh-loading-error branch February 27, 2026 03:09
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