Skip to content

Commit

Permalink
feat(commit): add commit pretty print
Browse files Browse the repository at this point in the history
  • Loading branch information
oknozor committed Sep 11, 2020
1 parent 5ff48a0 commit 2248c90
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
5 changes: 4 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,10 @@ impl CocoGitto {
None => format!("{}: {}", commit_type, message,),
};

self.repository.commit(message)
let oid = self.repository.commit(message)?;
let commit = self.repository.0.find_commit(oid)?;
let commit = Commit::from_git_commit(&commit)?;
Ok(println!("{}", commit))
}

pub fn create_version(&self, increment: VersionIncrement) -> Result<()> {
Expand Down
6 changes: 2 additions & 4 deletions src/repository.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::error::CocoGittoError::GitError;
use anyhow::Result;
use anyhow::{Error, Result};
use colored::Colorize;
use git2::{
Commit as Git2Commit, DiffOptions, Object, ObjectType, Oid, Repository as Git2Repository,
Expand All @@ -20,7 +20,7 @@ impl Repository {
self.0.workdir()
}

pub fn commit(&self, message: String) -> Result<()> {
pub fn commit(&self, message: String) -> Result<Oid> {
let repo = &self.0;
let sig = &&self.0.signature()?;
let tree_id = &&self.0.index()?.write_tree()?;
Expand Down Expand Up @@ -48,13 +48,11 @@ impl Repository {

self.0
.commit(Some("HEAD"), &sig, &sig, &message, &tree, &[&tip])
.map(|_| ())
.map_err(|err| anyhow!(err))
} else if repo_is_empty && repo_has_deltas {
// First repo commit
self.0
.commit(Some("HEAD"), &sig, &sig, &message, &tree, &[])
.map(|_| ())
.map_err(|err| anyhow!(err))
} else {
let statuses = repo.statuses(None)?;
Expand Down

0 comments on commit 2248c90

Please sign in to comment.