Skip to content

The fastest, cheapest, most efficient open-source agent harness. Run more than 500 agents on a $10 VPS.

fix(git_operations): validate repository with libgit2 instead of checking .git path

Steven Enamakele2ada0b66677
diff --git a/src/openhuman/tools/impl/filesystem/git_operations.rs b/src/openhuman/tools/impl/filesystem/git_operations.rs
index 920d824418..71c793085a 100644
--- a/src/openhuman/tools/impl/filesystem/git_operations.rs
+++ b/src/openhuman/tools/impl/filesystem/git_operations.rs
@@ -533,24 +533,12 @@ impl GitOperationsTool {
}
};
- // Check if we're in a git repository. A linked worktree's `.git` is a
- // file (a gitdir pointer), not a directory — `exists()` covers both.
let effective_dir = self.effective_action_dir_for_context(context);
- if !effective_dir.join(".git").exists() {
- // Try to find .git in parent directories
- let mut current_dir = effective_dir.as_path();
- let mut found_git = false;
- while current_dir.parent().is_some() {
- if current_dir.join(".git").exists() {
- found_git = true;
- break;
- }
- current_dir = current_dir.parent().unwrap();
- }
-
- if !found_git {
- return Ok(ToolResult::error("Not in a git repository"));
- }
+ // Validate the repository instead of trusting the presence of a `.git`
+ // path. This handles linked-worktree gitfiles and rejects malformed
+ // ancestor markers that Git itself cannot open.
+ if git2::Repository::discover(&effective_dir).is_err() {
+ return Ok(ToolResult::error("Not in a git repository"));
}
// Check autonomy level for write operations