Skip to content

Conversation

@kaffarell
Copy link

@kaffarell kaffarell commented Oct 31, 2025

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.repositories to distinguish config scopes.

This is my first contribution to jj, so if I did something wrong let me know!

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/updated tests to cover my changes

@kaffarell kaffarell requested a review from a team as a code owner October 31, 2025 21:05
Copy link
Contributor

@yuja yuja left a 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?

#6441

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
@kaffarell kaffarell requested a review from yuja November 2, 2025 21:03
Copy link
Contributor

@yuja yuja left a comment

Choose a reason for hiding this comment

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

Thanks.

Comment on lines +3919 to +3922
// Set hostname for --when.hostnames conditional config scopes.
if let Ok(hostname) = whoami::fallible::hostname() {
config_env.set_hostname(hostname);
}
Copy link
Contributor

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.

Comment on lines +146 to +149
match (candidates, actual) {
(Some(candidates), actual) => candidates.iter().any(|candidate| actual == candidate),
(None, _) => true, // no constraints
}
Copy link
Contributor

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.

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.

2 participants