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

jj should have a thing like git config ... #531

Closed
jsoref opened this issue Sep 9, 2022 · 21 comments · Fixed by #917 or #1312
Closed

jj should have a thing like git config ... #531

jsoref opened this issue Sep 9, 2022 · 21 comments · Fixed by #917 or #1312
Assignees

Comments

@jsoref
Copy link
Contributor

jsoref commented Sep 9, 2022

Description

Learning to edit toml isn't going to be top of anyone's minds when they start using jj. A jj config would mean they don't need to

Steps to Reproduce the Problem

  1. See jj should walk users through setting their email/name #530

Expected Behavior

jj config user.name '...'
jj config user.email '...'

Actual Behavior

% jj
Config error: invalid TOML value, did you mean to use a quoted string? at line 2 column 8 in ../../../.jjconfig.toml
% jj
Config error: expected newline, found a plus at line 3 column 16 in ../../../.jjconfig.toml

Specifications

  • Platform:
  • Version: 0.4.0
@dbarnett
Copy link
Contributor

jj help config would also be a nice place to point to any reference docs about what options the config actually supports. See also #879 on reference docs.

@dbarnett
Copy link
Contributor

I'd like to attempt this one. Seems like a good place to start to get familiar with the structure of the code before trying for some others I'm interested to tackle.

@martinvonz
Copy link
Member

Great! Yes, this should be a very good starter task. You probably don't even need any pointers because it's probably just a matter of updating the command arguments (DescribeArgs) and implementation cmd_describe().

@dbarnett
Copy link
Contributor

You're using describe as just an example, right? Or are you saying config relates to the describe command in particular?

@martinvonz
Copy link
Member

Oops, I thought you (and I) were commenting on #328 :)

This one is a bit harder than #328, but probably still a good starter task. I hope there's some good crate out there for parsing TOML and writing it back, while preserving comments etc. Assuming there is, this is probably not too hard.

dbarnett added a commit to dbarnett/jj that referenced this issue Dec 19, 2022
@dbarnett
Copy link
Contributor

I hope there's some good crate out there for parsing TOML and writing it back, while preserving comments etc.

Yeah, I'll need to figure out all of that to support "set", but I just did "get" and "list" for now which are simpler.

dbarnett added a commit to dbarnett/jj that referenced this issue Dec 19, 2022
dbarnett added a commit to dbarnett/jj that referenced this issue Dec 19, 2022
dbarnett added a commit to dbarnett/jj that referenced this issue Dec 21, 2022
dbarnett added a commit to dbarnett/jj that referenced this issue Dec 26, 2022
dbarnett added a commit to dbarnett/jj that referenced this issue Dec 26, 2022
dbarnett added a commit to dbarnett/jj that referenced this issue Dec 27, 2022
dbarnett added a commit to dbarnett/jj that referenced this issue Dec 27, 2022
dbarnett added a commit to dbarnett/jj that referenced this issue Dec 27, 2022
dbarnett added a commit to dbarnett/jj that referenced this issue Dec 27, 2022
dbarnett added a commit to dbarnett/jj that referenced this issue Dec 27, 2022
dbarnett added a commit that referenced this issue Dec 27, 2022
@martinvonz
Copy link
Member

This issue was about editing configs via jj config, so it should still be open

@martinvonz martinvonz reopened this Dec 28, 2022
@dbarnett
Copy link
Contributor

Oh yes, agreed. I think GitHub's detection was a little over-eager where I said "partially fixes".

@dbarnett dbarnett self-assigned this Jan 4, 2023
dbarnett added a commit that referenced this issue Jan 11, 2023
Part of #531 to define the overall `config` command.
dbarnett added a commit that referenced this issue Jan 11, 2023
Part of #531 to define the overall `config` command.
dbarnett added a commit that referenced this issue Jan 11, 2023
Part of #531 to define the overall `config` command.
dbarnett added a commit that referenced this issue Jan 12, 2023
Part of #531 to define the overall `config` command.
dbarnett added a commit that referenced this issue Jan 12, 2023
Part of #531 to define the overall `config` command.
dbarnett added a commit that referenced this issue Jan 12, 2023
Part of #531 to define the overall `config` command.
dbarnett added a commit that referenced this issue Jan 12, 2023
Part of #531 to define the overall `config` command.
dbarnett added a commit that referenced this issue Jan 12, 2023
Part of #531 to define the overall `config` command.
@dbarnett
Copy link
Contributor

Side comment: That GitHub spam from all the force-pushed commits is really annoying. Is that WAI or is there a better way I should be pushing commits?

@arxanas
Copy link
Contributor

arxanas commented Jan 13, 2023

It's really annoying, so I personally try to keep the issue references in the pull request instead of the commit (which is unfortunate for other reasons)...

@dbarnett
Copy link
Contributor

dbarnett commented Jan 13, 2023

Planning to add a config set command like the FR originally requested and then we can call this Fixed and follow up on other improvements separately.

A few other follow-ups I'm planning to work on:

  • Get config list supporting --user and --repo filters by taking advantage of LayeredConfigs (and improve the output ordering)
  • Exclude the built-in defaults from the config list output (maybe with a --show-defaults option to manually enable them)

@dbarnett
Copy link
Contributor

K, I'm forking these improvement ideas for config list into #1047. For this FR we'll focus on adding the remaining config set subcommand.

@dbarnett
Copy link
Contributor

Any suggestion for the case where user config path is a directory? Some cases are straightforward, but when there are multiple files in the config dir precedence could get tricky.

Ideal could be:

  • Empty dir => create a "config.toml" file
  • Dir contains a single file => write to that file
  • Dir contains multiple files => write config to highest precedence file

I'd like to not overthink this case, but unfortunately I can't really have a test for config set --user without doing something about that case (since the tests use a config directory with lots of files).

@jsoref
Copy link
Contributor Author

jsoref commented Feb 20, 2023

Your proposal is reasonable...

@yuja
Copy link
Contributor

yuja commented Feb 21, 2023

I'd like to not overthink this case, but unfortunately I can't really have a test for config set --user without doing something about that case (since the tests use a config directory with lots of files).

I think it's also fine to error out if the config path is a directory.

In tests, we can override the path with .jj_cmd(..).env("JJ_CONFIG", ..).

@dbarnett
Copy link
Contributor

Oh, true. Didn't think to override it to a file path.

One other gotcha will be inferring the value types. Easiest is to assume every value is a string, and maybe have an explicit arg for specifying other value types. Should also be possible to infer some types based on the config schema, but that's going to be a little complex to implement and will never be foolproof.

@martinvonz
Copy link
Member

One other gotcha will be inferring the value types.

We have the global --config-toml, so should we have --set-toml? I think we should use toml syntax anyway. Btw, I'm very open to dropping the -toml part of --config-toml and say that it's implied. Should jj config --set foo.bar baz be an error because baz is not a valid toml value? Or do we interpret invalid toml as string?

@dbarnett
Copy link
Contributor

I think requiring toml syntax will be awkward. Just to set a simple string value you'd need two layers of quoting like set user.email '"[email protected]"'. 99% of the usefulness would be setting a string, number, or bool value. For setting arrays, tables, etc you'd probably want to use edit instead of set anyway. We could mostly infer that if it doesn't look like a number or boolean it's a string value, except if you did want a literal string value like "1.1" or "true" it gets a little weird.

Probably time to go check how mercurial and git handle these cases...

@dbarnett
Copy link
Contributor

Probably time to go check how mercurial and git handle these cases...

Oh, mercurial doesn't have any direct set command AFAICT, just commands to get and edit. git has a --type arg, but also looks like it doesn't need to be as type-aware since the cfg format isn't so explicit about quoting etc.

Considering the whole command is a convenience helper, I'd vote to keep it pretty simplistic and infer number/boolean/string with a --type=number|bool|string option to force the type.

@yuja
Copy link
Contributor

yuja commented Feb 26, 2023

I'd vote to keep it pretty simplistic and infer number/boolean/string with a --type=number|bool|string option to force the type.

config::Config isn't strict about underlying value types, so I think it's okay to take everything as a string. If we add a proper support for config schema, value type can be determined by config key.

@dbarnett
Copy link
Contributor

dbarnett commented Mar 1, 2023

Okay! It's certainly not perfect, but we have config subcommands list/set/edit and you can configure email/name as requested in the FR, like: jj config set --user user.email "[email protected]".

We might still want to reference that new command in the hint for new users to set up name/email at https://github.com/martinvonz/jj/blob/99cb0ba7c5cef0d8b53dbfe64a168764e50a4dc2/src/cli_util.rs#L1045, though.

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