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

[PATCH] status&commit: Teach them to show commits of modified submodules.

From
Ping Yin <pkufranky@gmail.com>
Date
Nov 2, 2007, 11:53 UTC
Message-ID
<1194004427-26934-1-git-send-email-pkufranky@gmail.com>

git status/commit just treats submodules as ordinary files when reporting status changes. However, one may also wonder how the submodules change.

This commit teaches git status/commit to also show commits of modified submodules since HEAD (or HEAD^ if --amend option is on).

For example, when commiting, submodule sm1 and sm2 are both changed. sm1 has commit C in HEAD and
commit E in index. The history of sm1 is
	--A-->B-->C (in HEAD:354cd45)
	  \
	   -->D->E (in index:3f751e5)

git status will give the following output (just output commits of submodules before normal output) to show how to change from commit C (in HEAD) to commit E (in index): backward ('<<<') to commit A, and then forward ('>>>') to commit E.

	#
	# submodule modifiled: sm1 sm2
	#
	# * sm1 354cd45...3f751e5:
	#   <<<
	#   	one line message for C
	#   	one line message for B
	#   >>>
	#   	one line message for D
	#   	one line message for E
	#
	# * sm2 5c8bfb5...ac46d84:
	#   <<<
	#   	msg
	#
	# On branch master
	# Changes to be committed:
	#   (use "git reset HEAD <file>..." to unstage)
	#
	#	modified:   sm1
	#	modified:   sm2
---
 git-commit.sh |   40 ++++++++++++++++++++++++++++++++++++++++
 1 files changed, 40 insertions(+), 0 deletions(-)
diff --git a/git-commit.sh b/git-commit.sh
index fcb8443..d362caa 100755
--- a/git-commit.sh
+++ b/git-commit.sh
@@ -33,6 +33,40 @@ save_index () {
 	cp -p "$THIS_INDEX" "$NEXT_INDEX"
 }
 
+# Show log of modified submodule (index modification since HEAD or $1)
+show_module_log () {
+	modules=`git diff --cached --name-only $1 |
+	while read name
+	do
+		git ls-files --stage $name
+	done |
+	grep '^160000 ' | awk '{print $4}'`
+	test -z "$modules" && return
+
+	modules=$(echo $modules)
+	echo -e "#\n# submodule modifiled: $modules\n#"
+	for name in $modules
+	do
+		range=`git diff --cached -- $name | sed -n '2 p' | awk '{print $2}'`
+		indexone=${range#*..}
+		headone=${range%..*}
+		(
+			echo "* $name $headone...$indexone:"
+			cd $name >&/dev/null || { echo "  Warning: fail to chdir to $name" && exit; }
+			left="`git log --pretty=oneline $indexone..$headone 2>&1 | sed 's/^\w\+ /  \t/'`"
+			right="`git log --pretty=oneline --reverse  $headone..$indexone 2>&1 | sed 's/^\w\+ /  \t/'`"
+			if echo "$left$right" | grep 'unknown revision' >&/dev/null
+			then
+				echo "  Warning: $name is not a repository or dosn't contains commit $headone/$indexone"
+			else
+				test -n "$left" && echo -e "  <<<\n$left"
+				test -n "$right" && echo -e "  >>>\n$right"
+			fi
+			echo
+		) | sed 's/^/# /'
+	done
+}
+
 run_status () {
 	# If TMP_INDEX is defined, that means we are doing
 	# "--only" partial commit, and that index file is used
@@ -55,6 +89,12 @@ run_status () {
 	else
 		color=--nocolor
 	fi
+	if test -z "$amend"
+	then
+		show_module_log
+	else
+		show_module_log "HEAD^"
+	fi
 	git runstatus ${color} \
 		${verbose:+--verbose} \
 		${amend:+--amend} \
-- 
1.5.3.4
Next: Junio C Hamano
Message 1 of 11 in “status&commit: Teach them to show commits of modified submodules.”
  1. status&commit: Teach them to show commits of modified submodules.Ping Yin, Nov 2, 2007
  2. Junio C HamanoNov 2, 2007
  3. Yin PingNov 2, 2007
  4. Junio C HamanoNov 3, 2007
  5. Yin PingNov 4, 2007
  6. Yin PingNov 4, 2007
  7. Yin PingNov 4, 2007
  8. Junio C HamanoNov 4, 2007
  9. Yin PingNov 4, 2007
  10. Junio C HamanoNov 6, 2007
  11. Yin PingNov 7, 2007

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.