Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 59d43f4

Browse files
mxorkStephan Dilly
authored and
Stephan Dilly
committed
allow undefined user.name on commit
1 parent 6630b7c commit 59d43f4

File tree

1 file changed

+20
-1
lines changed

1 file changed

+20
-1
lines changed

‎asyncgit/src/sync/utils.rs‎

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,25 @@ pub fn get_head_repo(repo: &Repository) -> Result<CommitId> {
6666
}
6767
}
6868

69+
/// Wrap Repository::signature to allow unknown user.name.
70+
///
71+
/// See <https://github.com/extrawurst/gitui/issues/79>.
72+
pub fn signature_allow_undefined_name(
73+
repo: &Repository,
74+
) -> std::result::Result<git2::Signature<'static>, git2::Error> {
75+
match repo.signature() {
76+
Err(e) if e.code() == git2::ErrorCode::NotFound => {
77+
let config = repo.config()?;
78+
git2::Signature::now(
79+
config.get_str("user.name").unwrap_or("unknown"),
80+
config.get_str("user.email")?,
81+
)
82+
}
83+
84+
v => v,
85+
}
86+
}
87+
6988
/// ditto
7089
pub fn commit_new(repo_path: &str, msg: &str) -> Result<CommitId> {
7190
commit(repo_path, msg).map(CommitId::new)
@@ -77,7 +96,7 @@ pub fn commit(repo_path: &str, msg: &str) -> Result<Oid> {
7796

7897
let repo = repo(repo_path)?;
7998

80-
let signature = repo.signature()?;
99+
let signature = signature_allow_undefined_name(&repo)?;
81100
let mut index = repo.index()?;
82101
let tree_id = index.write_tree()?;
83102
let tree = repo.find_tree(tree_id)?;

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /