Skip to content
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

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

ckoehler
Copy link
Contributor

@ckoehler ckoehler commented Apr 6, 2024

This replaces the dirs crate with the more lightweight and flexible etcetera 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:

  • I have updated CHANGELOG.md
  • I have updated the documentation (README.md, docs/, demos/)
  • I have updated the config schema (cli/src/config-schema.json)
  • I have added tests to cover my changes

@ckoehler ckoehler force-pushed the push-kkwmmvvtprtr branch 5 times, most recently from 8c1371c to 1012f40 Compare April 6, 2024 05:40
docs/config.md Outdated Show resolved Hide resolved
cli/src/config.rs Outdated Show resolved Hide resolved
@noahmayr
Copy link
Contributor

noahmayr commented Apr 6, 2024

I'm not entirely sure how do prevent the line break in the doc table between "Application" and "Support" 😅 ...

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)

@ckoehler ckoehler force-pushed the push-kkwmmvvtprtr branch 2 times, most recently from 036a3cc to 85c4e91 Compare April 6, 2024 17:12
cli/src/config.rs Outdated Show resolved Hide resolved
cli/src/config.rs Outdated Show resolved Hide resolved
@ckoehler ckoehler force-pushed the push-kkwmmvvtprtr branch 5 times, most recently from 19ecfcc to 8f5a300 Compare April 7, 2024 00:54
@ckoehler ckoehler changed the title config: use XDG_CONFIG_HOME on MacOS as a fallback config: use XDG_CONFIG_HOME on MacOS by default Apr 9, 2024
CHANGELOG.md Outdated Show resolved Hide resolved
@ckoehler ckoehler force-pushed the push-kkwmmvvtprtr branch from 8f5a300 to cb93ef5 Compare April 12, 2024 03:16
@ckoehler
Copy link
Contributor Author

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:

  • Is this okay? Too much?
  • Do the tests describe the wanted behaviors well?

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!

@ilyagr
Copy link
Contributor

ilyagr commented Apr 12, 2024

Before I go too far (maybe it's too late already!), I'd like some feedback:

  • Is this okay? Too much?
  • Do the tests describe the wanted behaviors well?

The commits themselves are kind of a mess

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 Application Support location.

@hypatian
Copy link

hypatian commented Apr 12, 2024

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?

@ckoehler
Copy link
Contributor Author

Didn't we decide that we should allow all three locations? At least the commit descriptions seem to suggest the PR still forbids the Application Support location.

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.

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.)

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.

Has the documentation (including commit message) not been updated to match the code changes?

Not yet. I’ll do that.

@gulbanana
Copy link
Contributor

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.

@ckoehler
Copy link
Contributor Author

ckoehler commented Apr 12, 2024

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 Martin @ilyagr on Discord (maybe I misunderstood), but it’s easy enough to change.

@ckoehler ckoehler force-pushed the push-kkwmmvvtprtr branch 2 times, most recently from 8d58b3c to 885eb2c Compare April 12, 2024 22:53
@ckoehler ckoehler changed the title config: use XDG_CONFIG_HOME on MacOS by default config: also use XDG_CONFIG_HOME on MacOS Apr 13, 2024
@ckoehler ckoehler force-pushed the push-kkwmmvvtprtr branch 2 times, most recently from a47ffe2 to 80bfe37 Compare April 15, 2024 01:43
@ckoehler ckoehler force-pushed the push-kkwmmvvtprtr branch 3 times, most recently from ca05b21 to 8c57c05 Compare April 15, 2024 02:11
@ckoehler
Copy link
Contributor Author

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.

@ckoehler ckoehler force-pushed the push-kkwmmvvtprtr branch 2 times, most recently from 2af6237 to f748470 Compare April 17, 2024 13:39
Copy link
Member

@martinvonz martinvonz left a 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 to etcetera
  • refactor tests
  • refactor config_path()
  • add support for XDG_CONFIG_HOME

@ckoehler
Copy link
Contributor Author

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` to `etcetera`

* 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".

@martinvonz
Copy link
Member

I interpreted atomic as "need to build and work independently".

Yes, that's correct.

Those individual commits just won't work by themselves.

Why not?

@ckoehler
Copy link
Contributor Author

Those individual commits just won't work by themselves.

Why not?

Eh maybe I spoke too soon. Let me give it a shot. Thanks for the feedback :)

@ckoehler ckoehler force-pushed the push-kkwmmvvtprtr branch 2 times, most recently from 1f2b361 to 8d7a13b Compare April 18, 2024 03:42
@ckoehler
Copy link
Contributor Author

Alright, I hope this is easier to review.

Copy link
Member

@martinvonz martinvonz left a 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.

cli/src/config.rs Show resolved Hide resolved
@ckoehler ckoehler force-pushed the push-kkwmmvvtprtr branch 2 times, most recently from d6d6dae to 354cceb Compare April 19, 2024 02:30
cli/src/config.rs Show resolved Hide resolved
cli/src/config.rs Outdated Show resolved Hide resolved
cli/src/config.rs Show resolved Hide resolved
cli/src/config.rs Outdated Show resolved Hide resolved
@ckoehler ckoehler force-pushed the push-kkwmmvvtprtr branch 2 times, most recently from 62c3e72 to 7e2dac9 Compare April 19, 2024 18:39
cli/src/config.rs Show resolved Hide resolved
Comment on lines +270 to +281
if handle_missing == HandleMissingConfig::Create && !path.exists() {
create_config_file(&path)?;
}
Copy link
Member

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?

Copy link
Contributor Author

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.

Copy link
Contributor

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.

cli/src/config.rs Outdated Show resolved Hide resolved
cli/src/config.rs Show resolved Hide resolved
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
@ckoehler ckoehler force-pushed the push-kkwmmvvtprtr branch from 7e2dac9 to 6e79eb8 Compare April 20, 2024 02:12
cli/src/config.rs Show resolved Hide resolved
Want::New(want) => (None, Some(want)),
Want::ExistingAndNew(want) => (Some(want), Some(want)),
match self.want {
Want::None => {}
Copy link
Contributor

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.

Copy link
Contributor Author

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.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like this was added in #1861, so maybe @qfel can clarify?

Copy link
Contributor

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?

Copy link
Contributor Author

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.

Comment on lines +270 to +281
if handle_missing == HandleMissingConfig::Create && !path.exists() {
create_config_file(&path)?;
}
Copy link
Contributor

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),
Copy link
Contributor

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)

@ckoehler
Copy link
Contributor Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

FR: look in $XDG_CONFIG_HOME for jj config on OSX
10 participants