@@ -1262,42 +1262,33 @@ static int rebase_copy_notes(
12621262 return error ;
12631263}
12641264
1265- int git_rebase_finish (
1266- git_rebase * rebase ,
1267- const git_signature * signature )
1265+ static int return_to_orig_head (git_rebase * rebase )
12681266{
12691267 git_reference * terminal_ref = NULL , * branch_ref = NULL , * head_ref = NULL ;
12701268 git_commit * terminal_commit = NULL ;
12711269 git_buf branch_msg = GIT_BUF_INIT , head_msg = GIT_BUF_INIT ;
12721270 char onto [GIT_OID_HEXSZ ];
1273- int error ;
1274-
1275- assert (rebase );
1276-
1277- if (rebase -> inmemory )
1278- return 0 ;
1271+ int error = 0 ;
12791272
12801273 git_oid_fmt (onto , & rebase -> onto_id );
12811274
1282- if ((error = git_buf_printf (& branch_msg , "rebase finished: %s onto %.*s" ,
1283- rebase -> orig_head_name , GIT_OID_HEXSZ , onto )) < 0 ||
1284- (error = git_buf_printf (& head_msg , "rebase finished: returning to %s" ,
1285- rebase -> orig_head_name )) < 0 ||
1286- (error = git_repository_head (& terminal_ref , rebase -> repo )) < 0 ||
1275+ if ((error = git_buf_printf (& branch_msg ,
1276+ "rebase finished: %s onto %.*s" ,
1277+ rebase -> orig_head_name , GIT_OID_HEXSZ , onto )) == 0 &&
1278+ (error = git_buf_printf (& head_msg ,
1279+ "rebase finished: returning to %s" ,
1280+ rebase -> orig_head_name )) == 0 &&
1281+ (error = git_repository_head (& terminal_ref , rebase -> repo )) == 0 &&
12871282 (error = git_reference_peel ((git_object * * )& terminal_commit ,
1288- terminal_ref , GIT_OBJ_COMMIT )) < 0 ||
1283+ terminal_ref , GIT_OBJ_COMMIT )) == 0 &&
12891284 (error = git_reference_create_matching (& branch_ref ,
1290- rebase -> repo , rebase -> orig_head_name , git_commit_id (terminal_commit ), 1 ,
1291- & rebase -> orig_head_id , branch_msg .ptr )) < 0 ||
1292- (error = git_reference_symbolic_create (& head_ref ,
1285+ rebase -> repo , rebase -> orig_head_name ,
1286+ git_commit_id (terminal_commit ), 1 ,
1287+ & rebase -> orig_head_id , branch_msg .ptr )) == 0 )
1288+ error = git_reference_symbolic_create (& head_ref ,
12931289 rebase -> repo , GIT_HEAD_FILE , rebase -> orig_head_name , 1 ,
1294- head_msg .ptr )) < 0 ||
1295- (error = rebase_copy_notes (rebase , signature )) < 0 )
1296- goto done ;
1297-
1298- error = rebase_cleanup (rebase );
1290+ head_msg .ptr );
12991291
1300- done :
13011292 git_buf_free (& head_msg );
13021293 git_buf_free (& branch_msg );
13031294 git_commit_free (terminal_commit );
@@ -1308,6 +1299,26 @@ int git_rebase_finish(
13081299 return error ;
13091300}
13101301
1302+ int git_rebase_finish (
1303+ git_rebase * rebase ,
1304+ const git_signature * signature )
1305+ {
1306+ int error = 0 ;
1307+
1308+ assert (rebase );
1309+
1310+ if (rebase -> inmemory )
1311+ return 0 ;
1312+
1313+ if (!rebase -> head_detached )
1314+ error = return_to_orig_head (rebase );
1315+
1316+ if (error == 0 && (error = rebase_copy_notes (rebase , signature )) == 0 )
1317+ error = rebase_cleanup (rebase );
1318+
1319+ return error ;
1320+ }
1321+
13111322size_t git_rebase_operation_entrycount (git_rebase * rebase )
13121323{
13131324 assert (rebase );
0 commit comments