git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH] [Outreachy PATCH] t4041: use submodule repository for commit abbreviations

From
SGSrujith A Poojary via GitGitGadget <gitgitgadget@gmail.com>
Date
Oct 31, 2026, 08:25 UTC
Message-ID
<pull.2288.git.1793435149942.gitgitgadget@gmail.com>
From: Srujith A Poojary <poojarysrujith@gmail.com>

Use the submodule repository when abbreviating commit IDs in submodule diff headers, so uniqueness is checked against the correct object database.

Signed-off-by: Srujith A Poojary <poojarysrujith@gmail.com>
---
    [Outreachy PATCH] t4041: use submodule repository for commit
    abbreviations
Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-2288%2Fpoojarysrujith%2Fmicroproject-git-libification-v1
Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-2288/poojarysrujith/microproject-git-libification-v1
Pull-Request: https://github.com/gitgitgadget/git/pull/2288
 submodule.c                      | 10 ++++++++--
 t/t4041-diff-submodule-option.sh | 18 ++++++++++++++++++
 2 files changed, 26 insertions(+), 2 deletions(-)
diff --git a/submodule.c b/submodule.c
index 6fcb606f7e..2215a50d9c 100644
--- a/submodule.c
+++ b/submodule.c
@@ -599,9 +599,15 @@ static void show_submodule_header(struct diff_options *o,
 
 output_header:
 	strbuf_addf(&sb, "Submodule %s ", path);
-	strbuf_add_unique_abbrev(&sb, one, DEFAULT_ABBREV);
+	if (sub)
+		strbuf_repo_add_unique_abbrev(&sb, sub, one, DEFAULT_ABBREV);
+	else
+		strbuf_add_unique_abbrev(&sb, one, DEFAULT_ABBREV);
 	strbuf_addstr(&sb, (fast_backward || fast_forward) ? ".." : "...");
-	strbuf_add_unique_abbrev(&sb, two, DEFAULT_ABBREV);
+	if (sub)
+		strbuf_repo_add_unique_abbrev(&sb, sub, two, DEFAULT_ABBREV);
+	else
+		strbuf_add_unique_abbrev(&sb, two, DEFAULT_ABBREV);
 	if (message)
 		strbuf_addf(&sb, " %s\n", message);
 	else
diff --git a/t/t4041-diff-submodule-option.sh b/t/t4041-diff-submodule-option.sh
index 4dd4954260..e80472af32 100755
--- a/t/t4041-diff-submodule-option.sh
+++ b/t/t4041-diff-submodule-option.sh
@@ -14,6 +14,24 @@ export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
 
 . ./test-lib.sh
 
+test_expect_success SHA1 'submodule commit abbreviation uses submodule object database' '
+	test_when_finished "rm -rf collision-super" &&
+	git init -q collision-super &&
+	git init -q collision-super/sm1 &&
+	printf "0\n1\n2\n3\n4\n5\n6\n7\n8\n9\n\nb1rwzyc3\n" >collision-super/sm1/a0blgqsjc &&
+	git -C collision-super/sm1 add a0blgqsjc &&
+	tree=$(git -C collision-super/sm1 write-tree) &&
+	commit1=$(GIT_AUTHOR_DATE="1112911993 -0700" GIT_COMMITTER_DATE="1112911993 -0700" git -C collision-super/sm1 commit-tree "$tree" -m a2onsxbvj) &&
+	commit2=$(printf "child\n" | GIT_AUTHOR_DATE="1112912053 -0700" GIT_COMMITTER_DATE="1112912053 -0700" git -C collision-super/sm1 commit-tree "$tree" -p "$commit1") &&
+	git -C collision-super/sm1 checkout -q "$commit2" &&
+	git -C collision-super update-index --add --cacheinfo 160000,"$commit1",sm1 &&
+	git -C collision-super commit -q -m "Add submodule" &&
+	git -C collision-super diff --submodule=log >actual &&
+	printf "Submodule sm1 0000000000e..%s:\n  > child\n" \
+		"$(git -C collision-super/sm1 rev-parse --short "$commit2")" >expected &&
+	test_cmp expected actual
+'
+
 # Test non-UTF-8 encoding in case iconv is available.
 if test_have_prereq ICONV
 then

base-commit: 50fe5cc63f9cd6e89b87a2c9ccf96a444f4cfdb7
-- 
gitgitgadget
Next: Okhuomon Ajayi
Message 1 of 7 in “t4041: use submodule repository for commit abbreviations”
  1. [Outreachy PATCH] t4041: use submodule repository for commit abbreviationsSrujith A Poojary via GitGitGadget, Oct 31, 2026
  2. Okhuomon AjayiOct 31, 2026
  3. Srujith PoojaryOct 31, 2026
  4. Submodule: use the submodule repository to abbreviate commitsSrujith A Poojary via GitGitGadget, Oct 31, 2026
  5. Okhuomon AjayiOct 31, 2026
  6. Srujith PoojaryOct 31, 2026
  7. submodule: use the submodule repository to abbreviate commitsSrujith A Poojary via GitGitGadget, Oct 31, 2026

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.