Files
Kigi-CLI/crates/codegen/kigi-agent/src/prompt/ignore.rs
T
ZacharyZhang-NYandClaude Fable 5 574122884a fix(windows): resolve the home directory via the standard lookup
Port of upstream grok-build 1.0.4/1.0.5. Two paths read $HOME only,
which is usually unset on Windows outside Git Bash:

- the global-gitignore fallback (prompt/ignore.rs) now uses
  std::env::home_dir(), the crate-wide idiom;
- fast-worktree's resolve_kigi_home falls back to std::env::home_dir()
  with the same dunce canonicalization, eliminating the documented
  divergence from kigi_config::default_kigi_home. On Unix home_dir()
  reads $HOME first, so behavior is unchanged where HOME is set.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01KSy9S31pZNWXtRZNVJ1sDf
2026-08-27 11:34:45 -04:00

37 lines
1.0 KiB
Rust

//! Gitignore integration for AGENTS.md and skills discovery.
use ignore::gitignore::{Gitignore, GitignoreBuilder};
use std::path::{Path, PathBuf};
pub fn build_gitignore(repo_root: Option<&Path>) -> Option<Gitignore> {
let root = repo_root?;
let mut builder = GitignoreBuilder::new(root);
let repo_gitignore = root.join(".gitignore");
if repo_gitignore.exists() {
let _ = builder.add(&repo_gitignore);
}
if let Some(global_path) = get_global_gitignore_path()
&& global_path.exists()
{
let _ = builder.add(&global_path);
}
builder.build().ok()
}
pub fn is_ignored(path: &Path, gitignore: Option<&Gitignore>, repo_root: Option<&Path>) -> bool {
let Some(gi) = gitignore else {
return false;
};
kigi_tools::gitignore::is_ignored(gi, path, repo_root)
}
fn get_global_gitignore_path() -> Option<PathBuf> {
git2::Config::open_default()
.ok()
.and_then(|cfg| cfg.get_path("core.excludesFile").ok())
.or_else(|| std::env::home_dir().map(|h| h.join(".gitignore")))
}