Skip to content

Commit bfe3552

Browse files
committed
config: add hostname-based conditional config scopes
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: #6441
1 parent 3899e17 commit bfe3552

File tree

5 files changed

+190
-0
lines changed

5 files changed

+190
-0
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,9 @@ to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
5656

5757
* Add support for `--when.workspaces` config scopes.
5858

59+
* Add support for `--when.hostnames` config scopes. This allows configuration to
60+
be conditionally applied based on the hostname set in `operation.hostname`.
61+
5962
* `jj bisect run` accepts the command and arguments to pass to the command
6063
directly as positional arguments, such as
6164
`jj bisect --range=..main -- cargo check --all-targets`.

cli/src/config-schema.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -950,6 +950,13 @@
950950
"type": "string"
951951
}
952952
},
953+
"hostnames": {
954+
"type": "array",
955+
"description": "List of hostnames to match the hostname",
956+
"items": {
957+
"type": "string"
958+
}
959+
},
953960
"workspaces": {
954961
"type": "array",
955962
"description": "List of paths to match the workspace path prefix",

cli/src/config.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -376,6 +376,7 @@ pub struct ConfigEnv {
376376
repo_config_path: Option<ConfigPath>,
377377
workspace_config_path: Option<ConfigPath>,
378378
command: Option<String>,
379+
hostname: Option<String>,
379380
}
380381

381382
impl ConfigEnv {
@@ -423,6 +424,7 @@ impl ConfigEnv {
423424
repo_config_path: None,
424425
workspace_config_path: None,
425426
command: None,
427+
hostname: whoami::fallible::hostname().ok(),
426428
}
427429
}
428430

@@ -602,6 +604,7 @@ impl ConfigEnv {
602604
repo_path: self.repo_path.as_deref(),
603605
workspace_path: self.workspace_path.as_deref(),
604606
command: self.command.as_deref(),
607+
hostname: self.hostname.as_deref().unwrap_or(""),
605608
};
606609
jj_lib::config::resolve(config.as_ref(), &context)
607610
}
@@ -1852,6 +1855,7 @@ mod tests {
18521855
repo_config_path: None,
18531856
workspace_config_path: None,
18541857
command: None,
1858+
hostname: None,
18551859
}
18561860
}
18571861
}

docs/config.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1883,6 +1883,12 @@ email = "[email protected]"
18831883
[--scope.user]
18841884
18851885

1886+
# override ui.pager on specific machines
1887+
[[--scope]]
1888+
--when.hostnames = ["work-laptop", "work-desktop"]
1889+
[--scope.ui]
1890+
pager = "delta"
1891+
18861892
# disable pagination for `jj status`, use `delta` for `jj diff` and `jj show`
18871893
[[--scope]]
18881894
--when.commands = ["status"]
@@ -1940,6 +1946,16 @@ wip = ["log", "-r", "work"]
19401946

19411947
Use `jj root` to see the workspace root directory.
19421948

1949+
* `--when.hostnames`: List of hostnames to match against the `operation.hostname`
1950+
config setting.
1951+
1952+
Hostnames are compared case-sensitively and must match exactly.
1953+
1954+
```toml
1955+
--when.hostnames = ["work-laptop"] # matches only "work-laptop"
1956+
--when.hostnames = ["home-desktop", "laptop"] # matches "home-desktop" OR "laptop"
1957+
```
1958+
19431959
* `--when.commands`: List of subcommands to match.
19441960

19451961
Subcommands are space-separated and matched by prefix.

0 commit comments

Comments
 (0)