@@ -24,14 +24,35 @@ struct ProductVersion {
24
24
version : String ,
25
25
}
26
26
27
+ /// Configuration that applies to all versions of a product, located at $ROOT/$product/stackable/patches/patchable.toml
28
+ ///
29
+ /// Must be created by hand (for now).
27
30
#[ derive( Deserialize , Serialize ) ]
31
+ #[ serde( rename_all = "kebab-case" ) ]
28
32
struct ProductConfig {
33
+ /// The upstream repository URL
29
34
upstream : String ,
30
- mirror : Option < String > ,
35
+
36
+ /// The repository that commits are mirrored to by `init --mirror`, typically `https://github.com/stackabletech/$product.git`
37
+ ///
38
+ /// This value is _not_ used by `checkout`, that uses [`ProductVersionConfig::mirror`] instead.
39
+ /// `init --mirror` copies this value into [`ProductVersionConfig::mirror`].
40
+ default_mirror : Option < String > ,
31
41
}
32
42
43
+ /// Configuration that applies to an individual version of a product, located at $ROOT/$product/stackable/patches/$version/patchable.toml
44
+ ///
45
+ /// Typically created by `patchable init`.
33
46
#[ derive( Deserialize , Serialize ) ]
34
47
struct ProductVersionConfig {
48
+ /// The mirror repository that this version can be fetched from
49
+ ///
50
+ /// Copied from [`ProductConfig::default_mirror`] by `init --mirror`.
51
+ mirror : Option < String > ,
52
+
53
+ /// The upstream base commit for this version
54
+ ///
55
+ /// Must be a commit ID, not a generic commitish (branch, tag, or anotherother ref), those are resolved by `init`.
35
56
#[ serde( with = "utils::oid_serde" ) ]
36
57
base : Oid ,
37
58
}
@@ -163,6 +184,9 @@ enum Cmd {
163
184
/// Refs (such as tags and branches) will be resolved to commit IDs.
164
185
#[ clap( long) ]
165
186
base : String ,
187
+
188
+ #[ clap( long) ]
189
+ mirror : bool ,
166
190
} ,
167
191
168
192
/// Shows the patch directory for a given product version
@@ -211,6 +235,10 @@ pub enum Error {
211
235
path : PathBuf ,
212
236
} ,
213
237
238
+ #[ snafu( display(
239
+ "mirroring requested, but default-mirror is not configured in product configuration"
240
+ ) ) ]
241
+ InitMirrorNotConfigured ,
214
242
#[ snafu( display( "failed to add temporary mirror remote for {url:?}" ) ) ]
215
243
AddMirrorRemote { source : git2:: Error , url : String } ,
216
244
#[ snafu( display( "failed to push commit {commit} (as {refspec}) to mirror {url:?}" ) ) ]
@@ -312,10 +340,10 @@ fn main() -> Result<()> {
312
340
let base_commit = repo:: resolve_and_fetch_commitish (
313
341
& product_repo,
314
342
& version_config. base . to_string ( ) ,
315
- product_config
316
- . mirror
317
- . as_deref ( )
318
- . unwrap_or ( & product_config . upstream ) ,
343
+ version_config . mirror . as_deref ( ) . unwrap_or_else ( || {
344
+ tracing :: warn! ( "this product version is not mirrored, re-init it with -- mirror before merging it" ) ;
345
+ & product_config . upstream
346
+ } ) ,
319
347
)
320
348
. context ( FetchBaseCommitSnafu ) ?;
321
349
let base_branch = ctx. base_branch ( ) ;
@@ -425,7 +453,7 @@ fn main() -> Result<()> {
425
453
) ;
426
454
}
427
455
428
- Cmd :: Init { pv, base } => {
456
+ Cmd :: Init { pv, base, mirror } => {
429
457
let ctx = ProductVersionContext {
430
458
pv,
431
459
images_repo_root,
@@ -449,7 +477,11 @@ fn main() -> Result<()> {
449
477
. context ( FetchBaseCommitSnafu ) ?;
450
478
tracing:: info!( ?base, base. commit = ?base_commit, "resolved base commit" ) ;
451
479
452
- if let Some ( mirror_url) = config. mirror {
480
+ let mirror_url = if mirror {
481
+ let mirror_url = config
482
+ . default_mirror
483
+ . context ( InitMirrorNotConfiguredSnafu ) ?;
484
+
453
485
// Add mirror remote
454
486
let mut mirror_remote =
455
487
product_repo
@@ -491,16 +523,25 @@ fn main() -> Result<()> {
491
523
mirror_remote
492
524
. push ( & [ & refspec] , Some ( & mut push_options) )
493
525
. context ( PushToMirrorSnafu {
494
- url : mirror_url,
526
+ url : & mirror_url,
495
527
refspec : & refspec,
496
528
commit : base_commit,
497
529
} ) ?;
498
530
499
531
tracing:: info!( "successfully pushed base ref to mirror" ) ;
532
+ Some ( mirror_url)
533
+ } else {
534
+ tracing:: warn!(
535
+ "this version is not mirrored, re-run with --mirror before merging into main"
536
+ ) ;
537
+ None
500
538
} ;
501
539
502
540
tracing:: info!( "saving version-level configuration" ) ;
503
- let config = ProductVersionConfig { base : base_commit } ;
541
+ let config = ProductVersionConfig {
542
+ base : base_commit,
543
+ mirror : mirror_url,
544
+ } ;
504
545
let config_path = ctx. version_config_path ( ) ;
505
546
if let Some ( config_dir) = config_path. parent ( ) {
506
547
std:: fs:: create_dir_all ( config_dir)
0 commit comments