// Git operations test script (primarily focused on validation) // Note: Many git operations are destructive or require network access, // so this test primarily validates availability and URL handling. print("===== Git Operations Test ====="); // Test git availability print("\n=== Test Git Availability ==="); let git_cmd = which("git"); if git_cmd { print(`Git is available at: ${git_cmd}`); } else { print("WARNING: Git is not installed. Some tests will be skipped."); } // Test git URL parsing (testing internal implementation through git operations) print("\n=== Test Git URL Parsing ==="); // HTTPS URLs let https_urls = [ "https://github.com/user/repo.git", "https://github.com/user/repo", "https://example.com/user/repo.git" ]; print("Testing HTTPS GitHub URLs:"); for url in https_urls { // For testing purposes, we'll use the URL rather than actually cloning // Just check if git_clone responds with "already exists" message which indicates // it recognized and parsed the URL correctly let result = git_clone(url); // Check if the result contains a path with expected structure let contains_path = result.contains("/code/") && (result.contains("github.com") || result.contains("example.com")); print(` URL: ${url}`); print(` Path structure valid: ${contains_path ? "yes" : "no"}`); // Extract the expected path components from the parsing if contains_path { let parts = result.split("/"); let domain_part = ""; let user_part = ""; let repo_part = ""; let found_code = false; for i in 0..parts.len() { if parts[i] == "code" && (i+3) < parts.len() { domain_part = parts[i+1]; user_part = parts[i+2]; repo_part = parts[i+3]; found_code = true; break; } } if found_code { print(` Parsed domain: ${domain_part}`); print(` Parsed user: ${user_part}`); print(` Parsed repo: ${repo_part}`); } } } // SSH URLs let ssh_urls = [ "git@github.com:user/repo.git", "git@example.com:organization/repository.git" ]; print("\nTesting SSH Git URLs:"); for url in ssh_urls { // Similar approach to HTTPS testing let result = git_clone(url); let contains_path = result.contains("/code/"); print(` URL: ${url}`); print(` Path structure valid: ${contains_path ? "yes" : "no"}`); } // Test git_list print("\n=== Test git_list() ==="); let repos = git_list(); print(`Found ${repos.len()} local git repositories`); if repos.len() > 0 { print("First 3 repositories (or fewer if less available):"); let max = Math.min(3, repos.len()); for i in 0..max { print(` ${i+1}. ${repos[i]}`); } } // Test git command access through run print("\n=== Test Git Command Access ==="); if git_cmd { let git_version = run("git --version"); print(`Git version info: ${git_version.stdout}`); // Test git status command (this is safe and doesn't modify anything) let git_status = run("git status"); print("Git status command:"); print(` Exit code: ${git_status.code}`); if git_status.success { print(" Git status executed successfully in current directory"); } else { print(" Git status failed. This might not be a git repository."); } } // Minimal testing of other git operations (these are mostly destructive) print("\n=== Git Operations Availability Check ==="); print("The following git operations are available:"); print(" - git_clone: Available (tested above)"); print(" - git_list: Available (tested above)"); print(" - git_update: Available (not tested to avoid modifying repos)"); print(" - git_update_force: Available (not tested to avoid modifying repos)"); print(" - git_update_commit: Available (not tested to avoid modifying repos)"); print(" - git_update_commit_push: Available (not tested to avoid modifying repos)"); print("\nGit Operations Test completed!"); "Git Test Success"