@@ -5146,33 +5146,47 @@ static int commit_staged_changes(struct repository *r,
5146
5146
struct replay_ctx * ctx = opts -> ctx ;
5147
5147
unsigned int flags = ALLOW_EMPTY | EDIT_MSG ;
5148
5148
unsigned int final_fixup = 0 , is_clean ;
5149
+ struct strbuf rev = STRBUF_INIT ;
5150
+ int ret ;
5149
5151
5150
- if (has_unstaged_changes (r , 1 ))
5151
- return error (_ ("cannot rebase: You have unstaged changes." ));
5152
+ if (has_unstaged_changes (r , 1 )) {
5153
+ ret = error (_ ("cannot rebase: You have unstaged changes." ));
5154
+ goto out ;
5155
+ }
5152
5156
5153
5157
is_clean = !has_uncommitted_changes (r , 0 );
5154
5158
5155
5159
if (!is_clean && !file_exists (rebase_path_message ())) {
5156
5160
const char * gpg_opt = gpg_sign_opt_quoted (opts );
5157
-
5158
- return error ( _ ( staged_changes_advice ), gpg_opt , gpg_opt ) ;
5161
+ ret = error ( _ ( staged_changes_advice ), gpg_opt , gpg_opt );
5162
+ goto out ;
5159
5163
}
5164
+
5160
5165
if (file_exists (rebase_path_amend ())) {
5161
- struct strbuf rev = STRBUF_INIT ;
5162
5166
struct object_id head , to_amend ;
5163
5167
5164
- if (repo_get_oid (r , "HEAD" , & head ))
5165
- return error (_ ("cannot amend non-existing commit" ));
5166
- if (!read_oneliner (& rev , rebase_path_amend (), 0 ))
5167
- return error (_ ("invalid file: '%s'" ), rebase_path_amend ());
5168
- if (get_oid_hex (rev .buf , & to_amend ))
5169
- return error (_ ("invalid contents: '%s'" ),
5170
- rebase_path_amend ());
5171
- if (!is_clean && !oideq (& head , & to_amend ))
5172
- return error (_ ("\nYou have uncommitted changes in your "
5173
- "working tree. Please, commit them\n"
5174
- "first and then run 'git rebase "
5175
- "--continue' again." ));
5168
+ if (repo_get_oid (r , "HEAD" , & head )) {
5169
+ ret = error (_ ("cannot amend non-existing commit" ));
5170
+ goto out ;
5171
+ }
5172
+
5173
+ if (!read_oneliner (& rev , rebase_path_amend (), 0 )) {
5174
+ ret = error (_ ("invalid file: '%s'" ), rebase_path_amend ());
5175
+ goto out ;
5176
+ }
5177
+
5178
+ if (get_oid_hex (rev .buf , & to_amend )) {
5179
+ ret = error (_ ("invalid contents: '%s'" ),
5180
+ rebase_path_amend ());
5181
+ goto out ;
5182
+ }
5183
+ if (!is_clean && !oideq (& head , & to_amend )) {
5184
+ ret = error (_ ("\nYou have uncommitted changes in your "
5185
+ "working tree. Please, commit them\n"
5186
+ "first and then run 'git rebase "
5187
+ "--continue' again." ));
5188
+ goto out ;
5189
+ }
5176
5190
/*
5177
5191
* When skipping a failed fixup/squash, we need to edit the
5178
5192
* commit message, the current fixup list and count, and if it
@@ -5204,9 +5218,11 @@ static int commit_staged_changes(struct repository *r,
5204
5218
len -- ;
5205
5219
strbuf_setlen (& ctx -> current_fixups , len );
5206
5220
if (write_message (p , len , rebase_path_current_fixups (),
5207
- 0 ) < 0 )
5208
- return error (_ ("could not write file: '%s'" ),
5209
- rebase_path_current_fixups ());
5221
+ 0 ) < 0 ) {
5222
+ ret = error (_ ("could not write file: '%s'" ),
5223
+ rebase_path_current_fixups ());
5224
+ goto out ;
5225
+ }
5210
5226
5211
5227
/*
5212
5228
* If a fixup/squash in a fixup/squash chain failed, the
@@ -5236,54 +5252,68 @@ static int commit_staged_changes(struct repository *r,
5236
5252
* We need to update the squash message to skip
5237
5253
* the latest commit message.
5238
5254
*/
5239
- int res = 0 ;
5240
5255
struct commit * commit ;
5241
5256
const char * msg ;
5242
5257
const char * path = rebase_path_squash_msg ();
5243
5258
const char * encoding = get_commit_output_encoding ();
5244
5259
5245
- if (parse_head (r , & commit ))
5246
- return error (_ ("could not parse HEAD" ));
5260
+ if (parse_head (r , & commit )) {
5261
+ ret = error (_ ("could not parse HEAD" ));
5262
+ goto out ;
5263
+ }
5247
5264
5248
5265
p = repo_logmsg_reencode (r , commit , NULL , encoding );
5249
5266
if (!p ) {
5250
- res = error (_ ("could not parse commit %s" ),
5267
+ ret = error (_ ("could not parse commit %s" ),
5251
5268
oid_to_hex (& commit -> object .oid ));
5252
5269
goto unuse_commit_buffer ;
5253
5270
}
5254
5271
find_commit_subject (p , & msg );
5255
5272
if (write_message (msg , strlen (msg ), path , 0 )) {
5256
- res = error (_ ("could not write file: "
5273
+ ret = error (_ ("could not write file: "
5257
5274
"'%s'" ), path );
5258
5275
goto unuse_commit_buffer ;
5259
5276
}
5277
+
5278
+ ret = 0 ;
5279
+
5260
5280
unuse_commit_buffer :
5261
5281
repo_unuse_commit_buffer (r , commit , p );
5262
- if (res )
5263
- return res ;
5282
+ if (ret )
5283
+ goto out ;
5264
5284
}
5265
5285
}
5266
5286
5267
- strbuf_release (& rev );
5268
5287
flags |= AMEND_MSG ;
5269
5288
}
5270
5289
5271
5290
if (is_clean ) {
5272
5291
if (refs_ref_exists (get_main_ref_store (r ),
5273
5292
"CHERRY_PICK_HEAD" ) &&
5274
5293
refs_delete_ref (get_main_ref_store (r ), "" ,
5275
- "CHERRY_PICK_HEAD" , NULL , REF_NO_DEREF ))
5276
- return error (_ ("could not remove CHERRY_PICK_HEAD" ));
5277
- if (unlink (git_path_merge_msg (r )) && errno != ENOENT )
5278
- return error_errno (_ ("could not remove '%s'" ),
5279
- git_path_merge_msg (r ));
5280
- if (!final_fixup )
5281
- return 0 ;
5294
+ "CHERRY_PICK_HEAD" , NULL , REF_NO_DEREF )) {
5295
+ ret = error (_ ("could not remove CHERRY_PICK_HEAD" ));
5296
+ goto out ;
5297
+ }
5298
+
5299
+ if (unlink (git_path_merge_msg (r )) && errno != ENOENT ) {
5300
+ ret = error_errno (_ ("could not remove '%s'" ),
5301
+ git_path_merge_msg (r ));
5302
+ goto out ;
5303
+ }
5304
+
5305
+ if (!final_fixup ) {
5306
+ ret = 0 ;
5307
+ goto out ;
5308
+ }
5282
5309
}
5283
5310
5284
5311
if (run_git_commit (final_fixup ? NULL : rebase_path_message (),
5285
- opts , flags ))
5286
- return error (_ ("could not commit staged changes." ));
5312
+ opts , flags )) {
5313
+ ret = error (_ ("could not commit staged changes." ));
5314
+ goto out ;
5315
+ }
5316
+
5287
5317
unlink (rebase_path_amend ());
5288
5318
unlink (git_path_merge_head (r ));
5289
5319
refs_delete_ref (get_main_ref_store (r ), "" , "AUTO_MERGE" ,
@@ -5301,7 +5331,12 @@ static int commit_staged_changes(struct repository *r,
5301
5331
strbuf_reset (& ctx -> current_fixups );
5302
5332
ctx -> current_fixup_count = 0 ;
5303
5333
}
5304
- return 0 ;
5334
+
5335
+ ret = 0 ;
5336
+
5337
+ out :
5338
+ strbuf_release (& rev );
5339
+ return ret ;
5305
5340
}
5306
5341
5307
5342
int sequencer_continue (struct repository * r , struct replay_opts * opts )
0 commit comments