Skip to content

Commit

Permalink
feat: sozo init remove git (#2139)
Browse files Browse the repository at this point in the history
* feat: sozo init remove git

* refac: remove `.github` folder
  • Loading branch information
EjembiEmmanuel authored Jul 5, 2024
1 parent e8539d5 commit b2a4df6
Showing 1 changed file with 14 additions and 6 deletions.
20 changes: 14 additions & 6 deletions bin/sozo/src/commands/init.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ pub struct InitArgs {

#[arg(help = "Parse a full git url or a url path", default_value = "dojoengine/dojo-starter")]
template: String,

#[arg(long, help = "Initialize a new Git repository")]
git: bool,
}

impl InitArgs {
Expand Down Expand Up @@ -58,7 +61,7 @@ impl InitArgs {
set_current_dir(&target_dir)?;

// Modify the git history.
modify_git_history(&repo_url)?;
modify_git_history(&repo_url, self.git)?;

config.ui().print("\n🎉 Successfully created a new ⛩️ Dojo project!");

Expand All @@ -83,19 +86,24 @@ fn clone_repo(url: &str, path: &Path, config: &Config) -> Result<()> {
Ok(())
}

fn modify_git_history(url: &str) -> Result<()> {
fn modify_git_history(url: &str, init_git: bool) -> Result<()> {
trace!("Modifying Git history.");
let git_output = Command::new("git").args(["rev-parse", "--short", "HEAD"]).output()?.stdout;
let commit_hash = String::from_utf8(git_output)?;
trace!(commit_hash = commit_hash.trim());

fs::remove_dir_all(".git")?;
if Path::new(".github").exists() {
fs::remove_dir_all(".github")?;
}

Command::new("git").arg("init").output()?;
Command::new("git").args(["add", "--all"]).output()?;
if init_git {
Command::new("git").arg("init").output()?;
Command::new("git").args(["add", "--all"]).output()?;

let commit_msg = format!("chore: init from {} at {}", url, commit_hash.trim());
Command::new("git").args(["commit", "-m", &commit_msg]).output()?;
let commit_msg = format!("chore: init from {} at {}", url, commit_hash.trim());
Command::new("git").args(["commit", "-m", &commit_msg]).output()?;
}

trace!("Git history modified.");
Ok(())
Expand Down

0 comments on commit b2a4df6

Please sign in to comment.