Skip to content

Commit 85e3956

Browse files
committed
Make the subproject commit regex more accurate
1 parent 98ad725 commit 85e3956

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

src/handlers/check_commits/modified_submodule.rs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,23 @@
11
use std::sync::LazyLock;
22

3-
use regex::Regex;
3+
use regex::{Regex, RegexBuilder};
44

55
use crate::github::FileDiff;
66

77
const SUBMODULE_WARNING_MSG: &str = "Some commits in this PR modify **submodules**.";
88

9-
static SUBPROJECT_UPDATE_RE: LazyLock<Regex> =
10-
LazyLock::new(|| Regex::new(r"\+Subproject\scommit\s").unwrap());
9+
static SUBPROJECT_COMMIT_RE: LazyLock<Regex> = LazyLock::new(|| {
10+
RegexBuilder::new(r"^\+Subproject commit [a-zA-Z0-9]+$")
11+
.multi_line(true)
12+
.build()
13+
.unwrap()
14+
});
1115

1216
/// Returns a message if the PR modifies a git submodule.
1317
pub(super) fn modifies_submodule(diff: &[FileDiff]) -> Option<String> {
1418
if diff
1519
.iter()
16-
.any(|fd| SUBPROJECT_UPDATE_RE.is_match(&fd.patch))
20+
.any(|fd| SUBPROJECT_COMMIT_RE.is_match(&fd.patch))
1721
{
1822
Some(SUBMODULE_WARNING_MSG.to_string())
1923
} else {
@@ -61,6 +65,5 @@ fn no_submodule_update_tricky_case() {
6165
.to_string(),
6266
};
6367

64-
// FIXME: This should be true (aka None), but isn't currently!
6568
assert_eq!(modifies_submodule(&[filediff]), None)
6669
}

0 commit comments

Comments
 (0)