From 0586a438f64bc13d6634379cbeeaa96c9e8241d9 Mon Sep 17 00:00:00 2001 From: Sven van Haastregt Date: Sun, 3 Feb 2019 21:00:27 +0000 Subject: [PATCH] git-submodule.sh: shorten submodule SHA-1s using rev-parse 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. When a submodule hasn't been initialized with "submodule init" or not cloned, `git rev-parse` would not work in it yet; as a fallback, use the original method of cutting at 7 hexdigits. Signed-off-by: Sven van Haastregt Signed-off-by: Junio C Hamano --- 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")"