]> git.phdru.name Git - git-scripts.git/commitdiff
Add script `submodules/diff-name-only`
authorOleg Broytman <phd@phdru.name>
Thu, 27 May 2021 17:34:23 +0000 (20:34 +0300)
committerOleg Broytman <phd@phdru.name>
Thu, 27 May 2021 17:36:40 +0000 (20:36 +0300)
submodules/diff-name-only [new file with mode: 0755]

diff --git a/submodules/diff-name-only b/submodules/diff-name-only
new file mode 100755 (executable)
index 0000000..d513613
--- /dev/null
@@ -0,0 +1,20 @@
+#! /bin/sh
+# See the discussion at https://stackoverflow.com/q/67724347/7976758
+
+if [ -z "$1" ]; then
+    echo "Usage $0 from_commit [to_commit]"
+    exit 1
+fi
+
+from_commit="$1"
+to_commit="${2:-HEAD}"
+
+# In the superproject
+git --no-pager diff --name-only "$from_commit" "$to_commit"
+
+git submodule foreach "
+    # In submodule \"\$name\"
+    prev_commit=\`(git -C \"\$toplevel\" ls-tree "$from_commit" \"\$sm_path\" | awk '{print \$3}')\`
+    curr_commit=\`(git -C \"\$toplevel\" ls-tree "$to_commit" \"\$sm_path\" | awk '{print \$3}')\`
+    git --no-pager diff --name-only \$prev_commit \$curr_commit
+"