From b3ee8400dd955e2ecb80b06863da306e42f31d2d Mon Sep 17 00:00:00 2001 From: Thomas Otto Date: Mon, 8 May 2023 22:49:05 +0200 Subject: Fix submodule diff parsing (#1413) Added support for an optional -dirty hash suffix which is present in `git diff` output when files were changed in a submodule. --- src/handlers/submodule.rs | 2 +- src/tests/test_example_diffs.rs | 24 ++++++++++++++++++++++++ 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/src/handlers/submodule.rs b/src/handlers/submodule.rs index 4578594a..f4cf4c16 100644 --- a/src/handlers/submodule.rs +++ b/src/handlers/submodule.rs @@ -51,7 +51,7 @@ impl<'a> StateMachine<'a> { lazy_static! { static ref SUBMODULE_SHORT_LINE_REGEX: Regex = - Regex::new("^[-+]Subproject commit ([0-9a-f]{40})$").unwrap(); + Regex::new("^[-+]Subproject commit ([0-9a-f]{40})(-dirty)?$").unwrap(); } pub fn get_submodule_short_commit(line: &str) -> Option<&str> { diff --git a/src/tests/test_example_diffs.rs b/src/tests/test_example_diffs.rs index 2fca095c..b3595149 100644 --- a/src/tests/test_example_diffs.rs +++ b/src/tests/test_example_diffs.rs @@ -193,6 +193,20 @@ mod tests { assert_eq!(strip_ansi_codes(&output), DIFF_WITH_MERGE_CONFLICT); } + #[test] + fn test_simple_dirty_submodule_diff() { + DeltaTest::with_args(&["--width", "30"]) + .with_input(SUBMODULE_DIRTY) + .inspect() + .expect_after_skip( + 1, + r#" + some_submodule + ────────────────────────────── + ca030fd..803be42"#, + ); + } + #[test] fn test_submodule_diff_log() { // See etc/examples/662-submodules @@ -1934,6 +1948,16 @@ This is a regular file that contains: Some text here -Some text with a minus +Some text with a plus +"; + + const SUBMODULE_DIRTY: &str = "\ +diff --git a/some_submodule b/some_submodule +index ca030fd1a0..803be42ca4 160000 +--- a/some_submodule ++++ b/some_submodule +@@ -1 +1 @@ +-Subproject commit ca030fd1a02225a6fc1a834c480276d9c97a8c6f ++Subproject commit 803be42ca46af0fbc65b54a9abfb499389516939-dirty "; // See etc/examples/662-submodules -- cgit v1.2.3