Until now, `git submodule summary` was always emitting 7-character
SHA-1s that have a higher chance of being ambiguous for larger
repositories.  Use `git rev-parse --short` instead, which will
determine suitable short SHA-1 lengths.

We cannot always rely on successfully invoking `git rev-parse` in the
submodule directory.  Keep the old method using `cut` as a fallback.

Signed-off-by: Sven van Haastregt <sve...@gmail.com>
---

Differences since v2: Simplify code as suggested by Eric
Sunshine <sunsh...@sunshineco.com> and suppress stderr.

 git-submodule.sh | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/git-submodule.sh b/git-submodule.sh
index 5e608f8bad..e26146e721 100755
--- a/git-submodule.sh
+++ b/git-submodule.sh
@@ -850,8 +850,11 @@ cmd_summary() {
                        ;;
                esac
 
-               sha1_abbr_src=$(echo $sha1_src | cut -c1-7)
-               sha1_abbr_dst=$(echo $sha1_dst | cut -c1-7)
+               sha1_abbr_src=$(GIT_DIR="$name/.git" git rev-parse --short 
$sha1_src 2>/dev/null ||
+                       echo $sha1_src | cut -c1-7)
+               sha1_abbr_dst=$(GIT_DIR="$name/.git" git rev-parse --short 
$sha1_dst 2>/dev/null ||
+                       echo $sha1_dst | cut -c1-7)
+
                if test $status = T
                then
                        blob="$(gettext "blob")"
-- 
2.20.1.dirty

Reply via email to