cascade_cli/cli/commands/
diagnose.rs

1use crate::errors::Result;
2use crate::git::GitRepository;
3use std::path::Path;
4
5/// Run diagnostic checks for git2 TLS/SSH support
6pub async fn run() -> Result<()> {
7    println!("šŸ”§ Cascade CLI - Git2 Diagnostics\n");
8
9    // Check git2 features
10    let version = git2::Version::get();
11    println!("šŸ” Git2 Feature Support:");
12    println!(
13        "  HTTPS/TLS support: {}",
14        if version.https() { "āœ… YES" } else { "āŒ NO" }
15    );
16    println!(
17        "  SSH support: {}",
18        if version.ssh() { "āœ… YES" } else { "āŒ NO" }
19    );
20
21    // Get libgit2 version
22    let libgit2_version = version.libgit2_version();
23    println!(
24        "  libgit2 version: {}.{}.{}",
25        libgit2_version.0, libgit2_version.1, libgit2_version.2
26    );
27
28    println!();
29
30    // Check current repository if we're in one
31    if let Ok(repo) = GitRepository::open(Path::new(".")) {
32        println!("šŸ“ Current Repository Analysis:");
33
34        // Use the built-in diagnostic method
35        repo.diagnose_git2_support()?;
36
37        // Check remote URLs
38        if let Ok(remote_url) = repo.get_remote_url("origin") {
39            println!("\n🌐 Remote Configuration:");
40            println!("  Origin URL: {remote_url}");
41
42            if remote_url.starts_with("https://") {
43                if version.https() {
44                    println!("  āœ… HTTPS remote with TLS support - should work!");
45                } else {
46                    println!("  āŒ HTTPS remote but NO TLS support - will fallback to git CLI");
47                }
48            } else if remote_url.starts_with("git@") || remote_url.starts_with("ssh://") {
49                if version.ssh() {
50                    println!("  āœ… SSH remote with SSH support - should work!");
51                } else {
52                    println!("  āŒ SSH remote but NO SSH support - will fallback to git CLI");
53                }
54            }
55        }
56    } else {
57        println!("šŸ“ Not in a git repository - skipping repository-specific checks");
58    }
59
60    // Provide recommendations
61    println!("\nšŸ’” Recommendations:");
62
63    if !version.https() || !version.ssh() {
64        println!("  šŸ”§ MISSING FEATURES DETECTED:");
65        println!("     Your git2 is missing TLS/SSH support.");
66        println!("     This causes performance issues due to git CLI fallbacks.");
67        println!();
68        println!("  šŸ“ TO FIX: Update Cargo.toml git2 dependency:");
69        println!("     git2 = {{ version = \"0.20.2\", features = [\"vendored-libgit2\", \"https\", \"ssh\"] }}");
70        println!();
71        println!("  šŸš€ BENEFITS: Direct git2 operations (faster, more reliable)");
72    } else {
73        println!("  āœ… git2 has full TLS/SSH support!");
74        println!("     If you're still experiencing issues, they may be:");
75        println!("     - Network connectivity problems");
76        println!("     - Authentication/credential issues");
77        println!("     - Corporate firewall/proxy settings");
78        println!("     - SSL certificate verification problems");
79    }
80
81    Ok(())
82}