-
-
Save rust-play/0415e1b62e679d23a3faa20ba0480aee to your computer and use it in GitHub Desktop.
Code shared from the Rust Playground
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use std::process::Command; | |
fn main() { | |
if is_git_installed() { | |
println!("Git is installed. Initializing Git repository..."); | |
if let Err(e) = initialize_git_repo() { | |
eprintln!("Failed to initialize Git repository: {}", e); | |
} else { | |
println!("Git repository initialized successfully."); | |
} | |
} else { | |
println!("Git is not installed. Skipping Git initialization."); | |
} | |
} | |
fn is_git_installed() -> bool { | |
Command::new("git") | |
.arg("--version") | |
.output() | |
.map(|output| output.status.success()) | |
.unwrap_or(false) | |
} | |
fn initialize_git_repo() -> std::io::Result<()> { | |
let status = Command::new("git").arg("init").status()?; | |
if status.success() { | |
Ok(()) | |
} else { | |
Err(std::io::Error::new( | |
std::io::ErrorKind::Other, | |
format!("Git init failed with status: {}", status), | |
)) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment