Skip to content

Commit

Permalink
fix: windows path for the git client (kcl-lang#1377)
Browse files Browse the repository at this point in the history
Signed-off-by: peefy <[email protected]>
  • Loading branch information
Peefy authored May 28, 2024
1 parent 67e8c28 commit e824bd6
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 8 deletions.
31 changes: 24 additions & 7 deletions kclvm/driver/src/client/git.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use std::process::Command;

use crate::client::fs::directory_is_not_empty;
use anyhow::Result;
use kclvm_utils::path::PathPrefix;

pub(crate) fn cmd_clone_git_repo_to(
url: &str,
Expand All @@ -15,34 +16,50 @@ pub(crate) fn cmd_clone_git_repo_to(
if directory_is_not_empty(path) {
return Ok(path.to_path_buf());
}
let path = path.adjust_canonicalization();
let mut git_clone_cmd = Command::new("git");
git_clone_cmd.args(["clone", url]);
if let Some(branch_name) = branch {
git_clone_cmd.args(["--branch", branch_name]);
}
git_clone_cmd.arg(path);
git_clone_cmd.arg(&path);

let output = git_clone_cmd.output()?;
if !output.status.success() {
bail!("Failed to clone Git repository {}", url);
bail!(
"Failed to clone Git repository {}: stdout: {} stderr: {}",
url,
String::from_utf8(output.stdout).unwrap(),
String::from_utf8(output.stderr).unwrap()
);
}
if let Some(tag_name) = tag {
let output = Command::new("git")
.args(["checkout", tag_name])
.current_dir(path)
.current_dir(&path)
.output()?;
if !output.status.success() {
bail!("Failed to checkout Git tag");
bail!(
"Failed to checkout Git tag {}: stdout: {} stderr: {}",
tag_name,
String::from_utf8(output.stdout).unwrap(),
String::from_utf8(output.stderr).unwrap()
);
}
} else if let Some(commit_hash) = commit {
let output = Command::new("git")
.args(["checkout", commit_hash])
.current_dir(path)
.current_dir(&path)
.output()?;
if !output.status.success() {
bail!("Failed to checkout Git commit");
bail!(
"Failed to checkout Git commit {}: stdout: {} stderr: {}",
commit_hash,
String::from_utf8(output.stdout).unwrap(),
String::from_utf8(output.stderr).unwrap()
)
}
}

Ok(path.to_path_buf())
Ok(path.into())
}
2 changes: 1 addition & 1 deletion kclvm/utils/src/path.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ where
}
}

/// Conver windows drive letter to upcase
/// Convert windows drive letter to upcase
pub fn convert_windows_drive_letter(path: &str) -> String {
#[cfg(target_os = "windows")]
{
Expand Down

0 comments on commit e824bd6

Please sign in to comment.