cargo fix + fmt + clippy
This commit is contained in:
parent
c4b864f38f
commit
e6a2866e7e
55
src/git.rs
55
src/git.rs
@ -1,11 +1,14 @@
|
|||||||
use crate::api::search::PullRequestStatus;
|
use crate::api::search::PullRequestStatus;
|
||||||
use crate::graph::FlatDep;
|
use crate::graph::FlatDep;
|
||||||
use std::error::Error;
|
|
||||||
use git2::{Cred, ObjectType, Repository, Index, Sort, CherrypickOptions, Remote, Commit, PushOptions, RemoteCallbacks};
|
|
||||||
use git2::build::CheckoutBuilder;
|
|
||||||
use tokio::process::Command;
|
|
||||||
use dialoguer::Input;
|
use dialoguer::Input;
|
||||||
use std::env;
|
use git2::build::CheckoutBuilder;
|
||||||
|
use git2::{
|
||||||
|
CherrypickOptions,
|
||||||
|
Repository, Sort,
|
||||||
|
};
|
||||||
|
|
||||||
|
use std::error::Error;
|
||||||
|
use tokio::process::Command;
|
||||||
|
|
||||||
fn remote_ref(remote: &str, git_ref: &str) -> String {
|
fn remote_ref(remote: &str, git_ref: &str) -> String {
|
||||||
format!("{}/{}", remote, git_ref)
|
format!("{}/{}", remote, git_ref)
|
||||||
@ -14,10 +17,13 @@ fn remote_ref(remote: &str, git_ref: &str) -> String {
|
|||||||
fn loop_until_confirm(prompt: &str) {
|
fn loop_until_confirm(prompt: &str) {
|
||||||
let prompt = format!("{} Type 'yes' to continue", prompt);
|
let prompt = format!("{} Type 'yes' to continue", prompt);
|
||||||
loop {
|
loop {
|
||||||
let result = Input::<String>::new().with_prompt(&prompt).interact().unwrap();
|
let result = Input::<String>::new()
|
||||||
|
.with_prompt(&prompt)
|
||||||
|
.interact()
|
||||||
|
.unwrap();
|
||||||
match &result[..] {
|
match &result[..] {
|
||||||
"yes" => return,
|
"yes" => return,
|
||||||
_ => continue
|
_ => continue,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -58,7 +64,10 @@ pub fn generate_rebase_script(deps: FlatDep) -> String {
|
|||||||
out.push_str("\n# -------------- #\n\n");
|
out.push_str("\n# -------------- #\n\n");
|
||||||
|
|
||||||
out.push_str(&format!("export TO=\"{}\"\n", remote_ref("heap", &to)));
|
out.push_str(&format!("export TO=\"{}\"\n", remote_ref("heap", &to)));
|
||||||
out.push_str(&format!("export FROM=\"{}\"\n\n", remote_ref("heap", from.head())));
|
out.push_str(&format!(
|
||||||
|
"export FROM=\"{}\"\n\n",
|
||||||
|
remote_ref("heap", from.head())
|
||||||
|
));
|
||||||
|
|
||||||
out.push_str("git checkout \"$TO\"\n");
|
out.push_str("git checkout \"$TO\"\n");
|
||||||
out.push_str("git cherry-pick \"$PREBASE\"..\"$FROM\"\n");
|
out.push_str("git cherry-pick \"$PREBASE\"..\"$FROM\"\n");
|
||||||
@ -69,7 +78,11 @@ pub fn generate_rebase_script(deps: FlatDep) -> String {
|
|||||||
out
|
out
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn perform_rebase(deps: FlatDep, repo: &Repository, remote: &str) -> Result<(), Box<dyn Error>> {
|
pub async fn perform_rebase(
|
||||||
|
deps: FlatDep,
|
||||||
|
repo: &Repository,
|
||||||
|
remote: &str,
|
||||||
|
) -> Result<(), Box<dyn Error>> {
|
||||||
let deps = deps
|
let deps = deps
|
||||||
.iter()
|
.iter()
|
||||||
.filter(|(dep, _)| *dep.state() == PullRequestStatus::Open)
|
.filter(|(dep, _)| *dep.state() == PullRequestStatus::Open)
|
||||||
@ -96,7 +109,6 @@ pub async fn perform_rebase(deps: FlatDep, repo: &Repository, remote: &str) -> R
|
|||||||
for (pr, _) in deps {
|
for (pr, _) in deps {
|
||||||
println!("Working on PR: {:?}", pr.head());
|
println!("Working on PR: {:?}", pr.head());
|
||||||
|
|
||||||
|
|
||||||
let from = repo.revparse_single(&pr.head()).unwrap();
|
let from = repo.revparse_single(&pr.head()).unwrap();
|
||||||
let from = from.as_commit().unwrap();
|
let from = from.as_commit().unwrap();
|
||||||
|
|
||||||
@ -110,7 +122,9 @@ pub async fn perform_rebase(deps: FlatDep, repo: &Repository, remote: &str) -> R
|
|||||||
// TODO: Skip if remote/<branch> is the same SHA as <branch>
|
// TODO: Skip if remote/<branch> is the same SHA as <branch>
|
||||||
for from in walk {
|
for from in walk {
|
||||||
let from = repo.find_commit(from.unwrap()).unwrap();
|
let from = repo.find_commit(from.unwrap()).unwrap();
|
||||||
let to = repo.find_commit(repo.head().unwrap().target().unwrap()).unwrap();
|
let to = repo
|
||||||
|
.find_commit(repo.head().unwrap().target().unwrap())
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
if from.parent_count() > 1 {
|
if from.parent_count() > 1 {
|
||||||
panic!("Exiting: I don't know how to deal with merge commits correctly.");
|
panic!("Exiting: I don't know how to deal with merge commits correctly.");
|
||||||
@ -137,12 +151,22 @@ pub async fn perform_rebase(deps: FlatDep, repo: &Repository, remote: &str) -> R
|
|||||||
let tree = repo.find_tree(tree).unwrap();
|
let tree = repo.find_tree(tree).unwrap();
|
||||||
|
|
||||||
let signature = repo.signature().unwrap();
|
let signature = repo.signature().unwrap();
|
||||||
let commit = repo.commit(None, &signature, &signature, &from.message().unwrap(), &tree, &[&to]).unwrap();
|
let commit = repo
|
||||||
|
.commit(
|
||||||
|
None,
|
||||||
|
&signature,
|
||||||
|
&signature,
|
||||||
|
&from.message().unwrap(),
|
||||||
|
&tree,
|
||||||
|
&[&to],
|
||||||
|
)
|
||||||
|
.unwrap();
|
||||||
let commit = repo.find_commit(commit).unwrap();
|
let commit = repo.find_commit(commit).unwrap();
|
||||||
|
|
||||||
let mut cb = CheckoutBuilder::new();
|
let mut cb = CheckoutBuilder::new();
|
||||||
cb.force();
|
cb.force();
|
||||||
repo.checkout_tree(&commit.as_object(), Some(&mut cb)).unwrap();
|
repo.checkout_tree(&commit.as_object(), Some(&mut cb))
|
||||||
|
.unwrap();
|
||||||
repo.set_head_detached(commit.id()).unwrap();
|
repo.set_head_detached(commit.id()).unwrap();
|
||||||
|
|
||||||
// "Complete" the cherry-pick. There is likely a better way to do
|
// "Complete" the cherry-pick. There is likely a better way to do
|
||||||
@ -156,14 +180,15 @@ pub async fn perform_rebase(deps: FlatDep, repo: &Repository, remote: &str) -> R
|
|||||||
repo.branch(pr.head(), &head, true).unwrap();
|
repo.branch(pr.head(), &head, true).unwrap();
|
||||||
|
|
||||||
// Use remote branch as boundary for next cherry-pick
|
// Use remote branch as boundary for next cherry-pick
|
||||||
let from = repo.revparse_single(&remote_ref(remote, pr.head())).unwrap();
|
let from = repo
|
||||||
|
.revparse_single(&remote_ref(remote, pr.head()))
|
||||||
|
.unwrap();
|
||||||
let from = from.as_commit().unwrap();
|
let from = from.as_commit().unwrap();
|
||||||
stop_cherry_pick_at = from.id();
|
stop_cherry_pick_at = from.id();
|
||||||
|
|
||||||
push_refspecs.push(format!("refs/heads/{}:refs/heads/{}", pr.head(), pr.head()));
|
push_refspecs.push(format!("refs/heads/{}:refs/heads/{}", pr.head(), pr.head()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
let repo_dir = repo.workdir().unwrap().to_str().unwrap();
|
let repo_dir = repo.workdir().unwrap().to_str().unwrap();
|
||||||
|
|
||||||
// `libgit2` doesn't support refspecs containing raw SHAs, so we shell out
|
// `libgit2` doesn't support refspecs containing raw SHAs, so we shell out
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
use std::collections::HashMap;
|
|
||||||
use git2::Repository;
|
use git2::Repository;
|
||||||
|
use std::collections::HashMap;
|
||||||
use std::env;
|
use std::env;
|
||||||
use std::error::Error;
|
use std::error::Error;
|
||||||
use std::fs;
|
use std::fs;
|
||||||
|
@ -1,10 +1,6 @@
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
use regex::Regex;
|
use regex::Regex;
|
||||||
|
|
||||||
|
use crate::api::search::PullRequestStatus;
|
||||||
use crate::api::search::{PullRequestStatus};
|
|
||||||
use crate::graph::FlatDep;
|
use crate::graph::FlatDep;
|
||||||
|
|
||||||
fn process(row: String) -> String {
|
fn process(row: String) -> String {
|
||||||
|
Loading…
Reference in New Issue
Block a user