@@ -26,7 +26,7 @@ mod private
2626 /// Options for bumping the package version.
2727 pub bump : version:: BumpOptions ,
2828 /// Git options related to the package.
29- pub git_options : entity:: git:: GitOptions ,
29+ pub git_options : Option < entity:: git:: GitOptions > ,
3030 /// Options for publishing the package using Cargo.
3131 pub publish : cargo:: PublishOptions ,
3232 /// Indicates whether the process should be dry-run (no actual publishing).
@@ -44,6 +44,8 @@ mod private
4444 base_temp_dir : Option < path:: PathBuf > ,
4545 exclude_dev_dependencies : bool ,
4646 #[ former( default = true ) ]
47+ commit_changes : bool ,
48+ #[ former( default = true ) ]
4749 dry : bool ,
4850 }
4951
@@ -75,13 +77,16 @@ mod private
7577 dependencies : dependencies. clone ( ) ,
7678 dry : self . dry ,
7779 } ;
78- let git_options = entity :: git :: GitOptions
80+ let git_options = if self . commit_changes
7981 {
80- git_root : workspace_root,
81- items : dependencies. iter ( ) . chain ( [ & crate_dir ] ) . map ( | d | d. clone ( ) . absolute_path ( ) . join ( "Cargo.toml" ) ) . collect ( ) ,
82- message : format ! ( "{}-v{}" , self . package. name( ) . unwrap( ) , new_version ) ,
83- dry : self . dry ,
84- } ;
82+ Some ( entity:: git:: GitOptions
83+ {
84+ git_root : workspace_root,
85+ items : dependencies. iter ( ) . chain ( [ & crate_dir ] ) . map ( | d | d. clone ( ) . absolute_path ( ) . join ( "Cargo.toml" ) ) . collect ( ) ,
86+ message : format ! ( "{}-v{}" , self . package. name( ) . unwrap( ) , new_version ) ,
87+ dry : self . dry ,
88+ } )
89+ } else { None } ;
8590 let publish = cargo:: PublishOptions
8691 {
8792 path : crate_dir. clone ( ) . absolute_path ( ) . inner ( ) ,
@@ -126,7 +131,11 @@ mod private
126131
127132 /// Setting this option to true will temporarily remove development dependencies before executing the command, then restore them afterward.
128133 #[ allow( dead_code ) ] // former related
129- pub ( crate ) exclude_dev_dependencies : bool ,
134+ pub exclude_dev_dependencies : bool ,
135+
136+ /// Indicates whether changes should be committed.
137+ #[ former( default = true ) ]
138+ pub commit_changes : bool ,
130139
131140 /// `dry` - A boolean value indicating whether to do a dry run. If set to `true`, the application performs
132141 /// a simulated run without making any actual changes. If set to `false`, the operations are actually executed.
@@ -257,6 +266,10 @@ mod private
257266 {
258267 plan = plan. exclude_dev_dependencies ( * exclude_dev_dependencies )
259268 }
269+ if let Some ( commit_changes ) = & self . storage . commit_changes
270+ {
271+ plan = plan. commit_changes ( * commit_changes )
272+ }
260273 let plan = plan
261274 . channel ( channel )
262275 . package ( package )
@@ -373,45 +386,55 @@ mod private
373386 } = instruction;
374387 pack. dry = dry;
375388 bump. dry = dry;
376- git_options. dry = dry;
389+ git_options. as_mut ( ) . map ( | d | d . dry = dry ) ;
377390 publish. dry = dry;
378391
379392 report. get_info = Some ( cargo:: pack ( pack ) . err_with_report ( & report ) ? ) ;
380393 // aaa : redundant field? // aaa : removed
381394 let bump_report = version:: bump ( bump ) . err_with_report ( & report ) ?;
382395 report. bump = Some ( bump_report. clone ( ) ) ;
383- let git_root = git_options. git_root . clone ( ) ;
384- let git = match entity:: git:: perform_git_commit ( git_options )
396+
397+ let git_root = git_options. as_ref ( ) . map ( | g | g. git_root . clone ( ) ) ;
398+ if let Some ( git_options ) = git_options
385399 {
386- Ok ( git ) => git,
387- Err ( e ) =>
400+ let git = match entity:: git:: perform_git_commit ( git_options )
388401 {
389- version:: revert ( & bump_report )
390- . map_err ( | le | format_err ! ( "Base error:\n {}\n Revert error:\n {}" , e. to_string( ) . replace( '\n' , "\n \t " ) , le. to_string( ) . replace( '\n' , "\n \t " ) ) )
391- . err_with_report ( & report ) ?;
392- return Err ( ( report, e ) ) ;
393- }
394- } ;
395- report. add = git. add ;
396- report. commit = git. commit ;
402+ Ok ( git ) => git,
403+ Err ( e ) =>
404+ {
405+ version:: revert ( & bump_report )
406+ . map_err ( | le | format_err ! ( "Base error:\n {}\n Revert error:\n {}" , e. to_string( ) . replace( '\n' , "\n \t " ) , le. to_string( ) . replace( '\n' , "\n \t " ) ) )
407+ . err_with_report ( & report ) ?;
408+ return Err ( ( report, e ) ) ;
409+ }
410+ } ;
411+ report. add = git. add ;
412+ report. commit = git. commit ;
413+ }
397414 report. publish = match cargo:: publish ( publish )
398415 {
399416 Ok ( publish ) => Some ( publish ) ,
400417 Err ( e ) =>
401418 {
402- tool:: git:: reset ( git_root. as_ref ( ) , true , 1 , false )
403- . map_err
404- (
405- | le |
406- format_err ! ( "Base error:\n {}\n Revert error:\n {}" , e. to_string( ) . replace( '\n' , "\n \t " ) , le. to_string( ) . replace( '\n' , "\n \t " ) )
407- )
408- . err_with_report ( & report ) ?;
419+ if let Some ( git_root ) = git_root. as_ref ( )
420+ {
421+ tool:: git:: reset ( git_root. as_ref ( ) , true , 1 , false )
422+ . map_err
423+ (
424+ | le |
425+ format_err ! ( "Base error:\n {}\n Revert error:\n {}" , e. to_string( ) . replace( '\n' , "\n \t " ) , le. to_string( ) . replace( '\n' , "\n \t " ) )
426+ )
427+ . err_with_report ( & report ) ?;
428+ }
409429 return Err ( ( report, e ) ) ;
410430 }
411431 } ;
412432
413- let res = tool:: git:: push ( & git_root, dry ) . err_with_report ( & report ) ?;
414- report. push = Some ( res ) ;
433+ if let Some ( git_root ) = git_root. as_ref ( )
434+ {
435+ let res = tool:: git:: push ( & git_root, dry ) . err_with_report ( & report ) ?;
436+ report. push = Some ( res ) ;
437+ }
415438
416439 Ok ( report )
417440 }
0 commit comments