@@ -66,13 +66,32 @@ pub fn get_head_repo(repo: &Repository) -> Result<CommitId> {
66
66
}
67
67
}
68
68
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
+
69
88
/// this does not run any git hooks
70
89
pub fn commit ( repo_path : & str , msg : & str ) -> Result < CommitId > {
71
90
scope_time ! ( "commit" ) ;
72
91
73
92
let repo = repo ( repo_path) ?;
74
93
75
- let signature = repo . signature ( ) ?;
94
+ let signature = signature_allow_undefined_name ( & repo ) ?;
76
95
let mut index = repo. index ( ) ?;
77
96
let tree_id = index. write_tree ( ) ?;
78
97
let tree = repo. find_tree ( tree_id) ?;
0 commit comments