Skip to content

fix(tool): correct git grep ref argument order in code_search#150

Open
zhuichen wants to merge 1 commit into
alibaba:mainfrom
zhuichen:fix/code-search-commit-ref-order
Open

fix(tool): correct git grep ref argument order in code_search#150
zhuichen wants to merge 1 commit into
alibaba:mainfrom
zhuichen:fix/code-search-commit-ref-order

Conversation

@zhuichen

Copy link
Copy Markdown
Contributor

Summary

Fix code_search failures in commit/range review modes by correcting git grep argument ordering and preserving option-like ref safety checks.

Problem

In commit/range mode, code_search constructed git grep args with an invalid revision placement, which caused errors like:

  • fatal: unable to resolve revision: --end-of-options

As a result, code_search became unreliable for --commit and --from/--to workflows.

Root Cause

buildGrepArgs assembled arguments in a way that made Git parse an invalid token as a revision.

Changes

  • Corrected git grep arg order in:
    • internal/tool/code_search.go
  • Added/kept defensive guard for option-like refs (-...) to avoid ambiguous/unsafe execution.
  • Updated tests to match the corrected command structure and behavior:
    • internal/tool/code_search_test.go

Validation

Executed per contribution guide:

  • go fmt ./...
  • go vet ./...
  • make test (race enabled)
  • make build

All passed.

Impact

  • Restores code_search correctness in commit/range mode.
  • Improves stability of AI review tool-calls for non-workspace reviews.
  • Keeps security behavior for option-like refs.

🤖 Generated with Claude Code

@CLAassistant

CLAassistant commented Jun 16, 2026

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@github-actions

Copy link
Copy Markdown

OpenCodeReview: No comments generated. Looks good to me.

Co-Authored-By: Claude <noreply@anthropic.com>
@zhuichen zhuichen force-pushed the fix/code-search-commit-ref-order branch from 1af6682 to d51ae74 Compare June 16, 2026 08:15
@MuoDoo MuoDoo self-requested a review June 16, 2026 11:38
@MuoDoo

MuoDoo commented Jun 16, 2026

Copy link
Copy Markdown
Collaborator

I couldn’t reproduce the --end-of-options revision error with the current args. Could you share the exact failing case?

@guqihao-7

Copy link
Copy Markdown
Contributor

I couldn’t reproduce the --end-of-options revision error with the current args. Could you share the exact failing case?我无法用当前参数复现 --end-of-options 修订版本错误。你能分享具体的失败案例吗?

I can reproduce
image

@guqihao-7

Copy link
Copy Markdown
Contributor

I couldn’t reproduce the --end-of-options revision error with the current args. Could you share the exact failing case?

my git version is: git version 2.39.5 (Apple Git-154)

I suspect this is related to the git version. I couldn't reproduce it on my Ubuntu, but my Mac.

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.

4 participants