Skip to content

Commit 23bbba4

Browse files
committed
feat: commit_changes flag for .publish. Default value is true
1 parent 72c89a0 commit 23bbba4

File tree

4 files changed

+66
-31
lines changed

4 files changed

+66
-31
lines changed

module/move/willbe/src/action/publish.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,7 @@ mod private
121121
patterns : Vec< String >,
122122
channel : channel::Channel,
123123
exclude_dev_dependencies : bool,
124+
commit_changes : bool,
124125
dry : bool,
125126
temp : bool
126127
)
@@ -236,6 +237,7 @@ mod private
236237
.workspace_dir( CrateDir::try_from( workspace_root_dir ).unwrap() )
237238
.option_base_temp_dir( dir.clone() )
238239
.exclude_dev_dependencies( exclude_dev_dependencies )
240+
.commit_changes( commit_changes )
239241
.dry( dry )
240242
.roots( roots )
241243
.packages( queue )

module/move/willbe/src/command/mod.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,11 @@ mod private
3030
.kind( Type::Bool )
3131
.optional( true )
3232
.end()
33+
.property( "commit_changes" )
34+
.hint( "Indicates whether changes should be committed. Default is `true`." )
35+
.kind( Type::Bool )
36+
.optional( true )
37+
.end()
3338
.property( "dry" )
3439
.hint( "Enables 'dry run'. Does not publish, only simulates. Default is `true`." )
3540
.kind( Type::Bool )

module/move/willbe/src/command/publish.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ mod private
1818
#[ former( default = true ) ]
1919
exclude_dev_dependencies : bool,
2020
#[ former( default = true ) ]
21+
commit_changes : bool,
22+
#[ former( default = true ) ]
2123
dry : bool,
2224
#[ former( default = true ) ]
2325
temp : bool,
@@ -55,10 +57,11 @@ mod private
5557
{
5658
channel,
5759
exclude_dev_dependencies,
60+
commit_changes,
5861
dry,
5962
temp
6063
} = o.props.try_into()?;
61-
let plan = action::publish_plan( patterns, channel, exclude_dev_dependencies, dry, temp )
64+
let plan = action::publish_plan( patterns, channel, exclude_dev_dependencies, commit_changes, dry, temp )
6265
.context( "Failed to plan the publication process" )?;
6366

6467
let mut formatted_plan = String::new();
@@ -116,6 +119,8 @@ mod private
116119
this = if let Some( v ) = value
117120
.get_owned( "exclude_dev_dependencies" ) { this.exclude_dev_dependencies::< bool >( v ) } else { this };
118121
this = if let Some( v ) = value
122+
.get_owned( "commit_changes" ) { this.commit_changes::< bool >( v ) } else { this };
123+
this = if let Some( v ) = value
119124
.get_owned( "dry" ) { this.dry::< bool >( v ) } else { this };
120125
this = if let Some( v ) = value
121126
.get_owned( "temp" ) { this.temp::< bool >( v ) } else { this };

module/move/willbe/src/entity/publish.rs

Lines changed: 53 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -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{}\nRevert 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{}\nRevert 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{}\nRevert 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{}\nRevert 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

Comments
 (0)