@@ -151,12 +151,13 @@ impl <'repo> Rebase<'repo> {
151
151
152
152
/// Commits the current patch. You must have resolved any conflicts that
153
153
/// were introduced during the patch application from the `git_rebase_next`
154
- /// invocation.
155
- pub fn commit ( & mut self , author : & Signature , committer : & Signature , message : & str ) -> Result < Oid , Error > {
154
+ /// invocation. To keep the author and message from the original commit leave
155
+ /// them as None
156
+ pub fn commit ( & mut self , author : Option < & Signature > , committer : & Signature , message : Option < & str > ) -> Result < Oid , Error > {
156
157
let mut id: raw:: git_oid = unsafe { mem:: zeroed ( ) } ;
157
- let message = try!( CString :: new ( message) ) ;
158
+ let message = try!( :: opt_cstr ( message) ) ;
158
159
unsafe {
159
- try_call ! ( raw:: git_rebase_commit( & mut id, self . raw, author. raw( ) , committer. raw( ) , ptr:: null( ) , message) ) ;
160
+ try_call ! ( raw:: git_rebase_commit( & mut id, self . raw, author. map ( |a| a . raw( ) ) , committer. raw( ) , ptr:: null( ) , message) ) ;
160
161
Ok ( Binding :: from_raw ( & id as * const _ ) )
161
162
}
162
163
}
@@ -173,9 +174,9 @@ impl <'repo> Rebase<'repo> {
173
174
174
175
/// Finishes a rebase that is currently in progress once all patches have
175
176
/// been applied.
176
- pub fn finish ( & mut self , signature : & Signature ) -> Result < ( ) , Error > {
177
+ pub fn finish ( & mut self , signature : Option < & Signature > ) -> Result < ( ) , Error > {
177
178
unsafe {
178
- try_call ! ( raw:: git_rebase_finish( self . raw, signature. raw( ) ) ) ;
179
+ try_call ! ( raw:: git_rebase_finish( self . raw, signature. map ( |s| s . raw( ) ) ) ) ;
179
180
}
180
181
181
182
Ok ( ( ) )
@@ -313,7 +314,8 @@ impl<'rebase> Binding for RebaseOperation<'rebase> {
313
314
314
315
#[ cfg( test) ]
315
316
mod tests {
316
- use { RebaseOptions , RebaseOperationType } ;
317
+ use std:: { fs, path} ;
318
+ use { RebaseOptions , RebaseOperationType , Signature } ;
317
319
318
320
#[ test]
319
321
fn smoke ( ) {
@@ -351,4 +353,60 @@ mod tests {
351
353
assert ! ( op. is_none( ) ) ;
352
354
}
353
355
}
356
+
357
+ #[ test]
358
+ fn keeping_original_author_msg ( ) {
359
+ let ( td, repo) = :: test:: repo_init ( ) ;
360
+ let head_target = repo. head ( ) . unwrap ( ) . target ( ) . unwrap ( ) ;
361
+ let tip = repo. find_commit ( head_target) . unwrap ( ) ;
362
+ let sig = Signature :: now ( "testname" , "testemail" ) . unwrap ( ) ;
363
+ let mut index = repo. index ( ) . unwrap ( ) ;
364
+
365
+ fs:: File :: create ( td. path ( ) . join ( "file_a" ) ) . unwrap ( ) ;
366
+ index. add_path ( path:: Path :: new ( "file_a" ) ) . unwrap ( ) ;
367
+ index. write ( ) . unwrap ( ) ;
368
+ let tree_id_a = index. write_tree ( ) . unwrap ( ) ;
369
+ let tree_a = repo. find_tree ( tree_id_a) . unwrap ( ) ;
370
+ let c1 = repo
371
+ . commit ( Some ( "refs/heads/master" ) , & sig, & sig, "A" , & tree_a, & [ & tip] )
372
+ . unwrap ( ) ;
373
+ let c1 = repo. find_commit ( c1) . unwrap ( ) ;
374
+
375
+ fs:: File :: create ( td. path ( ) . join ( "file_b" ) ) . unwrap ( ) ;
376
+ index. add_path ( path:: Path :: new ( "file_b" ) ) . unwrap ( ) ;
377
+ index. write ( ) . unwrap ( ) ;
378
+ let tree_id_b = index. write_tree ( ) . unwrap ( ) ;
379
+ let tree_b = repo. find_tree ( tree_id_b) . unwrap ( ) ;
380
+ let c2 = repo
381
+ . commit ( Some ( "refs/heads/master" ) , & sig, & sig, "B" , & tree_b, & [ & c1] )
382
+ . unwrap ( ) ;
383
+
384
+ let branch = repo. find_annotated_commit ( c2) . unwrap ( ) ;
385
+ let upstream = repo. find_annotated_commit ( tip. id ( ) ) . unwrap ( ) ;
386
+ let mut opts: RebaseOptions = Default :: default ( ) ;
387
+ let mut rebase = repo
388
+ . rebase ( Some ( & branch) , Some ( & upstream) , None , Some ( & mut opts) )
389
+ . unwrap ( ) ;
390
+
391
+ assert_eq ! ( rebase. len( ) , 2 ) ;
392
+
393
+ {
394
+ rebase. next ( ) . unwrap ( ) . unwrap ( ) ;
395
+ let id = rebase. commit ( None , & sig, None ) . unwrap ( ) ;
396
+ let commit = repo. find_commit ( id) . unwrap ( ) ;
397
+ assert_eq ! ( commit. message( ) , Some ( "A" ) ) ;
398
+ assert_eq ! ( commit. author( ) . name( ) , Some ( "testname" ) ) ;
399
+ assert_eq ! ( commit. author( ) . email( ) , Some ( "testemail" ) ) ;
400
+ }
401
+
402
+ {
403
+ rebase. next ( ) . unwrap ( ) . unwrap ( ) ;
404
+ let id = rebase. commit ( None , & sig, None ) . unwrap ( ) ;
405
+ let commit = repo. find_commit ( id) . unwrap ( ) ;
406
+ assert_eq ! ( commit. message( ) , Some ( "B" ) ) ;
407
+ assert_eq ! ( commit. author( ) . name( ) , Some ( "testname" ) ) ;
408
+ assert_eq ! ( commit. author( ) . email( ) , Some ( "testemail" ) ) ;
409
+ }
410
+ rebase. finish ( None ) . unwrap ( ) ;
411
+ }
354
412
}
0 commit comments