mirror of
https://github.com/gitui-org/gitui
synced 2026-05-24 01:18:21 +00:00
Merge branch 'master' of github.com:Extrawurst/gitui
# Conflicts: # asyncgit/src/sync/utils.rs
This commit is contained in:
commit
37b0644d96
1 changed files with 20 additions and 1 deletions
|
|
@ -66,13 +66,32 @@ pub fn get_head_repo(repo: &Repository) -> Result<CommitId> {
|
|||
}
|
||||
}
|
||||
|
||||
/// Wrap Repository::signature to allow unknown user.name.
|
||||
///
|
||||
/// See <https://github.com/extrawurst/gitui/issues/79>.
|
||||
pub fn signature_allow_undefined_name(
|
||||
repo: &Repository,
|
||||
) -> std::result::Result<git2::Signature<'static>, git2::Error> {
|
||||
match repo.signature() {
|
||||
Err(e) if e.code() == git2::ErrorCode::NotFound => {
|
||||
let config = repo.config()?;
|
||||
git2::Signature::now(
|
||||
config.get_str("user.name").unwrap_or("unknown"),
|
||||
config.get_str("user.email")?,
|
||||
)
|
||||
}
|
||||
|
||||
v => v,
|
||||
}
|
||||
}
|
||||
|
||||
/// this does not run any git hooks
|
||||
pub fn commit(repo_path: &str, msg: &str) -> Result<CommitId> {
|
||||
scope_time!("commit");
|
||||
|
||||
let repo = repo(repo_path)?;
|
||||
|
||||
let signature = repo.signature()?;
|
||||
let signature = signature_allow_undefined_name(&repo)?;
|
||||
let mut index = repo.index()?;
|
||||
let tree_id = index.write_tree()?;
|
||||
let tree = repo.find_tree(tree_id)?;
|
||||
|
|
|
|||
Loading…
Reference in a new issue