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 <svenvh@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Sven van Haastregt committed
Feb 3, 2019 at 21:00 UTC
0586a438f64bc13d6634379cbeeaa96c9e8241d9
1 file changed
+5
-2
git-submodule.sh
+5
-2
@@ -850,8 +850,11 @@ cmd_summary() {
850
;;
851
esac
852
853
- sha1_abbr_src=$(echo $sha1_src | cut -c1-7)
854
- sha1_abbr_dst=$(echo $sha1_dst | cut -c1-7)
853
+ sha1_abbr_src=$(GIT_DIR="$name/.git" git rev-parse --short $sha1_src 2>/dev/null ||
854
+ echo $sha1_src | cut -c1-7)
855
+ sha1_abbr_dst=$(GIT_DIR="$name/.git" git rev-parse --short $sha1_dst 2>/dev/null ||
856
+ echo $sha1_dst | cut -c1-7)
857
+
858
if test $status = T
859
then
860
blob="$(gettext "blob")"