@@ -140,18 +140,28 @@ pub struct SubmitOptions {
140
140
141
141
/// The result of creating a commit.
142
142
#[ derive( Clone , Debug ) ]
143
- pub struct CreateStatus {
144
- /// The commit OID after carrying out the creation process. Usually, this
145
- /// will be the same as the original commit OID, unless the forge amends it
146
- /// (e.g. to include a change ID).
147
- pub final_commit_oid : NonZeroOid ,
148
-
149
- /// An identifier corresponding to the commit, for display purposes only.
150
- /// This may be a branch name, a change ID, the commit summary, etc.
151
- ///
152
- /// This does not necessarily correspond to the commit's name/identifier in
153
- /// the forge (e.g. not a code review link).
154
- pub local_commit_name : String ,
143
+ pub enum CreateStatus {
144
+ /// The commit was successfully created.
145
+ Created {
146
+ /// The commit OID after carrying out the creation process. Usually, this
147
+ /// will be the same as the original commit OID, unless the forge amends it
148
+ /// (e.g. to include a change ID).
149
+ final_commit_oid : NonZeroOid ,
150
+
151
+ /// An identifier corresponding to the commit, for display purposes only.
152
+ /// This may be a branch name, a change ID, the commit summary, etc.
153
+ ///
154
+ /// This does not necessarily correspond to the commit's name/identifier in
155
+ /// the forge (e.g. not a code review link).
156
+ local_commit_name : String ,
157
+ } ,
158
+
159
+ /// The commit was skipped. Possibly it had already been created, or it
160
+ /// couldn't be created due to a previous commit's error.
161
+ Skipped ,
162
+
163
+ /// An error occurred while trying to create the commit.
164
+ Err ,
155
165
}
156
166
157
167
/// "Forge" refers to a Git hosting provider, such as GitHub, GitLab, etc.
@@ -369,30 +379,52 @@ fn submit(
369
379
( local, unsubmitted, to_update, to_skip)
370
380
} ) ;
371
381
372
- let ( submitted_commit_names, unsubmitted_commit_names) : ( BTreeSet < String > , BTreeSet < String > ) = {
382
+ let ( submitted_commit_names, unsubmitted_commit_names, create_error_commits) : (
383
+ BTreeSet < String > ,
384
+ BTreeSet < String > ,
385
+ BTreeSet < NonZeroOid > ,
386
+ ) = {
373
387
let unsubmitted_commit_names: BTreeSet < String > = unsubmitted_commits
374
388
. values ( )
375
389
. flat_map ( |commit_status| commit_status. local_commit_name . clone ( ) )
376
390
. collect ( ) ;
377
391
if create {
378
- let created_commit_names = if dry_run {
379
- unsubmitted_commit_names. clone ( )
392
+ if dry_run {
393
+ (
394
+ unsubmitted_commit_names. clone ( ) ,
395
+ Default :: default ( ) ,
396
+ Default :: default ( ) ,
397
+ )
380
398
} else {
381
399
let create_statuses =
382
400
try_exit_code ! ( forge. create( unsubmitted_commits, & submit_options) ?) ;
383
- create_statuses
384
- . into_values ( )
385
- . map (
386
- |CreateStatus {
387
- final_commit_oid : _,
388
- local_commit_name,
389
- } | local_commit_name,
390
- )
391
- . collect ( )
392
- } ;
393
- ( created_commit_names, Default :: default ( ) )
401
+ let mut submitted_commit_names = BTreeSet :: new ( ) ;
402
+ let mut error_commits = BTreeSet :: new ( ) ;
403
+ for ( commit_oid, create_status) in create_statuses {
404
+ match create_status {
405
+ CreateStatus :: Created {
406
+ final_commit_oid : _, // currently not rendered
407
+ local_commit_name,
408
+ } => {
409
+ submitted_commit_names. insert ( local_commit_name) ;
410
+ }
411
+ // For now, treat `Skipped` the same as `Err` as it would be
412
+ // a lot of work to render it differently in the output, and
413
+ // we may want to rethink the data structures before doing
414
+ // that.
415
+ CreateStatus :: Skipped | CreateStatus :: Err => {
416
+ error_commits. insert ( commit_oid) ;
417
+ }
418
+ }
419
+ }
420
+ ( submitted_commit_names, Default :: default ( ) , error_commits)
421
+ }
394
422
} else {
395
- ( Default :: default ( ) , unsubmitted_commit_names)
423
+ (
424
+ Default :: default ( ) ,
425
+ unsubmitted_commit_names,
426
+ Default :: default ( ) ,
427
+ )
396
428
}
397
429
} ;
398
430
@@ -512,8 +544,33 @@ repository. To submit them, retry this operation with the --create option.",
512
544
if dry_run { "are" } else { "were" } ,
513
545
) ?;
514
546
}
547
+ if !create_error_commits. is_empty ( ) {
548
+ writeln ! (
549
+ effects. get_output_stream( ) ,
550
+ "Failed to create {}:" ,
551
+ Pluralize {
552
+ determiner: None ,
553
+ amount: create_error_commits. len( ) ,
554
+ unit: ( "commit" , "commits" )
555
+ } ,
556
+ ) ?;
557
+ for error_commit_oid in & create_error_commits {
558
+ let error_commit = repo. find_commit_or_fail ( * error_commit_oid) ?;
559
+ writeln ! (
560
+ effects. get_output_stream( ) ,
561
+ "{}" ,
562
+ effects
563
+ . get_glyphs( )
564
+ . render( error_commit. friendly_describe( effects. get_glyphs( ) ) ?) ?
565
+ ) ?;
566
+ }
567
+ }
515
568
516
- Ok ( Ok ( ( ) ) )
569
+ if !create_error_commits. is_empty ( ) {
570
+ Ok ( Err ( ExitCode ( 1 ) ) )
571
+ } else {
572
+ Ok ( Ok ( ( ) ) )
573
+ }
517
574
}
518
575
519
576
#[ instrument]
0 commit comments