Skip to content

Commit 2d09a61

Browse files
runningcodeclaude
andcommitted
feat(vcs): Address PR review comments for base_ref detection
- Fix UTF-8 error handling with proper anyhow::Error conversion - Add explicit type annotations for closure error handling - Use anyhow::Error consistently instead of git2::Error for better error messages - Implement cleaner error propagation as suggested in review 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
1 parent 8d8df84 commit 2d09a61

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

src/utils/vcs.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -257,21 +257,23 @@ pub fn git_repo_base_ref(repo: &git2::Repository, remote_name: &str) -> Result<O
257257
let remote_branch_name = format!("refs/remotes/{remote_name}/HEAD");
258258
let remote_ref = repo
259259
.find_reference(&remote_branch_name)
260-
.or_else(|_| {
260+
.or_else(|_| -> Result<git2::Reference, anyhow::Error> {
261261
// If remote/HEAD doesn't exist, try to query the remote for its actual default branch
262262
let mut remote = repo.find_remote(remote_name)?;
263263
remote.connect(git2::Direction::Fetch)?;
264264
let default_branch_buf = remote.default_branch()?;
265-
let default_branch = default_branch_buf.as_str().unwrap();
265+
let default_branch = default_branch_buf
266+
.as_str()
267+
.ok_or_else(|| anyhow::anyhow!("Default branch contains invalid UTF-8"))?;
266268

267269
// Convert "refs/heads/main" to "refs/remotes/origin/main"
268270
let branch_name = default_branch
269271
.strip_prefix("refs/heads/")
270272
.unwrap_or(default_branch);
271273
let remote_branch = format!("refs/remotes/{remote_name}/{branch_name}");
272-
repo.find_reference(&remote_branch)
274+
Ok(repo.find_reference(&remote_branch)?)
273275
})
274-
.map_err(|e| {
276+
.map_err(|e: anyhow::Error| {
275277
anyhow::anyhow!(
276278
"Could not find remote tracking branch for {}: {}",
277279
remote_name,

0 commit comments

Comments
 (0)