Skip to content

Worktrunk is a CLI for Git worktree management, designed for parallel AI agent workflows

Confirm the write when wt config update --output names a file (#4053)

Maximilian Roos2991dadd4952
diff --git a/CHANGELOG.md b/CHANGELOG.md
index cfe042584..9ef864864 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -2,6 +2,10 @@
## Unreleased
+### Improved
+
+- **`wt config update --output <path>` confirms the write**: it now prints `✓ Wrote user config migration @ ~/migrated.toml`, so a command whose only effect is the file it wrote now says where that file is. Writing to stdout with `--output=-` stays silent, since the artifact is right there. ([#4053](https://github.com/max-sixty/worktrunk/pull/4053))
+
### Fixed
- **`wt merge` no longer runs `post-commit` in a worktree the user never chose**: the merge removes the worktree that hook is anchored on before the hook starts, so the pipeline was spawned into an emptied path. Where the worktree sat inside the repository, git discovery walked up from there and the hook's commands ran in the primary worktree; anywhere else they didn't run at all, and the only record was a log file nothing reads. The merge now prints `▲ Skipped post-commit: …` naming that worktree, and points at `pre-remove` for work that must finish there. `--no-remove`, merging on the target branch, `wt step commit`, and `wt step squash` still run it. ([#4049](https://github.com/max-sixty/worktrunk/pull/4049))
diff --git a/src/commands/config/update.rs b/src/commands/config/update.rs
index 34ba303c4..b5cf43cd6 100644
--- a/src/commands/config/update.rs
+++ b/src/commands/config/update.rs
@@ -106,51 +106,57 @@ pub fn handle_config_update(yes: bool, output: Option<PathBuf>) -> anyhow::Resul
}
/// Write the migration artifact to a path, or to stdout when the path is `-`.
+///
+/// The two destinations differ in what they can carry, so they run as separate
+/// paths rather than one path testing `-` at each step. Stdout labels and
+/// concatenates every candidate and needs no confirmation — the artifact is
+/// right there. A file takes exactly one migration, so the checks below and
+/// the confirmation can name the config it came from.
fn write_migrated_output(output: &Path, candidates: &[UpdateCandidate]) -> anyhow::Result<()> {
- let stdout = output == Path::new("-");
+ if output == Path::new("-") {
+ for candidate in candidates {
+ eprint!("{}", format_dropped_approvals_warning(candidate));
+ }
+ print!("{}", format_migrated_output(candidates));
+ return Ok(());
+ }
if candidates.is_empty() {
- if !stdout {
- eprintln!("{}", info_message("No deprecated settings found"));
- }
+ eprintln!("{}", info_message("No deprecated settings found"));
return Ok(());
}
- if !stdout && candidates.len() > 1 {
+ let [candidate] = candidates else {
bail!(cformat!(
"Cannot write <bold>user config</> and <bold>project config</> migrations to one file; use <bold>--output=-</> to inspect both or run <bold>wt config update</> to apply them in place"
));
- }
+ };
let output = resolve_input_path(output);
- if !stdout
- && let Some(candidate) = candidates
- .iter()
- .filter(|candidate| drops_approved_commands(candidate))
- .find(|candidate| paths_match(&output, &candidate.config_path))
- {
+ if drops_approved_commands(candidate) && paths_match(&output, &candidate.config_path) {
bail!(cformat!(
"Cannot overwrite <bold>{}</> with <bold>--output</>; run <bold>wt config update</> to apply the migration in place",
candidate.info.label().to_lowercase()
));
}
- for candidate in candidates {
- eprint!("{}", format_dropped_approvals_warning(candidate));
- }
+ eprint!("{}", format_dropped_approvals_warning(candidate));
let artifact = format_migrated_output(candidates);
- if stdout {
- print!("{artifact}");
- return Ok(());
- }
-
worktrunk::utils::write_atomically(&output, &artifact).with_context(|| {
format!(
"Failed to write output @ {}",
format_path_for_display(&output)
)
})?;
+ eprintln!(
+ "{}",
+ success_message(format!(
+ "Wrote {} migration @ {}",
+ candidate.info.label().to_lowercase(),
+ format_path_for_display(&output)
+ ))
+ );
Ok(())
}
diff --git a/tests/integration_tests/config_show.rs b/tests/integration_tests/config_show.rs
index 8cd22464f..be9851f62 100644
--- a/tests/integration_tests/config_show.rs
+++ b/tests/integration_tests/config_show.rs
@@ -3565,7 +3565,13 @@ fn test_config_update_output_destinations_emit_same_config(repo: TestRepo) {
.unwrap();
assert!(file_output.status.success());
assert!(file_output.stdout.is_empty());
- assert!(file_output.stderr.is_empty());
+ let stderr = String::from_utf8_lossy(&file_output.stderr)
+ .ansi_strip()
+ .into_owned();
+ assert!(
+ stderr.contains("Wrote user config migration @") && stderr.contains("migrated.toml"),
+ "a file destination confirms the write, unlike stdout; got: {stderr}"
+ );
assert_eq!(fs::read(destination).unwrap(), stdout_output.stdout);
assert_eq!(fs::read_to_string(config_path).unwrap(), original);
}