Skip to content

Commit

Permalink
refactor: clippy lints
Browse files Browse the repository at this point in the history
  • Loading branch information
oknozor committed Sep 11, 2020
1 parent aa4a853 commit 0639872
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 28 deletions.
5 changes: 2 additions & 3 deletions src/commit.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
use crate::commit::CommitType::*;
use crate::error::CocoGittoError::CommitFormatError;
use anyhow::Result;
use chrono::format::Numeric::Timestamp;
use chrono::{DateTime, Duration, NaiveDateTime, Utc};
use chrono::{NaiveDateTime, Utc};
use colored::*;
use git2::Commit as Git2Commit;
use serde::export::Formatter;
Expand Down Expand Up @@ -101,7 +100,7 @@ impl Commit {
type_and_scope = &type_and_scope[0..type_and_scope.len() - 1];
}

let mut commit_type;
let commit_type;

let scope: Option<String> = if let Some(left_par_idx) = type_and_scope.find("(") {
commit_type = CommitType::from(&type_and_scope[0..left_par_idx]);
Expand Down
2 changes: 0 additions & 2 deletions src/error.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
use crate::commit::Commit;
use colored::*;
use thiserror::Error;

#[derive(Error, Debug)]
Expand Down
53 changes: 30 additions & 23 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ use crate::repository::Repository;
use crate::semver::SemVer;
use crate::settings::Settings;
use anyhow::Result;
use chrono::{NaiveDateTime, Utc};
use chrono::Utc;
use colored::*;
use commit::Commit;
use git2::{Commit as Git2Commit, Oid, RebaseOptions, Repository as Git2Repository};
Expand Down Expand Up @@ -99,40 +99,45 @@ impl CocoGitto {
.map(|commit| commit.0)
.collect();

let last_errored_commit = errored_commits.last();
println!("{:?}", last_errored_commit);
let commit = self
.repository
.0
.find_commit(errored_commits.last().unwrap().to_owned())?;
.find_commit(last_errored_commit.unwrap().to_owned())?;
let rebase_start = commit.parent_id(0)?;
let commit = self.repository.0.find_annotated_commit(rebase_start)?;
let current = self.repository.0.find_annotated_commit(head)?;
let mut options = RebaseOptions::new();
let mut rebase = self
.repository
.0
.rebase(None, Some(&commit), None, Some(&mut options))?;

while let Some(Ok(rebase_operation)) = rebase.next() {
let oid = rebase_operation.id();
let original_commit = self.repository.0.find_commit(oid)?;
println!("rebasing {}", oid);
if errored_commits.contains(&oid) {
println!("\tmatch found in errored commits");
let file_path = dir.path().join(&commit.id().to_string());
let mut file = File::create(&file_path)?;
file.write_all(original_commit.message_bytes())?;

Command::new(&editor)
.arg(&file_path)
.stdout(Stdio::inherit())
.stdin(Stdio::inherit())
.stderr(Stdio::inherit())
.output()?;

let new_message = std::fs::read_to_string(&file_path)?;
rebase.commit(None, &original_commit.committer(), Some(&new_message))?;
while let Some(op) = rebase.next() {
if let Ok(rebase_operation) = op {
let oid = rebase_operation.id();
let original_commit = self.repository.0.find_commit(oid)?;
println!("rebasing {}", oid);
if errored_commits.contains(&oid) {
println!("\tmatch found in errored commits");
let file_path = dir.path().join(&commit.id().to_string());
let mut file = File::create(&file_path)?;
file.write_all(original_commit.message_bytes())?;

Command::new(&editor)
.arg(&file_path)
.stdout(Stdio::inherit())
.stdin(Stdio::inherit())
.stderr(Stdio::inherit())
.output()?;

let new_message = std::fs::read_to_string(&file_path)?;
rebase.commit(None, &original_commit.committer(), Some(&new_message))?;
} else {
rebase.commit(None, &original_commit.committer(), None)?;
}
} else {
rebase.commit(None, &original_commit.committer(), None)?;
eprintln!("{:?}", op);
}
}

Expand All @@ -146,6 +151,7 @@ impl CocoGitto {
let commits = self.get_commit_range(from, to)?;
let errors: Vec<anyhow::Error> = commits
.iter()
.filter(|commit| !commit.message().unwrap_or("").starts_with("Merge"))
.map(|commit| Commit::from_git_commit(commit))
.filter(|commit| commit.is_err())
.map(|err| err.unwrap_err())
Expand All @@ -167,6 +173,7 @@ impl CocoGitto {
let commits = self.get_commit_range(from, to)?;
let logs = commits
.iter()
.filter(|commit| !commit.message().unwrap_or("").starts_with("Merge"))
.map(|commit| Commit::from_git_commit(commit))
.map(|commit| match commit {
Ok(commit) => commit.get_log(),
Expand Down

0 comments on commit 0639872

Please sign in to comment.