You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
let(version_str, upgrade_hint) = match raw.split_once(';'){
1131
-
Some((version, hint)) => {
1132
-
let trimmed_hint = hint.trim();
1133
-
if trimmed_hint.is_empty(){
1134
-
(version,None)
1135
-
}else{
1136
-
(version,Some(trimmed_hint))
1137
-
}
1138
-
}
1139
-
None => (raw.as_str(),None),
1140
-
};
1141
-
let version_str = version_str.trim();
1142
-
if version_str.is_empty(){
1129
+
let s = String::deserialize(deserializer)?;
1130
+
if s.is_empty(){
1143
1131
returnOk(None);
1144
1132
}
1145
1133
1146
-
let version = version_str
1134
+
let version = s
1147
1135
.parse::<semver::Version>()
1148
1136
.map_err(serde::de::Error::custom)?;
1149
1137
let cur_version = version::version()
1150
1138
.version
1151
1139
.parse::<semver::Version>()
1152
1140
.expect("Invalid prek version");
1153
1141
if version > cur_version {
1154
-
let hint = upgrade_hint.unwrap_or("Please consider updating prek.");
1155
1142
returnErr(serde::de::Error::custom(format!(
1156
-
"Required minimum prek version `{version}` is greater than current version `{cur_version}`. {hint}",
1143
+
"Required minimum prek version `{version}` is greater than current version `{cur_version}`. Please consider updating prek.",
1157
1144
)));
1158
1145
}
1159
1146
1160
-
Ok(Some(version_str.to_string()))
1147
+
Ok(Some(s))
1161
1148
}
1162
1149
1163
1150
/// Deserializes a vector of strings and validates that each is a known file type tag.
@@ -1702,52 +1689,6 @@ mod tests {
1702
1689
");
1703
1690
}
1704
1691
1705
-
#[test]
1706
-
fntest_upgrade_hint(){
1707
-
// Test that hint is included in error message when version is too new
1708
-
let yaml = indoc::indoc! {r"
1709
-
repos:
1710
-
- repo: local
1711
-
hooks:
1712
-
- id: test-hook
1713
-
name: Test Hook
1714
-
entry: echo test
1715
-
language: system
1716
-
minimum_prek_version: '10.0.0; Use `brew upgrade` to upgrade prek'
1717
-
"};
1718
-
let err = serde_saphyr::from_str::<Config>(yaml).unwrap_err();
1719
-
insta::assert_snapshot!(err, @"
1720
-
error: line 8 column 23: Required minimum prek version `10.0.0` is greater than current version `0.3.1`. Use `brew upgrade` to upgrade prek at line 8, column 23
1721
-
--> <input>:8:23
1722
-
|
1723
-
6 | entry: echo test
1724
-
7 | language: system
1725
-
8 | minimum_prek_version: '10.0.0; Use `brew upgrade` to upgrade prek'
1726
-
| ^ Required minimum prek version `10.0.0` is greater than current version `0.3.1`. Use `brew upgrade` to upgrade prek at line 8, column 23
1727
-
");
1728
-
1729
-
let yaml = indoc::indoc! {r"
1730
-
repos:
1731
-
- repo: local
1732
-
hooks:
1733
-
- id: test-hook
1734
-
name: Test Hook
1735
-
entry: echo test
1736
-
language: system
1737
-
minimum_prek_version: '10.0.0; '
1738
-
"};
1739
-
let err = serde_saphyr::from_str::<Config>(yaml).unwrap_err();
1740
-
insta::assert_snapshot!(err, @"
1741
-
error: line 8 column 23: Required minimum prek version `10.0.0` is greater than current version `0.3.1`. Please consider updating prek. at line 8, column 23
1742
-
--> <input>:8:23
1743
-
|
1744
-
6 | entry: echo test
1745
-
7 | language: system
1746
-
8 | minimum_prek_version: '10.0.0; '
1747
-
| ^ Required minimum prek version `10.0.0` is greater than current version `0.3.1`. Please consider updating prek. at line 8, column 23
0 commit comments