Skip to content

Commit

Permalink
config: also check XDG_CONFIG_HOME on MacOS
Browse files Browse the repository at this point in the history
This replaces the `dirs` crate with the more lightweight and flexible
`etcetera` crate, which also lets us use XDG config on MacOS. Will search in
$HOME, the platform-specific dir, and $XDG_CONFIG_HOME (if different from the
platform-specific dir, like on MacOS).

I changed some tests to more accurately describe the desired behavior and added
a couple of new ones.

Fixes #3434
  • Loading branch information
ckoehler committed Apr 15, 2024
1 parent 0ef25bb commit 436d224
Show file tree
Hide file tree
Showing 8 changed files with 210 additions and 182 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

* The default template alias `builtin_log_root(change_id: ChangeId, commit_id: CommitId)` was replaced by `format_root_commit(root: Commit)`.

* On MacOS, jj will now also look for its config in `$XDG_CONFIG_HOME` in addition to `~/Library/Application Support/jj/` and `$HOME/.jjconfig.toml`

### New features

* The list of conflicted paths is printed whenever the working copy changes.
Expand Down
62 changes: 12 additions & 50 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,9 @@ config = { version = "0.13.4", default-features = false, features = ["toml"] }
criterion = "0.5.1"
crossterm = { version = "0.27", default-features = false }
digest = "0.10.7"
dirs = "5.0.1"
either = "1.10.0"
esl01-renderdag = "0.3.0"
etcetera = "0.8.0"
futures = "0.3.30"
git2 = "0.18.3"
gix = { version = "0.61.0", default-features = false, features = [
Expand Down
2 changes: 1 addition & 1 deletion cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ clap_mangen = { workspace = true }
config = { workspace = true }
criterion = { workspace = true, optional = true }
crossterm = { workspace = true }
dirs = { workspace = true }
esl01-renderdag = { workspace = true }
etcetera = { workspace = true }
futures = { workspace = true }
git2 = { workspace = true }
gix = { workspace = true }
Expand Down
7 changes: 3 additions & 4 deletions cli/src/cli_util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ use crate::command_error::{
};
use crate::commit_templater::{CommitTemplateLanguage, CommitTemplateLanguageExtension};
use crate::config::{
new_config_path, AnnotatedValue, CommandNameAndArgs, ConfigSource, LayeredConfigs,
new_or_existing_config_path, AnnotatedValue, CommandNameAndArgs, ConfigSource, LayeredConfigs,
};
use crate::formatter::{FormatRecorder, Formatter, PlainTextFormatter};
use crate::git_util::{
Expand Down Expand Up @@ -1984,9 +1984,8 @@ pub fn get_new_config_file_path(
) -> Result<PathBuf, CommandError> {
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::User => new_or_existing_config_path()?
.ok_or_else(|| user_error("No repo config path found to edit"))?,
ConfigSource::Repo => command.workspace_loader()?.repo_path().join("config.toml"),
_ => {
return Err(user_error(format!(
Expand Down
Loading

0 comments on commit 436d224

Please sign in to comment.