- 1: bcd366b54 ! 1: f4a73faf0 config: change how config paths are represented
@@ Metadata
## Commit message ##
config: change how config paths are represented
+ This change, from an enum to a struct, is a more accurate representation
+ of the actual way that a ConfigPath works; additionally, it lets us add
+ different information without modifying every single enumeration field.
+
+ The change to `config_paths()`, to return a `ConfigPath` instead of a
+ `Path`, is less interesting, but in my opinion results in slightly more
+ obvious code. It also makes the test code significantly easier.
+
## cli/src/commands/config/mod.rs ##
@@ cli/src/commands/config/mod.rs: mod path;
mod set;
- 2: 8a31c0b81 ! 2: f82fac4ea config: switch to etcetera from dirs
@@ cli/Cargo.toml: clap_complete_nushell = { workspace = true }
gix = { workspace = true, optional = true }
## cli/src/config.rs ##
+@@ cli/src/config.rs: impl UnresolvedConfigEnv {
+
+ // theoretically this should be an `if let Some(...) = ... && ..., but that
+ // isn't stable
+- let get_existing = |opt: Option<ConfigPath>| match opt {
+- Some(path) if path.exists() => Some(path),
+- _ => None,
+- };
+- if let Some(path) = get_existing(platform_config_dir) {
+- paths.push(path);
++ if let Some(path) = platform_config_dir {
++ if path.exists() {
++ paths.push(path);
++ }
+ }
+ paths
+ }
@@ cli/src/config.rs: pub struct ConfigEnv {
impl ConfigEnv {
/// Initializes configuration loader based on environment variables.
- 3: a4a790ea3 ! 3: 57b4cd795 config: default to XDG config files on macOS
@@ cli/src/config.rs: impl UnresolvedConfigEnv {
}
}
@@ cli/src/config.rs: impl UnresolvedConfigEnv {
- if let Some(path) = get_existing(platform_config_dir) {
paths.push(path);
}
+
+- // theoretically this should be an `if let Some(...) = ... && ..., but that
++ // theoretically these should be an `if let Some(...) = ... && ..., but that
+ // isn't stable
+ if let Some(path) = platform_config_dir {
+ if path.exists() {
+ paths.push(path);
+ }
+ }
+
-+ if let Some(path) = get_existing(legacy_platform_config_path) {
-+ paths.push(path);
++ if let Some(path) = legacy_platform_config_path {
++ if path.exists() {
++ paths.push(path);
++ }
+ }
-+ if let Some(path) = get_existing(legacy_platform_config_dir) {
-+ paths.push(path);
++ if let Some(path) = legacy_platform_config_dir {
++ if path.exists() {
++ paths.push(path);
++ }
+ }
+
paths
- 4: b6c814370 = 4: d1110e1b0 config: deprecate macOS legacy platform configs