-
Notifications
You must be signed in to change notification settings - Fork 379
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
config: also use XDG_CONFIG_HOME on MacOS #3466
base: main
Are you sure you want to change the base?
Conversation
8c1371c
to
1012f40
Compare
I don't think there's a line break, it's just Github's wrapping (check the line numbers on the left, the second line doesn't have one) |
036a3cc
to
85c4e91
Compare
19ecfcc
to
8f5a300
Compare
8f5a300
to
cb93ef5
Compare
Sooo I'm finding the current behavior of the config file handling really convoluted. As a result, I am making bigger changes than I thought I'd have to. Before I go too far (maybe it's too late already!), I'd like some feedback:
The commits themselves are kind of a mess (I want to keep more history with so many changes), so don't look at those yet. I'll clean them up before I merge anything. Thanks! |
I'm a little confused -- what are the changes (especially if the commits are too raw to be looked at)? Didn't we decide that we should allow all three locations? At least the commit descriptions seem to suggest the PR still forbids the |
I'm very confused here—from reading through the changes, it looks to me like despite the documentation and the commit message claiming that on macOS it will use XDG_CONFIG_DIR by default, it will actually use the system location by default. And, of course, it gives errors on multiple locations not on any specific location. (Edit: to be clear: it will read from the system location by default. Newly created files go to ~/.jjconfig.toml, it looks like.) Has the documentation (including commit message) not been updated to match the code changes? |
Yes, all three are allowed. I’ll clean it up later. Sounds like the most helpful thing would be to describe the behavior this introduces.
Yes, if there is no configuration yet and jj has to create it, it goes into $HOME. If more than one exists, it shows an error. If only one exists, it uses that. For Mac, that can be Application Support, $XDG_CONFIG_HOME, or $HOME/.jjconfig.toml.
Not yet. I’ll do that. |
I don't think it's desirable to put the new config in $HOME instead of the OS-specific location by default, basically for the reasons here #3466 (comment). The problem with the existing config implementation was that it didn't support XDG_CONFIG_HOME; adding that support is good, but we shouldn't break the use of AppData/Application Support for people who aren't using XDG. Which will be most people. |
I based that on a comment by |
8d58b3c
to
885eb2c
Compare
a47ffe2
to
80bfe37
Compare
ca05b21
to
8c57c05
Compare
I updated all the docs and changelog and cleaned up the commit. The behavior of some of the config commands creating config files if none exist is really separate from this, so it can be its own PR. |
2af6237
to
f748470
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I find this hard to review. It feels like it does many things at once. Is it possible to split it up something like the following?
- change from
dirs
toetcetera
- refactor tests
- refactor
config_path()
- add support for XDG_CONFIG_HOME
Sure! Those individual commits just won't work by themselves. I interpreted atomic as "need to build and work independently". |
Yes, that's correct.
Why not? |
Eh maybe I spoke too soon. Let me give it a shot. Thanks for the feedback :) |
1f2b361
to
8d7a13b
Compare
Alright, I hope this is easier to review. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, it was a lot easier to review now, but I'm still quite confused about the third commit.
d6d6dae
to
354cceb
Compare
62c3e72
to
7e2dac9
Compare
if handle_missing == HandleMissingConfig::Create && !path.exists() { | ||
create_config_file(&path)?; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Was this required because of some other changes? Or does this represent a change in behavior?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I combined the two functions into one, with an argument to create the file when needed. This is existing behavior.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perhaps, create_config_file()
can be moved to caller? It's generally easier to test if the function had no side effect.
Add a cfg to make etctera use the correct config directory on MacOS (which etcetera calls the `data_dir`).
Rename the test enum and `new_config_path` function to reflect that we never have just "new": we either look for existing or create new, or just look for existing.
* rename it to make clearer what it does * it returns an existing config or None if there isn't one * if told to create missing, it does so * as a result, `ConfigPath` is no longer necessary and removed
7e2dac9
to
6e79eb8
Compare
Want::New(want) => (None, Some(want)), | ||
Want::ExistingAndNew(want) => (Some(want), Some(want)), | ||
match self.want { | ||
Want::None => {} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Doesn't it remove the assertion for Want::None
case?
I don't remember the original expectation of these tests, but it doesn't make sense to run a test with no assertion.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for pointing that out, you're exactly right! The Want::None
test doesn't really make sense, because we need to either call the function that gives us a config path without creating it or with creating it.
What we want is a way to tell the test to run one or the other, and what to expect out of each. I'm changing it accordingly.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It has been a while, so I don't remember well, but..
It looks like Want::None used to declare both new_config_path and existing_config_path were expected to return None. In this PR test_config_path_home_dir_doesnt_create_new uses Want::None. What do you want to assert for that test? That both existing_config_path and new_or_existing_config_path return None, or something else?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I didn't understand the behavior too well before. In this case it should be None with existing_config_path
and Some("<path>")
with new_or_existing_config_path
.
if handle_missing == HandleMissingConfig::Create && !path.exists() { | ||
create_config_file(&path)?; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perhaps, create_config_file()
can be moved to caller? It's generally easier to test if the function had no side effect.
@@ -31,6 +31,8 @@ pub enum ConfigError { | |||
ConfigReadError(#[from] config::ConfigError), | |||
#[error("Both {0} and {1} exist. Please consolidate your configs in one of them.")] | |||
AmbiguousSource(PathBuf, PathBuf), | |||
#[error("Configs found in {0}, {1}, and {2}. Please consolidate your configs in one of them.")] | |||
AmbiguousSource3(PathBuf, PathBuf, PathBuf), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perhaps, these two error variants can be combined as AmbiguousSource(Vec<PathBuf>)
. The error message could be formatted as something like "Configs found in multiple locations: {}", .0.iter().map(|path| path.display()).join(", ")
(untested)
I'm going to take a break from this PR, it's been taking a lot more time than I expected. Someone else is free to take it over. |
This replaces the
dirs
crate with the more lightweight and flexibleetcetera
crate, which also lets us use XDG config on MacOS.Fixes #3434.
I'm not entirely sure how do prevent the line break in the doc table between "Application" and "Support" 😅 ...Checklist
If applicable:
CHANGELOG.md