Skip to content

loopguard: read the git subcommand after git's own options - #212

Open
KVR Vishnu (VISHNU0906) wants to merge 1 commit into
microsoft:mainfrom
VISHNU0906:fix/git-global-options
Open

KVR Vishnu (VISHNU0906) wants to merge 1 commit into
microsoft:mainfrom
VISHNU0906:fix/git-global-options

Conversation

@VISHNU0906

Copy link
Copy Markdown
Contributor

Hi Aaron Li (@aaron-jx-li), one more from the shell-edit parser in loopguard/shell_edits.py.

Agents often run git with -C <dir> instead of a cd. The parser took the word right after git as the subcommand, so with any of git's own options in front it found nothing:

  • git -C /w/repo apply /tmp/fix.diff was not counted as an edit
  • git -C repo checkout HEAD -- pkg/mod.py and git --git-dir=.git --work-tree . restore pkg/mod.py were not counted as a write, and not as a revert either
  • same for -c core.autocrlf=false, --no-pager and friends

So TurnGuard.fold saw no edit for those turns, and putting back a file the turn had edited did not count toward its churn.

A small _git_args helper now skips git's own options (and the value of the ones that take the next word: -C, -c, --git-dir, --work-tree, --namespace, --config-env, --attr-source) before reading the subcommand. _restored and the git apply check both use it. Plain git apply / git checkout -- behave as before, and reads like git -C repo diff or git -C repo log -- f.py still count as nothing.

Tests: new cases in test_edits_made_through_the_shell_are_recognised plus one through TurnGuard.fold that checks the patch and the revert are both counted. With the fix reverted, 5 of them fail. python -m pytest tests passes on Python 3.10 and 3.13 (902 passed, 16 skipped), experiments/tests passes, and scripts/dead_code.py output is the same as on main.

git -C <dir> apply x.diff and git -C <dir> checkout -- f.py put the
subcommand after git's own options (-C, -c, --no-pager, --git-dir ...).
The shell-edit parser took the word right after git for the
subcommand, so the patch was not counted as an edit and putting back a
file the turn had edited was not counted either.

Signed-off-by: KVR Vishnu <46535652+VISHNU0906@users.noreply.github.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.

1 participant