fixup git
This commit is contained in:
parent
4fb4ed4ea3
commit
b6787224c3
1 changed files with 28 additions and 20 deletions
48
src/git.rs
48
src/git.rs
|
|
@ -37,21 +37,14 @@ pub fn remove_worktree(worktree_dir: &std::path::Path) -> Result<(), GitError> {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn create_orphan_branch(branch: &str) -> Result<(), GitError> {
|
pub fn create_orphan_branch(branch: &str) -> Result<(), GitError> {
|
||||||
let tmp_worktree = mktemp::Temp::new_path();
|
{
|
||||||
let tmp_worktree_pathbuf = tmp_worktree.to_path_buf();
|
let tmp_worktree = mktemp::Temp::new_path();
|
||||||
let Some(tmp_worktree_dir) = tmp_worktree_pathbuf.as_path().to_str() else {
|
create_orphan_branch_at_path(branch, &tmp_worktree.to_path_buf())?;
|
||||||
return Err(GitError::Oops);
|
}
|
||||||
};
|
// The temp dir is now removed / cleaned up.
|
||||||
|
|
||||||
let result = std::process::Command::new("git")
|
let result = std::process::Command::new("git")
|
||||||
.args([
|
.args(["worktree", "prune"])
|
||||||
"worktree",
|
|
||||||
"add",
|
|
||||||
"--orphan",
|
|
||||||
"-b",
|
|
||||||
branch,
|
|
||||||
tmp_worktree_dir,
|
|
||||||
])
|
|
||||||
.output()?;
|
.output()?;
|
||||||
if !result.status.success() {
|
if !result.status.success() {
|
||||||
println!("stdout: {}", std::str::from_utf8(&result.stdout).unwrap());
|
println!("stdout: {}", std::str::from_utf8(&result.stdout).unwrap());
|
||||||
|
|
@ -59,10 +52,27 @@ pub fn create_orphan_branch(branch: &str) -> Result<(), GitError> {
|
||||||
return Err(GitError::Oops);
|
return Err(GitError::Oops);
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut readme_filename = tmp_worktree_pathbuf.clone();
|
Ok(())
|
||||||
|
}
|
||||||
|
pub fn create_orphan_branch_at_path(
|
||||||
|
branch: &str,
|
||||||
|
worktree_path: &std::path::PathBuf,
|
||||||
|
) -> Result<(), GitError> {
|
||||||
|
let Some(worktree_dir) = worktree_path.to_str() else {
|
||||||
|
return Err(GitError::Oops);
|
||||||
|
};
|
||||||
|
|
||||||
|
let result = std::process::Command::new("git")
|
||||||
|
.args(["worktree", "add", "--orphan", "-b", branch, worktree_dir])
|
||||||
|
.output()?;
|
||||||
|
if !result.status.success() {
|
||||||
|
println!("stdout: {}", std::str::from_utf8(&result.stdout).unwrap());
|
||||||
|
println!("stderr: {}", std::str::from_utf8(&result.stderr).unwrap());
|
||||||
|
return Err(GitError::Oops);
|
||||||
|
}
|
||||||
|
|
||||||
|
let mut readme_filename = worktree_path.clone();
|
||||||
readme_filename.push("README.md");
|
readme_filename.push("README.md");
|
||||||
println!("readme_filename: {:?}", readme_filename);
|
|
||||||
println!("tmp_worktree_pathbuf: {:?}", tmp_worktree_pathbuf);
|
|
||||||
let mut readme = std::fs::File::create(readme_filename)?;
|
let mut readme = std::fs::File::create(readme_filename)?;
|
||||||
write!(
|
write!(
|
||||||
readme,
|
readme,
|
||||||
|
|
@ -71,7 +81,7 @@ pub fn create_orphan_branch(branch: &str) -> Result<(), GitError> {
|
||||||
|
|
||||||
let result = std::process::Command::new("git")
|
let result = std::process::Command::new("git")
|
||||||
.args(["add", "README.md"])
|
.args(["add", "README.md"])
|
||||||
.current_dir(tmp_worktree_dir)
|
.current_dir(worktree_dir)
|
||||||
.output()?;
|
.output()?;
|
||||||
if !result.status.success() {
|
if !result.status.success() {
|
||||||
println!("stdout: {}", std::str::from_utf8(&result.stdout).unwrap());
|
println!("stdout: {}", std::str::from_utf8(&result.stdout).unwrap());
|
||||||
|
|
@ -81,7 +91,7 @@ pub fn create_orphan_branch(branch: &str) -> Result<(), GitError> {
|
||||||
|
|
||||||
let result = std::process::Command::new("git")
|
let result = std::process::Command::new("git")
|
||||||
.args(["commit", "-m", "create entomologist issue branch"])
|
.args(["commit", "-m", "create entomologist issue branch"])
|
||||||
.current_dir(tmp_worktree_dir)
|
.current_dir(worktree_path)
|
||||||
.output()?;
|
.output()?;
|
||||||
if !result.status.success() {
|
if !result.status.success() {
|
||||||
println!("stdout: {}", std::str::from_utf8(&result.stdout).unwrap());
|
println!("stdout: {}", std::str::from_utf8(&result.stdout).unwrap());
|
||||||
|
|
@ -89,8 +99,6 @@ pub fn create_orphan_branch(branch: &str) -> Result<(), GitError> {
|
||||||
return Err(GitError::Oops);
|
return Err(GitError::Oops);
|
||||||
}
|
}
|
||||||
|
|
||||||
// git worktree prune
|
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue