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(){
1131
1143
returnOk(None);
1132
1144
}
1133
1145
1134
-
let version = s
1146
+
let version = version_str
1135
1147
.parse::<semver::Version>()
1136
1148
.map_err(serde::de::Error::custom)?;
1137
1149
let cur_version = version::version()
1138
1150
.version
1139
1151
.parse::<semver::Version>()
1140
1152
.expect("Invalid prek version");
1141
1153
if version > cur_version {
1154
+
let hint = upgrade_hint.unwrap_or("Please consider updating prek.");
1142
1155
returnErr(serde::de::Error::custom(format!(
1143
-
"Required minimum prek version `{version}` is greater than current version `{cur_version}`. Please consider updating prek.",
1156
+
"Required minimum prek version `{version}` is greater than current version `{cur_version}`. {hint}",
1144
1157
)));
1145
1158
}
1146
1159
1147
-
Ok(Some(s))
1160
+
Ok(Some(version_str.to_string()))
1148
1161
}
1149
1162
1150
1163
/// Deserializes a vector of strings and validates that each is a known file type tag.
@@ -1689,6 +1702,52 @@ mod tests {
1689
1702
");
1690
1703
}
1691
1704
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