From a8b02de5c3bdf71b135809bdbf761183abd7b8d2 Mon Sep 17 00:00:00 2001 From: Piotr Kufel Date: Sat, 12 Aug 2023 17:38:46 -0700 Subject: [PATCH] Allow editing user-specific config file outside of a repo This addresses #2054. --- CHANGELOG.md | 2 ++ cli/src/cli_util.rs | 4 ++-- cli/src/commands/mod.rs | 10 ++-------- 3 files changed, 6 insertions(+), 10 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 66d6ee9e1..ab1bd4757 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -65,6 +65,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Fixed bugs +* `jj config set --user` and `jj config edit --user` can now be used outside of any repository. + * SSH authentication could hang when ssh-agent couldn't be reached [#1970](https://github.com/martinvonz/jj/issues/1970) diff --git a/cli/src/cli_util.rs b/cli/src/cli_util.rs index 7f7746903..6672db662 100644 --- a/cli/src/cli_util.rs +++ b/cli/src/cli_util.rs @@ -2137,14 +2137,14 @@ pub fn write_config_value_to_file( pub fn get_new_config_file_path( config_source: &ConfigSource, - workspace_loader: &WorkspaceLoader, + command: &CommandHelper, ) -> Result { let edit_path = match config_source { // TODO(#531): Special-case for editors that can't handle viewing directories? ConfigSource::User => { new_config_path()?.ok_or_else(|| user_error("No repo config path found to edit"))? } - ConfigSource::Repo => workspace_loader.repo_path().join("config.toml"), + ConfigSource::Repo => command.workspace_loader()?.repo_path().join("config.toml"), _ => { return Err(user_error(format!( "Can't get path for config source {config_source:?}" diff --git a/cli/src/commands/mod.rs b/cli/src/commands/mod.rs index d48438a35..eac98dfce 100644 --- a/cli/src/commands/mod.rs +++ b/cli/src/commands/mod.rs @@ -1259,10 +1259,7 @@ fn cmd_config_set( command: &CommandHelper, args: &ConfigSetArgs, ) -> Result<(), CommandError> { - let config_path = get_new_config_file_path( - &args.config_args.get_source_kind(), - command.workspace_loader()?, - )?; + let config_path = get_new_config_file_path(&args.config_args.get_source_kind(), command)?; if config_path.is_dir() { return Err(user_error(format!( "Can't set config in path {path} (dirs not supported)", @@ -1278,10 +1275,7 @@ fn cmd_config_edit( command: &CommandHelper, args: &ConfigEditArgs, ) -> Result<(), CommandError> { - let config_path = get_new_config_file_path( - &args.config_args.get_source_kind(), - command.workspace_loader()?, - )?; + let config_path = get_new_config_file_path(&args.config_args.get_source_kind(), command)?; run_ui_editor(command.settings(), &config_path) }