From 4dfbd2e0e2edecd2ed7d3cd44bac8257e61ba83c Mon Sep 17 00:00:00 2001 From: Ilka Guigova Date: Fri, 27 Nov 2026 06:51:53 -0700 Subject: [PATCH] Keep a moved submodule as its commit change in local patches A person's diff.submodule setting reshaped the patch: "log" dropped the submodule's diff header, so the review was refused as an invalid diff, and "diff" inlined the submodule's own files, which passed the header check and were uploaded in place of the gitlink change. Pin --submodule=short beside the other settings the server depends on. Fixes #105. Co-Authored-By: Claude Opus 5.5 --- src/git.rs | 66 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) diff --git a/src/git.rs b/src/git.rs index 1c392b4..0e50abc 100644 --- a/src/git.rs +++ b/src/git.rs @@ -400,6 +400,8 @@ async fn diff( "--no-ext-diff", "--no-textconv", "--no-color", + // A submodule is its commit change, never its own files or log. + "--submodule=short", "--src-prefix=a/", "--dst-prefix=b/", &base_commit_sha, @@ -767,4 +769,68 @@ mod tests { staged ); } + + #[tokio::test] + async fn a_moved_submodule_is_its_commit_change_whatever_the_configuration_says() { + let identify = |dir: &Path| { + run(dir, &["config", "user.email", "dev@example.com"]); + run(dir, &["config", "user.name", "dev"]); + }; + let library = tempfile::tempdir().unwrap(); + run(library.path(), &["init", "-q", "-b", "main"]); + identify(library.path()); + std::fs::write(library.path().join("f"), "one\n").unwrap(); + run(library.path(), &["add", "f"]); + run(library.path(), &["commit", "-qm", "one"]); + + let repo = tempfile::tempdir().unwrap(); + let dir = repo.path(); + run(dir, &["init", "-q", "-b", "main"]); + identify(dir); + let source = library.path().to_str().unwrap(); + run( + dir, + &[ + "-c", + "protocol.file.allow=always", + "submodule", + "add", + "-q", + source, + "lib", + ], + ); + run(dir, &["commit", "-qm", "base"]); + let base = run(dir, &["rev-parse", "HEAD"]).trim().to_owned(); + run(dir, &["update-ref", "refs/remotes/origin/main", &base]); + run( + dir, + &[ + "symbolic-ref", + "refs/remotes/origin/HEAD", + "refs/remotes/origin/main", + ], + ); + let submodule = dir.join("lib"); + identify(&submodule); + std::fs::write(submodule.join("f"), "one\ntwo\n").unwrap(); + run(&submodule, &["commit", "-qam", "two"]); + run(dir, &["add", "lib"]); + + // "log" drops the submodule's header, and "diff" inlines its files. + for setting in ["short", "log", "diff"] { + run(dir, &["config", "diff.submodule", setting]); + let changes = local_changes(dir, "origin", LocalSelection::Staged, None) + .await + .unwrap(); + let headers: Vec<&str> = changes + .patch + .lines() + .filter(|line| line.starts_with("diff --git ")) + .collect(); + assert_eq!(headers, ["diff --git a/lib b/lib"], "{setting}"); + assert!(changes.patch.contains("+Subproject commit "), "{setting}"); + assert!(!changes.patch.contains("+two"), "{setting}"); + } + } }