Unified · Split
| @@ -943,6 +943,21 @@ version = "1.2.0" · 942 unmodified lines | |||
| 943 | source = "registry+https://github.com/rust-lang/crates.io-index" | 943 | source = "registry+https://github.com/rust-lang/crates.io-index" |
| 944 | checksum = "2022715d62ab30faffd124d40b76f4134a550a87792276512b18d63272333394" | 944 | checksum = "2022715d62ab30faffd124d40b76f4134a550a87792276512b18d63272333394" |
| 945 | 945 | ||
| 946 | [[package]] | ||
| 947 | name = "futures" | ||
| 948 | version = "0.3.21" | ||
| 949 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 950 | checksum = "f73fe65f54d1e12b726f517d3e2135ca3125a437b6d998caf1962961f7172d9e" | ||
| 951 | dependencies = [ | ||
| 952 | "futures-channel", | ||
| 953 | "futures-core", | ||
| 954 | "futures-executor", | ||
| 955 | "futures-io", | ||
| 956 | "futures-sink", | ||
| 957 | "futures-task", | ||
| 958 | "futures-util", | ||
| 959 | ] | ||
| 960 | |||
| 946 | [[package]] | 961 | [[package]] |
| 947 | name = "futures-channel" | 962 | name = "futures-channel" |
| 948 | version = "0.3.21" | 963 | version = "0.3.21" |
| @@ -959,6 +974,17 @@ version = "0.3.21" · 10 unmodified lines | |||
| 959 | source = "registry+https://github.com/rust-lang/crates.io-index" | 974 | source = "registry+https://github.com/rust-lang/crates.io-index" |
| 960 | checksum = "0c09fd04b7e4073ac7156a9539b57a484a8ea920f79c7c675d05d289ab6110d3" | 975 | checksum = "0c09fd04b7e4073ac7156a9539b57a484a8ea920f79c7c675d05d289ab6110d3" |
| 961 | 976 | ||
| 977 | [[package]] | ||
| 978 | name = "futures-executor" | ||
| 979 | version = "0.3.21" | ||
| 980 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 981 | checksum = "9420b90cfa29e327d0429f19be13e7ddb68fa1cccb09d65e5706b8c7a749b8a6" | ||
| 982 | dependencies = [ | ||
| 983 | "futures-core", | ||
| 984 | "futures-task", | ||
| 985 | "futures-util", | ||
| 986 | ] | ||
| 987 | |||
| 962 | [[package]] | 988 | [[package]] |
| 963 | name = "futures-io" | 989 | name = "futures-io" |
| 964 | version = "0.3.21" | 990 | version = "0.3.21" |
| @@ -986,6 +1012,29 @@ version = "0.3.21" · 21 unmodified lines | |||
| 986 | source = "registry+https://github.com/rust-lang/crates.io-index" | 1012 | source = "registry+https://github.com/rust-lang/crates.io-index" |
| 987 | checksum = "21163e139fa306126e6eedaf49ecdb4588f939600f0b1e770f4205ee4b7fa868" | 1013 | checksum = "21163e139fa306126e6eedaf49ecdb4588f939600f0b1e770f4205ee4b7fa868" |
| 988 | 1014 | ||
| 1015 | [[package]] | ||
| 1016 | name = "futures-task" | ||
| 1017 | version = "0.3.21" | ||
| 1018 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 1019 | checksum = "57c66a976bf5909d801bbef33416c41372779507e7a6b3a5e25e4749c58f776a" | ||
| 1020 | |||
| 1021 | [[package]] | ||
| 1022 | name = "futures-util" | ||
| 1023 | version = "0.3.21" | ||
| 1024 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 1025 | checksum = "d8b7abd5d659d9b90c8cba917f6ec750a74e2dc23902ef9cd4cc8c8b22e6036a" | ||
| 1026 | dependencies = [ | ||
| 1027 | "futures-channel", | ||
| 1028 | "futures-core", | ||
| 1029 | "futures-io", | ||
| 1030 | "futures-sink", | ||
| 1031 | "futures-task", | ||
| 1032 | "memchr", | ||
| 1033 | "pin-project-lite", | ||
| 1034 | "pin-utils", | ||
| 1035 | "slab", | ||
| 1036 | ] | ||
| 1037 | |||
| 989 | [[package]] | 1038 | [[package]] |
| 990 | name = "generic-array" | 1039 | name = "generic-array" |
| 991 | version = "0.14.5" | 1040 | version = "0.14.5" |
| @@ -1100,7 +1149,7 @@ dependencies = [ · 108 unmodified lines | |||
| 1100 | "nom", | 1149 | "nom", |
| 1101 | "serde", | 1150 | "serde", |
| 1102 | "serde_derive", | 1151 | "serde_derive", |
| 1103 | "serial_test", | 1152 | "serial_test 0.7.0", |
| 1104 | "smallvec", | 1153 | "smallvec", |
| 1105 | "tempfile", | 1154 | "tempfile", |
| 1106 | "thiserror", | 1155 | "thiserror", |
| @@ -1467,6 +1516,7 @@ dependencies = [ · 360 unmodified lines | |||
| 1467 | "git-worktree", | 1516 | "git-worktree", |
| 1468 | "is_ci", | 1517 | "is_ci", |
| 1469 | "log", | 1518 | "log", |
| 1519 | "serial_test 0.8.0", | ||
| 1470 | "signal-hook", | 1520 | "signal-hook", |
| 1471 | "tempfile", | 1521 | "tempfile", |
| 1472 | "thiserror", | 1522 | "thiserror", |
| @@ -2587,7 +2637,20 @@ dependencies = [ · 1114 unmodified lines | |||
| 2587 | "lazy_static", | 2637 | "lazy_static", |
| 2588 | "log", | 2638 | "log", |
| 2589 | "parking_lot 0.12.1", | 2639 | "parking_lot 0.12.1", |
| 2590 | "serial_test_derive", | 2640 | "serial_test_derive 0.7.0", |
| 2641 | ] | ||
| 2642 | |||
| 2643 | [[package]] | ||
| 2644 | name = "serial_test" | ||
| 2645 | version = "0.8.0" | ||
| 2646 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 2647 | checksum = "7eec42e7232e5ca56aa59d63af3c7f991fe71ee6a3ddd2d3480834cf3902b007" | ||
| 2648 | dependencies = [ | ||
| 2649 | "futures", | ||
| 2650 | "lazy_static", | ||
| 2651 | "log", | ||
| 2652 | "parking_lot 0.12.1", | ||
| 2653 | "serial_test_derive 0.8.0", | ||
| 2591 | ] | 2654 | ] |
| 2592 | 2655 | ||
| 2593 | [[package]] | 2656 | [[package]] |
| @@ -2603,6 +2666,19 @@ dependencies = [ · 9 unmodified lines | |||
| 2603 | "syn", | 2666 | "syn", |
| 2604 | ] | 2667 | ] |
| 2605 | 2668 | ||
| 2669 | [[package]] | ||
| 2670 | name = "serial_test_derive" | ||
| 2671 | version = "0.8.0" | ||
| 2672 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 2673 | checksum = "f1b95bb2f4f624565e8fe8140c789af7e2082c0e0561b5a82a1b678baa9703dc" | ||
| 2674 | dependencies = [ | ||
| 2675 | "proc-macro-error", | ||
| 2676 | "proc-macro2", | ||
| 2677 | "quote", | ||
| 2678 | "rustversion", | ||
| 2679 | "syn", | ||
| 2680 | ] | ||
| 2681 | |||
| 2606 | [[package]] | 2682 | [[package]] |
| 2607 | name = "sha-1" | 2683 | name = "sha-1" |
| 2608 | version = "0.10.0" | 2684 | version = "0.10.0" |
| @@ -325,7 +325,7 @@ mod types { · 324 unmodified lines | |||
| 325 | pub conditional: conditional::Context<'a>, | 325 | pub conditional: conditional::Context<'a>, |
| 326 | } | 326 | } |
| 327 | 327 | ||
| 328 | impl Options<'_> { | 328 | impl<'a> Options<'a> { |
| 329 | /// Provide options to never follow include directives at all. | 329 | /// Provide options to never follow include directives at all. |
| 330 | pub fn no_includes() -> Self { | 330 | pub fn no_includes() -> Self { |
| 331 | Options { | 331 | Options { |
| @@ -335,9 +335,6 @@ mod types { · 3 unmodified lines | |||
| 335 | conditional: Default::default(), | 335 | conditional: Default::default(), |
| 336 | } | 336 | } |
| 337 | } | 337 | } |
| 338 | } | ||
| 339 | |||
| 340 | impl<'a> Options<'a> { | ||
| 341 | /// Provide options to follow includes like git does, provided the required `conditional` and `interpolate` contexts | 338 | /// Provide options to follow includes like git does, provided the required `conditional` and `interpolate` contexts |
| 342 | /// to support `gitdir` and `onbranch` based `includeIf` directives as well as standard `include.path` resolution. | 339 | /// to support `gitdir` and `onbranch` based `includeIf` directives as well as standard `include.path` resolution. |
| 343 | /// Note that the follow-mode is `git`-style, following at most 10 indirections while | 340 | /// Note that the follow-mode is `git`-style, following at most 10 indirections while |
| @@ -1,39 +1,14 @@ | |||
| 1 | use std::{borrow::Cow, env, fs}; | 1 | use std::{borrow::Cow, fs}; |
| 2 | 2 | ||
| 3 | use git_config::file::includes; | 3 | use git_config::file::includes; |
| 4 | use git_config::file::init; | 4 | use git_config::file::init; |
| 5 | use git_config::{file::init::from_env, File}; | 5 | use git_config::{file::init::from_env, File}; |
| 6 | use git_testtools::Env; | ||
| 6 | use serial_test::serial; | 7 | use serial_test::serial; |
| 7 | use tempfile::tempdir; | 8 | use tempfile::tempdir; |
| 8 | 9 | ||
| 9 | use crate::file::init::from_paths::escape_backslashes; | 10 | use crate::file::init::from_paths::escape_backslashes; |
| 10 | 11 | ||
| 11 | pub struct Env<'a> { | ||
| 12 | altered_vars: Vec<&'a str>, | ||
| 13 | } | ||
| 14 | |||
| 15 | impl<'a> Env<'a> { | ||
| 16 | pub(crate) fn new() -> Self { | ||
| 17 | Env { | ||
| 18 | altered_vars: Vec::new(), | ||
| 19 | } | ||
| 20 | } | ||
| 21 | |||
| 22 | pub(crate) fn set(mut self, var: &'a str, value: impl Into<String>) -> Self { | ||
| 23 | env::set_var(var, value.into()); | ||
| 24 | self.altered_vars.push(var); | ||
| 25 | self | ||
| 26 | } | ||
| 27 | } | ||
| 28 | |||
| 29 | impl<'a> Drop for Env<'a> { | ||
| 30 | fn drop(&mut self) { | ||
| 31 | for var in &self.altered_vars { | ||
| 32 | env::remove_var(var); | ||
| 33 | } | ||
| 34 | } | ||
| 35 | } | ||
| 36 | |||
| 37 | #[test] | 12 | #[test] |
| 38 | #[serial] | 13 | #[serial] |
| 39 | fn empty_without_relevant_environment() { | 14 | fn empty_without_relevant_environment() { |
| @@ -1,5 +1,6 @@ | |||
| 1 | mod util; | 1 | mod util; |
| 2 | 2 | ||
| 3 | use git_testtools::Env; | ||
| 3 | use serial_test::serial; | 4 | use serial_test::serial; |
| 4 | use util::{assert_section_value, Condition, GitEnv}; | 5 | use util::{assert_section_value, Condition, GitEnv}; |
| 5 | 6 | ||
| @@ -90,7 +91,7 @@ fn dot_slash_from_environment_causes_error() -> crate::Result { · 84 unmodified lines | |||
| 90 | let env = GitEnv::repo_name("worktree")?; | 91 | let env = GitEnv::repo_name("worktree")?; |
| 91 | 92 | ||
| 92 | { | 93 | { |
| 93 | let _environment = crate::file::init::from_env::Env::new() | 94 | let _environment = Env::new() |
| 94 | .set("GIT_CONFIG_COUNT", "1") | 95 | .set("GIT_CONFIG_COUNT", "1") |
| 95 | .set( | 96 | .set( |
| 96 | "GIT_CONFIG_KEY_0", | 97 | "GIT_CONFIG_KEY_0", |
| @@ -112,7 +113,7 @@ fn dot_slash_from_environment_causes_error() -> crate::Result { · 15 unmodified lines | |||
| 112 | 113 | ||
| 113 | let absolute_path = escape_backslashes(env.home_dir().join("include.config")); | 114 | let absolute_path = escape_backslashes(env.home_dir().join("include.config")); |
| 114 | { | 115 | { |
| 115 | let _environment = crate::file::init::from_env::Env::new() | 116 | let _environment = Env::new() |
| 116 | .set("GIT_CONFIG_COUNT", "1") | 117 | .set("GIT_CONFIG_COUNT", "1") |
| 117 | .set("GIT_CONFIG_KEY_0", "includeIf.gitdir:./worktree/.path") | 118 | .set("GIT_CONFIG_KEY_0", "includeIf.gitdir:./worktree/.path") |
| 118 | .set("GIT_CONFIG_VALUE_0", &absolute_path); | 119 | .set("GIT_CONFIG_VALUE_0", &absolute_path); |
| @@ -130,7 +131,7 @@ fn dot_slash_from_environment_causes_error() -> crate::Result { · 11 unmodified lines | |||
| 130 | } | 131 | } |
| 131 | 132 | ||
| 132 | { | 133 | { |
| 133 | let _environment = crate::file::init::from_env::Env::new() | 134 | let _environment = Env::new() |
| 134 | .set("GIT_CONFIG_COUNT", "1") | 135 | .set("GIT_CONFIG_COUNT", "1") |
| 135 | .set( | 136 | .set( |
| 136 | "GIT_CONFIG_KEY_0", | 137 | "GIT_CONFIG_KEY_0", |
| @@ -409,3 +409,29 @@ pub fn sleep_forever() -> ! { · 408 unmodified lines | |||
| 409 | std::thread::sleep(std::time::Duration::from_secs(u64::MAX)) | 409 | std::thread::sleep(std::time::Duration::from_secs(u64::MAX)) |
| 410 | } | 410 | } |
| 411 | } | 411 | } |
| 412 | |||
| 413 | pub struct Env<'a> { | ||
| 414 | altered_vars: Vec<&'a str>, | ||
| 415 | } | ||
| 416 | |||
| 417 | impl<'a> Env<'a> { | ||
| 418 | pub fn new() -> Self { | ||
| 419 | Env { | ||
| 420 | altered_vars: Vec::new(), | ||
| 421 | } | ||
| 422 | } | ||
| 423 | |||
| 424 | pub fn set(mut self, var: &'a str, value: impl Into<String>) -> Self { | ||
| 425 | std::env::set_var(var, value.into()); | ||
| 426 | self.altered_vars.push(var); | ||
| 427 | self | ||
| 428 | } | ||
| 429 | } | ||
| 430 | |||
| 431 | impl<'a> Drop for Env<'a> { | ||
| 432 | fn drop(&mut self) { | ||
| 433 | for var in &self.altered_vars { | ||
| 434 | std::env::remove_var(var); | ||
| 435 | } | ||
| 436 | } | ||
| 437 | } | ||