- prepare for having one module per condition kind - prepare for pulling apart all-in-one tests into their own sub-tests
Unified · Split
| @@ -1,5 +1,3 @@ | ||
| 1 | −use bstr::BString; | |
| 2 | −use std::convert::TryFrom; | |
| 3 | 1 | use std::fs; |
| 4 | 2 | use std::path::{Path, PathBuf}; |
| 5 | 3 | |
| @@ -8,9 +6,10 @@ use crate::file::from_paths::escape_backslashes; · 2 unmodified lines | ||
| 8 | 6 | use git_config::file::from_paths; |
| 9 | 7 | use git_config::File; |
| 10 | 8 | use git_path::{create_symlink, CanonicalizedTempDir}; |
| 11 | −use git_ref::FullName; | |
| 12 | 9 | use tempfile::tempdir; |
| 13 | 10 | |
| 11 | +mod onbranch; | |
| 12 | + | |
| 14 | 13 | #[test] |
| 15 | 14 | fn include_and_includeif_correct_inclusion_order() { |
| 16 | 15 | let dir = tempdir().unwrap(); |
| @@ -117,108 +116,7 @@ fn pattern_is_current_dir() { · 100 unmodified lines | ||
| 117 | 116 | } |
| 118 | 117 | |
| 119 | 118 | #[test] |
| 120 | −fn onbranch_tests() { | |
| 121 | − let dir = tempdir().unwrap(); | |
| 122 | − let config_path = dir.path().join("a"); | |
| 123 | − let hierarchy_branch_path = dir.path().join("hierarchy_branch"); | |
| 124 | − let branch_path = dir.path().join("branch"); | |
| 125 | − let another_branch_path = dir.path().join("anohter_branch"); | |
| 126 | − fs::write( | |
| 127 | − branch_path.as_path(), | |
| 128 | − " | |
| 129 | −[core] | |
| 130 | − x = branch-override", | |
| 131 | − ) | |
| 132 | − .unwrap(); | |
| 133 | − | |
| 134 | − fs::write( | |
| 135 | − another_branch_path.as_path(), | |
| 136 | − " | |
| 137 | −[core] | |
| 138 | − z = another-branch-override", | |
| 139 | − ) | |
| 140 | − .unwrap(); | |
| 141 | − | |
| 142 | − fs::write( | |
| 143 | − hierarchy_branch_path.as_path(), | |
| 144 | − " | |
| 145 | −[core] | |
| 146 | − y = hierarchy-branch-override", | |
| 147 | − ) | |
| 148 | − .unwrap(); | |
| 149 | − | |
| 150 | − fs::write( | |
| 151 | − config_path.as_path(), | |
| 152 | − format!( | |
| 153 | − r#" | |
| 154 | −[core] | |
| 155 | − x = 1 | |
| 156 | − y = 1 | |
| 157 | − z = 1 | |
| 158 | −[includeIf "onbranch:foo*"] | |
| 159 | − path = {} | |
| 160 | −[includeIf "onbranch:br/"] | |
| 161 | − path = {} | |
| 162 | −[includeIf "onbranch:foo*"] | |
| 163 | − path = {}"#, | |
| 164 | − escape_backslashes(&branch_path), | |
| 165 | − escape_backslashes(&hierarchy_branch_path), | |
| 166 | − escape_backslashes(&another_branch_path), | |
| 167 | − ), | |
| 168 | − ) | |
| 169 | − .unwrap(); | |
| 170 | − | |
| 171 | − { | |
| 172 | − let branch_name = FullName::try_from(BString::from("refs/heads/foobar")).unwrap(); | |
| 173 | − let branch_name = branch_name.as_ref(); | |
| 174 | − let options = from_paths::Options { | |
| 175 | − branch_name: Some(branch_name), | |
| 176 | − ..Default::default() | |
| 177 | − }; | |
| 178 | − | |
| 179 | − let config = File::from_paths(Some(&config_path), options).unwrap(); | |
| 180 | − assert_eq!( | |
| 181 | − config.string("core", None, "x"), | |
| 182 | − Some(cow_str("branch-override")), | |
| 183 | − "branch name match" | |
| 184 | − ); | |
| 185 | − } | |
| 186 | − | |
| 187 | − { | |
| 188 | − let branch_name = FullName::try_from(BString::from("refs/heads/foo/bar")).unwrap(); | |
| 189 | − let branch_name = branch_name.as_ref(); | |
| 190 | − let options = from_paths::Options { | |
| 191 | − branch_name: Some(branch_name), | |
| 192 | − ..Default::default() | |
| 193 | − }; | |
| 194 | − | |
| 195 | − let config = File::from_paths(Some(&config_path), options).unwrap(); | |
| 196 | − assert_eq!( | |
| 197 | − config.string("core", None, "z"), | |
| 198 | − Some(cow_str("1")), | |
| 199 | − "branch name match" | |
| 200 | − ); | |
| 201 | − } | |
| 202 | − | |
| 203 | − { | |
| 204 | − let branch_name = FullName::try_from(BString::from("refs/heads/br/one")).unwrap(); | |
| 205 | − let branch_name = branch_name.as_ref(); | |
| 206 | − let options = from_paths::Options { | |
| 207 | − branch_name: Some(branch_name), | |
| 208 | − ..Default::default() | |
| 209 | − }; | |
| 210 | − | |
| 211 | − let config = File::from_paths(Some(&config_path), options).unwrap(); | |
| 212 | − assert_eq!( | |
| 213 | − config.string("core", None, "y"), | |
| 214 | − Some(cow_str("hierarchy-branch-override")), | |
| 215 | − "hierarchy branch name match" | |
| 216 | − ); | |
| 217 | − } | |
| 218 | −} | |
| 219 | − | |
| 220 | −#[test] | |
| 221 | −fn gitdir_tests() { | |
| 119 | +fn gitdir() { | |
| 222 | 120 | let dir = tempdir().unwrap(); |
| 223 | 121 | |
| 224 | 122 | let config_path = dir.path().join("a"); |
| @@ -0,0 +1,109 @@ | ||
| 1 | +use crate::file::cow_str; | |
| 2 | +use crate::file::from_paths::escape_backslashes; | |
| 3 | +use bstr::BString; | |
| 4 | +use git_config::file::from_paths; | |
| 5 | +use git_ref::FullName; | |
| 6 | +use std::convert::TryFrom; | |
| 7 | +use std::fs; | |
| 8 | +use tempfile::tempdir; | |
| 9 | + | |
| 10 | +#[test] | |
| 11 | +fn mixed() { | |
| 12 | + let dir = tempdir().unwrap(); | |
| 13 | + let config_path = dir.path().join("a"); | |
| 14 | + let hierarchy_branch_path = dir.path().join("hierarchy_branch"); | |
| 15 | + let branch_path = dir.path().join("branch"); | |
| 16 | + let another_branch_path = dir.path().join("another branch"); | |
| 17 | + fs::write( | |
| 18 | + branch_path.as_path(), | |
| 19 | + " | |
| 20 | +[core] | |
| 21 | +x = branch-override", | |
| 22 | + ) | |
| 23 | + .unwrap(); | |
| 24 | + | |
| 25 | + fs::write( | |
| 26 | + another_branch_path.as_path(), | |
| 27 | + " | |
| 28 | +[core] | |
| 29 | +z = another-branch-override", | |
| 30 | + ) | |
| 31 | + .unwrap(); | |
| 32 | + | |
| 33 | + fs::write( | |
| 34 | + hierarchy_branch_path.as_path(), | |
| 35 | + " | |
| 36 | +[core] | |
| 37 | +y = hierarchy-branch-override", | |
| 38 | + ) | |
| 39 | + .unwrap(); | |
| 40 | + | |
| 41 | + fs::write( | |
| 42 | + config_path.as_path(), | |
| 43 | + format!( | |
| 44 | + r#" | |
| 45 | +[core] | |
| 46 | +x = 1 | |
| 47 | +y = 1 | |
| 48 | +z = 1 | |
| 49 | +[includeIf "onbranch:foo*"] | |
| 50 | +path = {} | |
| 51 | +[includeIf "onbranch:br/"] | |
| 52 | +path = {} | |
| 53 | +[includeIf "onbranch:foo*"] | |
| 54 | +path = {}"#, | |
| 55 | + escape_backslashes(&branch_path), | |
| 56 | + escape_backslashes(&hierarchy_branch_path), | |
| 57 | + escape_backslashes(&another_branch_path), | |
| 58 | + ), | |
| 59 | + ) | |
| 60 | + .unwrap(); | |
| 61 | + | |
| 62 | + { | |
| 63 | + let branch_name = FullName::try_from(BString::from("refs/heads/foobar")).unwrap(); | |
| 64 | + let branch_name = branch_name.as_ref(); | |
| 65 | + let options = from_paths::Options { | |
| 66 | + branch_name: Some(branch_name), | |
| 67 | + ..Default::default() | |
| 68 | + }; | |
| 69 | + | |
| 70 | + let config = git_config::File::from_paths(Some(&config_path), options).unwrap(); | |
| 71 | + assert_eq!( | |
| 72 | + config.string("core", None, "x"), | |
| 73 | + Some(cow_str("branch-override")), | |
| 74 | + "branch name match" | |
| 75 | + ); | |
| 76 | + } | |
| 77 | + | |
| 78 | + { | |
| 79 | + let branch_name = FullName::try_from(BString::from("refs/heads/foo/bar")).unwrap(); | |
| 80 | + let branch_name = branch_name.as_ref(); | |
| 81 | + let options = from_paths::Options { | |
| 82 | + branch_name: Some(branch_name), | |
| 83 | + ..Default::default() | |
| 84 | + }; | |
| 85 | + | |
| 86 | + let config = git_config::File::from_paths(Some(&config_path), options).unwrap(); | |
| 87 | + assert_eq!( | |
| 88 | + config.string("core", None, "z"), | |
| 89 | + Some(cow_str("1")), | |
| 90 | + "branch name match" | |
| 91 | + ); | |
| 92 | + } | |
| 93 | + | |
| 94 | + { | |
| 95 | + let branch_name = FullName::try_from(BString::from("refs/heads/br/one")).unwrap(); | |
| 96 | + let branch_name = branch_name.as_ref(); | |
| 97 | + let options = from_paths::Options { | |
| 98 | + branch_name: Some(branch_name), | |
| 99 | + ..Default::default() | |
| 100 | + }; | |
| 101 | + | |
| 102 | + let config = git_config::File::from_paths(Some(&config_path), options).unwrap(); | |
| 103 | + assert_eq!( | |
| 104 | + config.string("core", None, "y"), | |
| 105 | + Some(cow_str("hierarchy-branch-override")), | |
| 106 | + "hierarchy branch name match" | |
| 107 | + ); | |
| 108 | + } | |
| 109 | +} | |