diff --git a/CHANGELOG.md b/CHANGELOG.md index 8db6d9580ae..fe6ae63cc06 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -65,6 +65,8 @@ to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). * New `diff_contains()` revset function can be used to search diffs. +* When reconfiguring the author that the working copy won't be updated + ### Fixed bugs * `jj diff --git` no longer shows the contents of binary files. diff --git a/cli/src/commands/config.rs b/cli/src/commands/config.rs index 4c33a0021d8..34af113c33b 100644 --- a/cli/src/commands/config.rs +++ b/cli/src/commands/config.rs @@ -14,9 +14,10 @@ use std::io::Write; +use jj_lib::repo::Repo; use tracing::instrument; -use crate::cli_util::{get_new_config_file_path, run_ui_editor, CommandHelper}; +use crate::cli_util::{get_new_config_file_path, run_ui_editor, short_change_hash, CommandHelper}; use crate::command_error::{config_error, user_error, CommandError}; use crate::config::{ to_toml_value, write_config_value_to_file, AnnotatedValue, ConfigNamePathBuf, ConfigSource, @@ -285,7 +286,7 @@ pub(crate) fn cmd_config_get( #[instrument(skip_all)] pub(crate) fn cmd_config_set( - _ui: &mut Ui, + ui: &mut Ui, command: &CommandHelper, args: &ConfigSetArgs, ) -> Result<(), CommandError> { @@ -296,9 +297,56 @@ pub(crate) fn cmd_config_set( path = config_path.display() ))); } + + // If the user is trying to change the author config, we should warn them that + // it won't affect the working copy author + if args.name == ConfigNamePathBuf::from_iter(vec!["user", "name"]) { + let config = command.settings().config(); + let user_name: String = config.get("user.name")?; + + // only warn if the author is actually changing + if user_name != args.value { + let user_email: String = config.get("user.email")?; + warn_wc_author(&user_name, &user_email, command, ui)? + } + } else if args.name == ConfigNamePathBuf::from_iter(vec!["user", "email"]) { + let config = command.settings().config(); + let user_email: String = config.get("user.email")?; + + // only warn if the author is actually changing + if user_email != args.value { + let user_name: String = config.get("user.name")?; + warn_wc_author(&user_name, &user_email, command, ui)? + } + } write_config_value_to_file(&args.name, &args.value, &config_path) } +fn warn_wc_author( + user_name: &str, + user_email: &str, + command: &CommandHelper, + ui: &mut Ui, +) -> Result<(), CommandError> { + let helper = command.workspace_helper(ui)?; + let repo = helper.repo(); + let maybe_wc_commit = helper + .get_wc_commit_id() + .map(|id| repo.store().get_commit(id)) + .transpose()?; + + let change_hash = match maybe_wc_commit { + Some(commit) => format!("{} ", &short_change_hash(commit.change_id())[..8]), /* extra space for formatting */ + None => String::from(""), + }; + Ok(writeln!( + ui.warning_default(), + "This setting will only impact future commits.\nThe author of the working copy \ + {change_hash}will stay \"{user_name} <{user_email}>\". \nTo change it, use \"jj describe \ + --reset-author --no-edit\"" + )?) +} + #[instrument(skip_all)] pub(crate) fn cmd_config_edit( _ui: &mut Ui,