-
Notifications
You must be signed in to change notification settings - Fork 773
config: add hostname-based conditional config scopes #7923
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
base: main
Are you sure you want to change the base?
Conversation
31e9c9d to
7d57a13
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.
Thanks. Can you include the issue number in commit description?
7d57a13 to
971eddb
Compare
This enables configuration to be conditionally applied based on the hostname set in `operation.hostname`. Users can now use `--when.hostnames = ["host-a", "host-b"]` in their config files to apply settings only on specific machines. Fixes: jj-vcs#6441
971eddb to
a8716d5
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.
Thanks.
| // Set hostname for --when.hostnames conditional config scopes. | ||
| if let Ok(hostname) = whoami::fallible::hostname() { | ||
| config_env.set_hostname(hostname); | ||
| } |
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.
nit: simply initialize it by ConfigEnv::from_environment() and delete setter. It doesn't make sense to update static value here.
| match (candidates, actual) { | ||
| (Some(candidates), actual) => candidates.iter().any(|candidate| actual == candidate), | ||
| (None, _) => true, // no constraints | ||
| } |
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.
nit: candidates.is_none_or(|candidates| ...). actual doesn't have to be a part of match.
This enables configuration to be conditionally applied based on the hostname set in
operation.hostname. Users can now use--when.hostnames = ["host-a", "host-b"]in their config files to apply settings only on specific machines. I think this would be a great addition as e.g. I have the same folder structure on my work and personal machine, so I can't use--when.repositoriesto distinguish config scopes.This is my first contribution to jj, so if I did something wrong let me know!
Checklist
If applicable:
CHANGELOG.mdREADME.md,docs/,demos/)cli/src/config-schema.json)