Skip to content

feat(rev-parse): add revision parsing command#345

Closed
marshawcoco wants to merge 18 commits intoweb3infra-foundation:mainfrom
marshawcoco:feat/rev-parse-upstream
Closed

feat(rev-parse): add revision parsing command#345
marshawcoco wants to merge 18 commits intoweb3infra-foundation:mainfrom
marshawcoco:feat/rev-parse-upstream

Conversation

@marshawcoco
Copy link
Copy Markdown
Contributor

@marshawcoco marshawcoco commented Apr 7, 2026

Summary

  • add a rev-parse command for parsing and normalizing revision names and repository paths
  • wire the command into CLI dispatch and command registration
  • add command tests covering the new revision parsing flow

Test plan

  • Reviewed commit cd70d00
  • cargo +nightly fmt --all --check
  • cargo clippy --all-targets --all-features -- -D warnings
  • cargo test --all -- --test-threads=1

🤖 Generated with Claude Code

marshawcoco and others added 10 commits March 31, 2026 17:22
Add bisect module that uses binary search to find the commit that
introduced a bug between a known "good" and "bad" state.

Features:
- bisect start [--bad <rev>] [--good <rev>] - initialize session
- bisect bad [<rev>] - mark commit as containing the bug
- bisect good [<rev>] - mark commit as working correctly
- bisect reset [<rev>] - end session and restore original HEAD
- bisect skip [<rev>] - skip untestable commits
- bisect log - show current bisect state

Also fixes SQLite connection string parsing on Windows by normalizing
paths with \?\ prefix.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
…arnings

- Use restore::restore_to_file in bisect checkout to properly handle LFS pointers
- Make restore_to_file public in restore.rs for reuse
- Fix clippy manual_strip lint by using strip_prefix instead of slicing
- Add #[cfg(unix)] to platform-specific imports to resolve unused warnings
- Fix unused variable in bisect_test.rs

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Add rev-parse with CLI and integration coverage, and include Windows-focused test/runtime fixes needed to keep the command workflow stable.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Stabilize Windows CI-related tests by normalizing orchestrator paths, avoiding the unimplemented Windows sandbox, and relaxing symlink-sensitive fixtures. Also fix local MCP DB path setup and test helpers that depend on HOME/USERPROFILE overrides.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: cd70d00e88

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Adds a new rev-parse CLI command to resolve revision specs and print repository paths, integrating it into the command registry and adding integration tests to validate expected behaviors.

Changes:

  • Introduce rev-parse command implementation + CLI wiring (--short, --abbrev-ref, --show-toplevel, JSON/machine output).
  • Add integration tests for the new command and adjust existing commit-producing tests to use --no-verify.
  • Improve some platform/path handling (Windows main thread spawn, path display normalization, HOME detection, tempdir-based tests).

Reviewed changes

Copilot reviewed 12 out of 12 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
src/command/rev_parse.rs New rev-parse command implementation and argument parsing.
src/cli.rs Register rev-parse in CLI enum and dispatch.
src/command/mod.rs Export the new rev_parse command module.
tests/command/rev_parse_test.rs New integration tests covering resolve/short/abbrev-ref/show-toplevel/json/machine flows.
tests/command/mod.rs Include the new rev_parse_test module.
src/main.rs Windows-specific main-thread spawn changes before running CLI logic.
src/internal/tui/diff.rs Adjust path display logic with additional normalization for relative rendering.
src/command/fetch.rs Prefer HOME/USERPROFILE env vars when deriving home directory for vault temp dir.
src/internal/ai/tools/utils.rs Make path-validation tests use tempdir() instead of hard-coded /tmp paths.
src/command/tag.rs Update tests to commit with --no-verify.
tests/command/revert_test.rs Update revert tests to commit with no_verify: true.
tests/command/show_ref_test.rs Update commit setup to use no_verify: true.

Complete rev-parse integration with stable error handling and non-ambiguous short hash resolution, and make Windows task worktrees fall back to copying .libra storage when symlink privileges are unavailable.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: ec014ad6c6

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Fix the remaining workspace storage helper references, make rev-parse --abbrev-ref HEAD return structured errors on HEAD lookup failures, restore the Windows restricted sandbox default, and update the README command support table.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 13527e2f38

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Use fallible branch lookups in rev-parse abbrev-ref resolution so branch storage failures surface as structured fatal errors, and gate the Windows storage copy helper to Windows and test builds to keep clippy clean.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 1bc0f348dc

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

}

async fn resolve_abbrev_ref(spec: &str) -> CliResult<String> {
if spec.eq_ignore_ascii_case("HEAD") {
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Match HEAD token using exact case

resolve_abbrev_ref currently uses a case-insensitive check for HEAD, so inputs like libra rev-parse --abbrev-ref head are forced into the HEAD code path and can return the current branch even when a real branch named head exists. Git ref names are case-sensitive and head is a valid branch name, so this can return incorrect results and break scripts that rely on exact symbolic-ref resolution. Compare against "HEAD" exactly and let other casings flow through normal branch lookup.

Useful? React with 👍 / 👎.


fn ensure_vault_ssh_tmp_dir() -> Result<PathBuf, String> {
let home = dirs::home_dir().ok_or_else(|| "cannot determine home directory".to_string())?;
let home = resolve_home_directory()?;
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Use consistent home path for SSH key GC

This change writes vault SSH temp files under resolve_home_directory() but the cleanup pass still scans dirs::home_dir(), so the two paths can diverge when HOME/USERPROFILE overrides are in effect (common in CI/sandboxed runs). In that case expired decrypted key files in the actual write location are never collected after abnormal exits, leaving sensitive material on disk longer than intended. Reuse the same home-resolution logic in cleanup_expired_vault_ssh_temp_files to keep write and GC directories aligned.

Useful? React with 👍 / 👎.

Use an explicit repo database path for cloud env resolution so local config still loads after tests or callers change the process cwd.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 27d63926d5

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment on lines +70 to +71
if args.show_toplevel {
let workdir = util::try_working_dir().map_err(map_repo_path_error)?;
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Reject ignored operands when --show-toplevel is set

resolve_rev_parse returns immediately for --show-toplevel, so any provided SPEC (and --short) is silently ignored while still exiting successfully. For example, libra rev-parse --show-toplevel --short HEAD prints only the worktree path, which can mislead scripts that expect revision resolution and fail-open on incorrect output. Please make these combinations explicit clap conflicts (or implement multi-output semantics) so incompatible arguments do not get dropped silently.

Useful? React with 👍 / 👎.

Add the missing cfg-gated test imports and align the cloud/config changes with rustfmt so the command_test target builds cleanly in CI.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 54e729a0ec

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment on lines +115 to +116
if let Some(branch) = Branch::find_branch_result(spec, None)
.await
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Normalize full local ref names before branch lookup

--abbrev-ref currently queries Branch::find_branch_result with the raw spec, so an input like refs/heads/main is looked up literally and falls through to not a symbolic ref. Git accepts full local refnames here and resolves them to the short branch name (main), so scripts that pass canonical refs will regress. Strip/normalize the refs/heads/ prefix (and then resolve) before doing the branch lookup.

Useful? React with 👍 / 👎.

Comment on lines +122 to +123
if let Some((remote, branch_name)) = spec.split_once('/')
&& !remote.is_empty()
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Parse remote names with slashes in --abbrev-ref

The remote-tracking path parser assumes the remote name has no / by using split_once('/'). For remotes like team/upstream, team/upstream/main is misparsed as remote=team and branch=upstream/main, so lookup fails even when team/upstream/main exists. This makes --abbrev-ref incorrect for valid remote names; use a parser that can disambiguate remote/branch boundaries (e.g., try split points or reuse branch search logic that already handles nested remote names).

Useful? React with 👍 / 👎.

marshawcoco and others added 2 commits April 8, 2026 23:46
Update the D1 global config error assertion to match the current config resolution wrapper while remaining compatible with adjacent connection-style messages.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Build tag command test repositories through the direct add/commit helpers instead of parse_async so the force-tag cases start from a reliably committed repo.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 4f33b38bf2

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment on lines +788 to +792
if entry.encrypted {
let plaintext = decrypt_value(&entry.value, "local")
.await
.context(format!("failed to decrypt {vault_key}"))?;
return Ok(Some(plaintext));
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Use explicit-db scope when decrypting local env secrets

resolve_env_for_target now supports LocalIdentityTarget::ExplicitDb, but the encrypted branch still calls decrypt_value(..., "local"), which loads the local unseal key from the current repository context rather than from the explicit DB target. In the cwd-drift scenario this change is meant to support (e.g., cloud env read from another repo DB), encrypted vault.env.* values will be read from the correct DB but fail to decrypt, causing cloud credential resolution to fail despite valid stored secrets. Please thread the explicit target (or repo id) into unseal-key lookup so DB selection and decryption use the same repository scope.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

代码中不能包含日志文件

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

我已删除并提交。

Drop the accidentally committed .claude-ci-test.log file so the rev-parse PR only contains source and test changes.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
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.

3 participants