Skip to content

Commit

Permalink
fix: inconsistencies with git commit (#32)
Browse files Browse the repository at this point in the history
`git commit` checks the current directory for a git repository and if none is found, it checks the parent directories. This commit brings `git-cm`'s behavior on-par with the one from `git commit`.
  • Loading branch information
maksyms authored Jul 22, 2020
1 parent d09fc0d commit 663182b
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions src/git.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use crate::questions::SurveyResults;
use anyhow::{anyhow, Result};
use git2::{Commit, ObjectType, Oid, Repository};
use git2::{Commit, ObjectType, Oid, Repository, RepositoryOpenFlags};
use once_cell::sync::Lazy;
use std::{collections::HashMap, path::Path};
use std::{collections::HashMap, ffi::OsStr, path::Path};

/// All default conventional commit types alongside their description.
pub static DEFAULT_TYPES: Lazy<HashMap<&str, &str>> = Lazy::new(|| {
Expand Down Expand Up @@ -103,8 +103,12 @@ fn find_last_commit(repo: &Repository) -> Result<Commit> {
/// The method uses the default username and email address found for the
/// repository. Defaults to the globally configured when needed.
pub fn commit_to_repo(msg: &str, repository: impl AsRef<Path>) -> Result<Oid> {
let repo =
Repository::open(repository.as_ref().as_os_str()).expect("Failed to open git repository");
let repo = Repository::open_ext(
repository.as_ref().as_os_str(),
RepositoryOpenFlags::empty(),
vec![OsStr::new("")],
)
.expect("Failed to open git repository");

let mut index = repo.index()?;
let oid = index.write_tree()?;
Expand Down

0 comments on commit 663182b

Please sign in to comment.