[PR #514] Fix git-ai blame from subdirectory with relative file paths #529

Closed
opened 2026-03-02 04:13:53 +03:00 by kerem · 0 comments
Owner

Original Pull Request: https://github.com/git-ai-project/git-ai/pull/514

State: closed
Merged: Yes


Fix git-ai blame from subdirectory with relative file paths

Summary

Fixes #54. When running git-ai blame <file> from a subdirectory with a relative path, the file path was passed directly to repo.blame() without resolving it against the current working directory. This caused "File not found" errors because blame() assumed the path was relative to the repo root.

The fix resolves relative file paths to absolute paths (by joining with current_dir) before passing to blame(), which already has logic to canonicalize absolute paths and strip the repo root prefix.

Also adds git_ai_from_working_dir() to the TestRepo harness and 8 new tests covering subdirectory blame scenarios.

Review & Testing Checklist for Human

  • Verify the path resolution in handle_ai_blame handles edge cases: paths with .. components (e.g., git-ai blame ../sibling/file.rs), symlinked directories, and the current_dir() fallback to "."
  • Check whether the same bug exists in handle_ai_diff or other subcommands that accept file paths — handle_ai_diff has identical current_dir logic but may not need file path resolution
  • Manual test: clone a repo, cd into a subdirectory, run git-ai blame <relative-file> and confirm it works

Notes

  • The blame() function already handles absolute-to-relative conversion via canonicalize() + strip_prefix(), so the fix just needs to make the path absolute before that existing logic kicks in
  • All existing tests pass (full suite), lint and format checks pass
  • Link to Devin run
  • Requested by: @svarlamov

Open with Devin
**Original Pull Request:** https://github.com/git-ai-project/git-ai/pull/514 **State:** closed **Merged:** Yes --- # Fix git-ai blame from subdirectory with relative file paths ## Summary Fixes #54. When running `git-ai blame <file>` from a subdirectory with a relative path, the file path was passed directly to `repo.blame()` without resolving it against the current working directory. This caused "File not found" errors because `blame()` assumed the path was relative to the repo root. The fix resolves relative file paths to absolute paths (by joining with `current_dir`) before passing to `blame()`, which already has logic to canonicalize absolute paths and strip the repo root prefix. Also adds `git_ai_from_working_dir()` to the TestRepo harness and 8 new tests covering subdirectory blame scenarios. ## Review & Testing Checklist for Human - [ ] Verify the path resolution in `handle_ai_blame` handles edge cases: paths with `..` components (e.g., `git-ai blame ../sibling/file.rs`), symlinked directories, and the `current_dir()` fallback to `"."` - [ ] Check whether the same bug exists in `handle_ai_diff` or other subcommands that accept file paths — `handle_ai_diff` has identical `current_dir` logic but may not need file path resolution - [ ] Manual test: clone a repo, `cd` into a subdirectory, run `git-ai blame <relative-file>` and confirm it works ### Notes - The `blame()` function already handles absolute-to-relative conversion via `canonicalize()` + `strip_prefix()`, so the fix just needs to make the path absolute before that existing logic kicks in - All existing tests pass (full suite), lint and format checks pass - [Link to Devin run](https://app.devin.ai/sessions/22db57aeefb0441fb6bcd123d2fa3b1e) - Requested by: @svarlamov <!-- devin-review-badge-begin --> --- <a href="https://app.devin.ai/review/git-ai-project/git-ai/pull/514" target="_blank"> <picture> <source media="(prefers-color-scheme: dark)" srcset="https://static.devin.ai/assets/gh-open-in-devin-review-dark.svg?v=1"> <img src="https://static.devin.ai/assets/gh-open-in-devin-review-light.svg?v=1" alt="Open with Devin"> </picture> </a> <!-- devin-review-badge-end -->
kerem 2026-03-02 04:13:53 +03:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/git-ai#529
No description provided.