From 6a7f413a9c38626efb8089ca5ecd0d0c92809983 Mon Sep 17 00:00:00 2001 From: Pagwin Date: Sun, 25 Sep 2022 14:46:30 -0400 Subject: [PATCH] giving up and using the cli --- src/main.rs | 94 ++++++++++++++++++++--------------------------------- 1 file changed, 36 insertions(+), 58 deletions(-) diff --git a/src/main.rs b/src/main.rs index c7b5317..fbed6c7 100644 --- a/src/main.rs +++ b/src/main.rs @@ -6,7 +6,6 @@ extern crate git2; use std::{path::{PathBuf, Path}, io::{Read, Cursor}, collections::{HashMap, HashSet}, ffi::OsStr}; use clap::{Command, Arg}; -use git2::{build::CheckoutBuilder, IndexAddOption}; use serde::{Serialize, Deserialize}; @@ -105,26 +104,26 @@ fn main() -> Result<(),Errors> { - let branch = repo.branches(Some(git2::BranchType::Remote))?.find(|branch|{ - if let Ok(branch) = branch{ - if let Ok(Some(name)) = branch.0.name(){ - name == format!("origin/{}",skelly_branch) - }else{false} - }else{false} - }).ok_or(git2::Error::from_str(format!("no branch with name {}",skelly_branch).as_str()))??; + // let branch = repo.branches(Some(git2::BranchType::Remote))?.find(|branch|{ + // if let Ok(branch) = branch{ + // if let Ok(Some(name)) = branch.0.name(){ + // name == format!("origin/{}",skelly_branch) + // }else{false} + // }else{false} + // }).ok_or(git2::Error::from_str(format!("no branch with name {}",skelly_branch).as_str()))??; - match repo.set_head(branch.0.into_reference().name().ok_or(git2::Error::from_str("the branch with a name somehow has a reference without a name"))?){ - Err(e)=>{ - panic!("{}",e.message()); - } - _=>{} - } + // match repo.set_head(branch.0.into_reference().name().ok_or(git2::Error::from_str("the branch with a name somehow has a reference without a name"))?){ + // Err(e)=>{ + // panic!("{}",e.message()); + // } + // _=>{} + // } - #[cfg(debug_assertions)] - { - eprintln!("head set"); - std::io::stdin().read_line(&mut String::new())?; - } + //#[cfg(debug_assertions)] + //{ + // eprintln!("head set"); + // std::io::stdin().read_line(&mut String::new())?; + //} repo.remote_delete("origin")?; @@ -136,49 +135,28 @@ fn main() -> Result<(),Errors> { - let mut walk = repo.revwalk()?; - walk.set_sorting(git2::Sort::TIME)?; - walk.push_head()?; - let oldest_commit = repo.find_commit(walk.last().ok_or(Errors::GitErr(git2::Error::from_str("No Oldest commit")))??)?; - - #[cfg(debug_assertions)] - { - eprintln!("oldest commit found and head checked"); - std::io::stdin().read_line(&mut String::new())?; - } - - repo.reset(oldest_commit.as_object(), git2::ResetType::Soft, None)?; + //let mut walk = repo.revwalk()?; + //walk.set_sorting(git2::Sort::TIME)?; + //walk.push_head()?; + //let head = walk.next().ok_or(git2::Error::from_str("no head"))?.map(|oid|repo.find_commit(oid))??; + //let oldest_commit = repo.find_commit(walk.last().ok_or(git2::Error::from_str("No Oldest commit"))??)?; + // + //#[cfg(debug_assertions)] + //{ + // eprintln!("oldest commit found and head checked"); + // std::io::stdin().read_line(&mut String::new())?; + //} - //repo.cherrypick(&head, None)?; - #[cfg(debug_assertions)] - { - eprintln!("repo reset"); - std::io::stdin().read_line(&mut String::new())?; - } - - - let mut index = repo.index()?; - index.add_all(["**"], IndexAddOption::DEFAULT, None)?; - let tree = repo.find_tree(index.write_tree()?)?; - repo.set_index(&mut index)?; - #[cfg(debug_assertions)] - { - eprintln!("index set"); - std::io::stdin().read_line(&mut String::new())?; - } - - oldest_commit.amend(None, None, None, None, Some(format!("Initialized repo from {} skeleton", skelly_name).as_str()), Some(&tree))?; - - #[cfg(debug_assertions)] - { - eprintln!("commit ammended"); - std::io::stdin().read_line(&mut String::new())?; - } - return Ok(()) + eprintln!("rebasing skeleton's commits down into single commit"); + // I give up git2 documentation/api is just too bad for me to do this + std::process::exit(std::process::Command::new("git") + .current_dir(repo.path()) + .args(["rebase", "-i" , "--root" , skelly_branch.as_str()]) + .status()?.code().ok_or(Errors::Unknown)?); } None=>{ - println!("failed to provide a path to clone the skeleton directory into"); + eprintln!("failed to provide a path to clone the skeleton directory into"); std::process::exit(1); } }