diff options
| author | Soispha Peetz <soispha@b-peetz.de> | 2026-11-11 19:09:16 +0100 |
|---|---|---|
| committer | Soispha Peetz <soispha@b-peetz.de> | 2026-11-14 18:35:52 +0100 |
| commit | e7b738c2b2ea0bae682b525639f302919934d9b3 (patch) | |
| tree | ee3493186200367257b4273f41b0051a77a8d21b | |
| parent | pkgs/rollup: Really sort the patches by number (diff) | |
| download | nixos-config-e7b738c2b2ea0bae682b525639f302919934d9b3.zip | |
pkgs/rollup: Support a `--dry-run` flag
That makes testing easier.
| -rw-r--r-- | pkgs/by-name/ro/rollup/src/main.rs | 42 |
1 files changed, 30 insertions, 12 deletions
diff --git a/pkgs/by-name/ro/rollup/src/main.rs b/pkgs/by-name/ro/rollup/src/main.rs index 29746e07..48bbc842 100644 --- a/pkgs/by-name/ro/rollup/src/main.rs +++ b/pkgs/by-name/ro/rollup/src/main.rs @@ -15,6 +15,10 @@ mod parse; #[derive(Parser)] struct Cli { + /// Don't actually do anything, just check' + #[arg(long, global = true)] + dry_run: bool, + #[command(subcommand)] subcommand: Cmd, } @@ -127,11 +131,9 @@ fn main() -> Result<()> { to, debug_parse, } => { - check_to(&to)?; - apply_patches(patch_files, to, debug_parse)? + apply_patches(patch_files, owner, debug_parse, args.dry_run)? } - Cmd::Create { tag } => { - create_patches(tag)?; + create_patches(tag, args.dry_run)?; } Cmd::CreateApply { tag, @@ -140,7 +142,8 @@ fn main() -> Result<()> { } => { check_to(&to)?; - let Some(patches_directory) = create_patches(tag)? else { + let Some(patches_directory) = create_patches(tag, args.dry_run)? + else { return Ok(()); }; let patch_files = { @@ -175,6 +178,7 @@ fn main() -> Result<()> { patch_files.into_iter().map(|s| s.unwrap()).collect(), to, debug_parse, + args.dry_run, )?; } } @@ -182,7 +186,7 @@ fn main() -> Result<()> { Ok(()) } -fn create_patches(tag: String) -> Result<Option<PathBuf>> { +fn create_patches(tag: &str, dry_run: bool) -> Result<Option<PathBuf>> { let current_dir = current_dir()?; let (stdout, _) = git!(in current_dir; "tag", "--contains", "HEAD", tag.as_str()); @@ -205,15 +209,25 @@ fn create_patches(tag: String) -> Result<Option<PathBuf>> { let tempdir = PathBuf::from(String::from_utf8(mktemp.stdout).unwrap().trim()); git!(in current_dir; "format-patch", format!("{}..", tag).as_str(), "-o", tempdir.display().to_string().as_str()); - git!(in current_dir; "tag", "--delete", tag.as_str()); - git!(in current_dir; "tag", "--annotate", tag.as_str(), "-m", ""); + + if dry_run { + eprintln!("Dry-run is on; Not actually moving patch tag `{tag}` forward.") + } else { + git!(in current_dir; "tag", "--delete", tag); + git!(in current_dir; "tag", "--annotate", tag, "-m", ""); + } println!("Patches have been generated here: `{}`", tempdir.display()); Ok(Some(tempdir)) } -fn apply_patches(patch_files: Vec<PathBuf>, to: PathBuf, debug_parse: bool) -> Result<()> { +fn apply_patches( + patch_files: Vec<PathBuf>, + to: PathBuf, + debug_parse: bool, + dry_run: bool, +) -> Result<()> { let mut patches = vec![]; for file in &patch_files { patches.push(parse::parse_file(file, debug_parse)?); @@ -302,9 +316,13 @@ fn apply_patches(patch_files: Vec<PathBuf>, to: PathBuf, debug_parse: bool) -> R ..patch.to_owned() }; - git!(@set_stdin_to filtered_patch; in to; "apply", "-", "--whitespace=nowarn"); - git!(in to; "add", "."); - git!(@set_stdin_to filtered_patch.commit_message; in to; "commit", "--file=-", format!("--date={}", filtered_patch.date).as_str(), "--quiet"); + if dry_run { + eprintln!("Dry-run is on; Not actually applying, adding and commiting"); + } else { + git!(@set_stdin_to filtered_patch; in to; "apply", "-", "--whitespace=nowarn"); + git!(in to; "add", "."); + git!(@set_stdin_to filtered_patch.commit_message; in to; "commit", "--file=-", format!("--date={}", filtered_patch.date).as_str(), "--quiet"); + } } Ok(()) |
