Skip to content

Commit

Permalink
feat: fix git sync
Browse files Browse the repository at this point in the history
  • Loading branch information
jincheng.zhang committed Apr 30, 2024
1 parent 87b06f5 commit 33daf77
Showing 1 changed file with 12 additions and 9 deletions.
21 changes: 12 additions & 9 deletions crates/netpurr/src/operation/git.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
use std::fs::File;
use std::io::Write;
use std::path::PathBuf;
use std::str::FromStr;
use futures_util::AsyncWriteExt;

use log::error;
use poll_promise::Promise;
Expand All @@ -21,6 +24,12 @@ impl Git {
if repo.is_err() {
error!("init git repo failed, path: {:?}", repo_path);
}
let gitignore_content = ".DS_Store\nrequests/";
let gitignore_path = repo_path.join("./.gitignore");
let mut file = File::create(gitignore_path);
if file.is_ok() {
file.unwrap().write_all(gitignore_content.as_bytes());
}
}
pub fn create_branch(
&self,
Expand Down Expand Up @@ -53,21 +62,15 @@ impl Git {
let repo = Repository::new(repo_path);
if let Ok(head) = repo.cmd_out(["branch", "--show-current"]) {
if let Some(branch_name) = head.get(0) {
repo.cmd(["fetch"]);
repo.cmd([
"branch",
format!("--set-upstream-to=origin/{}", &branch_name).as_str(),
])?;
repo.cmd(["add", "."])?;
repo.cmd(["stash", "clear"])?;
repo.cmd(["stash"])?;
repo.cmd(["rm", "-rf", "--ignore-unmatch","--cached", "requests/*"])?;
repo.commit_all("auto commit")?;
repo.cmd(["pull", "--rebase"])?;
repo.cmd(["stash", "pop"]);
if repo.commit_all("auto commit").is_ok() {
repo.cmd(["push", "--set-upstream", "origin", &branch_name])
} else {
Ok(())
}
repo.cmd(["push", "--set-upstream", "origin", &branch_name])
} else {
Ok(())
}
Expand Down

0 comments on commit 33daf77

Please sign in to comment.