cascade_cli/cli/commands/
diagnose.rs

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