feat(config): 为 anthropic、kimi、deepseek 添加 list_models 支持
This commit is contained in:
@@ -22,15 +22,41 @@ impl GitRepo {
|
||||
/// Open a git repository
|
||||
pub fn open<P: AsRef<Path>>(path: P) -> Result<Self> {
|
||||
let path = path.as_ref();
|
||||
let absolute_path = path.canonicalize().unwrap_or_else(|_| path.to_path_buf());
|
||||
|
||||
// Enhanced cross-platform path handling
|
||||
let absolute_path = if let Ok(canonical) = path.canonicalize() {
|
||||
canonical
|
||||
} else {
|
||||
// Fallback: convert to absolute path without canonicalization
|
||||
if path.is_absolute() {
|
||||
path.to_path_buf()
|
||||
} else {
|
||||
std::env::current_dir()?.join(path)
|
||||
}
|
||||
};
|
||||
|
||||
// Try multiple git repository discovery strategies for cross-platform compatibility
|
||||
let repo = Repository::discover(&absolute_path)
|
||||
.or_else(|_| Repository::open(&absolute_path))
|
||||
.or_else(|discover_err| {
|
||||
// Try direct open as fallback
|
||||
Repository::open(&absolute_path).map_err(|open_err| {
|
||||
// Provide detailed error information for debugging
|
||||
anyhow::anyhow!(
|
||||
"Git repository discovery failed:\n\
|
||||
Discovery error: {}\n\
|
||||
Direct open error: {}\n\
|
||||
Path attempted: {:?}\n\
|
||||
Current directory: {:?}",
|
||||
discover_err, open_err, absolute_path, std::env::current_dir()
|
||||
)
|
||||
})
|
||||
})
|
||||
.with_context(|| {
|
||||
format!(
|
||||
"Failed to open git repository at '{:?}'. Please ensure:\n\
|
||||
1. The directory is set as safe (run: git config --global --add safe.directory \"{}\")\n\
|
||||
2. The path is correct and contains a valid '.git' folder.",
|
||||
1. The directory contains a valid '.git' folder\n\
|
||||
2. The directory is set as safe (run: git config --global --add safe.directory \"{}\")\n\
|
||||
3. You have proper permissions to access the repository",
|
||||
absolute_path,
|
||||
absolute_path.display()
|
||||
)
|
||||
@@ -689,19 +715,37 @@ impl StatusSummary {
|
||||
pub fn find_repo<P: AsRef<Path>>(start_path: P) -> Result<GitRepo> {
|
||||
let start_path = start_path.as_ref();
|
||||
|
||||
// Try the starting path first
|
||||
if let Ok(repo) = GitRepo::open(start_path) {
|
||||
return Ok(repo);
|
||||
}
|
||||
|
||||
// Walk up the directory tree to find a git repository
|
||||
let mut current = start_path;
|
||||
let mut attempted_paths = vec![current.to_string_lossy().to_string()];
|
||||
|
||||
while let Some(parent) = current.parent() {
|
||||
attempted_paths.push(parent.to_string_lossy().to_string());
|
||||
|
||||
if let Ok(repo) = GitRepo::open(parent) {
|
||||
return Ok(repo);
|
||||
}
|
||||
current = parent;
|
||||
}
|
||||
|
||||
bail!("No git repository found starting from {:?}", start_path)
|
||||
// Provide detailed error information for debugging
|
||||
bail!(
|
||||
"No git repository found starting from {:?}.\n\
|
||||
Paths attempted:\n {}\n\
|
||||
Current directory: {:?}\n\
|
||||
Please ensure:\n\
|
||||
1. You are in a git repository or its subdirectory\n\
|
||||
2. The repository has a valid .git folder\n\
|
||||
3. You have proper permissions to access the repository",
|
||||
start_path,
|
||||
attempted_paths.join("\n "),
|
||||
std::env::current_dir()
|
||||
)
|
||||
}
|
||||
|
||||
/// Check if path is inside a git repository
|
||||
|
||||
Reference in New Issue
Block a user