mirror of
https://github.com/Pagwin-Fedora/ppi.git
synced 2025-07-17 22:15:42 +00:00
giving up and using the cli
This commit is contained in:
parent
33b158cc4c
commit
6a7f413a9c
1 changed files with 36 additions and 58 deletions
94
src/main.rs
94
src/main.rs
|
@ -6,7 +6,6 @@ extern crate git2;
|
||||||
use std::{path::{PathBuf, Path}, io::{Read, Cursor}, collections::{HashMap, HashSet}, ffi::OsStr};
|
use std::{path::{PathBuf, Path}, io::{Read, Cursor}, collections::{HashMap, HashSet}, ffi::OsStr};
|
||||||
|
|
||||||
use clap::{Command, Arg};
|
use clap::{Command, Arg};
|
||||||
use git2::{build::CheckoutBuilder, IndexAddOption};
|
|
||||||
use serde::{Serialize, Deserialize};
|
use serde::{Serialize, Deserialize};
|
||||||
|
|
||||||
|
|
||||||
|
@ -105,26 +104,26 @@ fn main() -> Result<(),Errors> {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
let branch = repo.branches(Some(git2::BranchType::Remote))?.find(|branch|{
|
// let branch = repo.branches(Some(git2::BranchType::Remote))?.find(|branch|{
|
||||||
if let Ok(branch) = branch{
|
// if let Ok(branch) = branch{
|
||||||
if let Ok(Some(name)) = branch.0.name(){
|
// if let Ok(Some(name)) = branch.0.name(){
|
||||||
name == format!("origin/{}",skelly_branch)
|
// name == format!("origin/{}",skelly_branch)
|
||||||
}else{false}
|
// }else{false}
|
||||||
}else{false}
|
// }else{false}
|
||||||
}).ok_or(git2::Error::from_str(format!("no branch with name {}",skelly_branch).as_str()))??;
|
// }).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"))?){
|
// 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)=>{
|
// Err(e)=>{
|
||||||
panic!("{}",e.message());
|
// panic!("{}",e.message());
|
||||||
}
|
// }
|
||||||
_=>{}
|
// _=>{}
|
||||||
}
|
// }
|
||||||
|
|
||||||
#[cfg(debug_assertions)]
|
//#[cfg(debug_assertions)]
|
||||||
{
|
//{
|
||||||
eprintln!("head set");
|
// eprintln!("head set");
|
||||||
std::io::stdin().read_line(&mut String::new())?;
|
// std::io::stdin().read_line(&mut String::new())?;
|
||||||
}
|
//}
|
||||||
|
|
||||||
repo.remote_delete("origin")?;
|
repo.remote_delete("origin")?;
|
||||||
|
|
||||||
|
@ -136,49 +135,28 @@ fn main() -> Result<(),Errors> {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
let mut walk = repo.revwalk()?;
|
//let mut walk = repo.revwalk()?;
|
||||||
walk.set_sorting(git2::Sort::TIME)?;
|
//walk.set_sorting(git2::Sort::TIME)?;
|
||||||
walk.push_head()?;
|
//walk.push_head()?;
|
||||||
let oldest_commit = repo.find_commit(walk.last().ok_or(Errors::GitErr(git2::Error::from_str("No Oldest commit")))??)?;
|
//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)]
|
//
|
||||||
{
|
//#[cfg(debug_assertions)]
|
||||||
eprintln!("oldest commit found and head checked");
|
//{
|
||||||
std::io::stdin().read_line(&mut String::new())?;
|
// 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)?;
|
|
||||||
|
|
||||||
|
|
||||||
//repo.cherrypick(&head, None)?;
|
eprintln!("rebasing skeleton's commits down into single commit");
|
||||||
#[cfg(debug_assertions)]
|
// I give up git2 documentation/api is just too bad for me to do this
|
||||||
{
|
std::process::exit(std::process::Command::new("git")
|
||||||
eprintln!("repo reset");
|
.current_dir(repo.path())
|
||||||
std::io::stdin().read_line(&mut String::new())?;
|
.args(["rebase", "-i" , "--root" , skelly_branch.as_str()])
|
||||||
}
|
.status()?.code().ok_or(Errors::Unknown)?);
|
||||||
|
|
||||||
|
|
||||||
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(())
|
|
||||||
}
|
}
|
||||||
None=>{
|
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);
|
std::process::exit(1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue