[PATCH] git-submodule: Try harder to describe the status of a submodule

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Some repositories might not use/have annotated tags (for example repositories created with
git-cvsimport) or might not have tags at all and could cause git-submodule status to fail because
git-describe might fail.

This change makes git-submodule status try harder in displaying the status of a module by
considering lightweight tags, subsequent tags and branches.

Signed-off-by: Emil Medve <Emilian.Medve@xxxxxxxxxxxxx>
---
 git-submodule.sh |   23 +++++++++++++++++++++--
 1 files changed, 21 insertions(+), 2 deletions(-)

diff --git a/git-submodule.sh b/git-submodule.sh
index 89a3885..7429ce3 100755
--- a/git-submodule.sh
+++ b/git-submodule.sh
@@ -134,6 +134,25 @@ modules_update()
 }
 
 #
+# Identify and display the most specific name describing an object specified by a SHA1 key
+#
+# First try to locate a tag that predates the commit. If that fails try to locate a tag that comes
+# after the commit. If that fails too (e.g. undefined), try to locate the branch of the commit. If
+# that fails too just display "undefined"
+#
+get_revname()
+{
+	_revname=$(git-describe --tags "$1" 2>/dev/null || git-describe --contains "$1" 2>/dev/null)
+	if test -z "$_revname" -o "$_revname" = "undefined"
+	then
+		_revname=$(git-describe --all "$1" 2>/dev/null | cut -d / -f2-)
+		test -z "$_revname" && _revname=undefined
+	fi
+	echo $_revname
+	unset _revname
+}
+
+#
 # List all submodules, prefixed with:
 #  - submodule not initialized
 #  + different revision checked out
@@ -155,7 +174,7 @@ modules_list()
 			say "-$sha1 $path"
 			continue;
 		fi
-		revname=$(unset GIT_DIR && cd "$path" && git-describe $sha1)
+		revname=$(unset GIT_DIR && cd "$path" && get_revname $sha1)
 		if git diff-files --quiet -- "$path"
 		then
 			say " $sha1 $path ($revname)"
@@ -163,7 +182,7 @@ modules_list()
 			if test -z "$cached"
 			then
 				sha1=$(unset GIT_DIR && cd "$path" && git-rev-parse --verify HEAD)
-				revname=$(unset GIT_DIR && cd "$path" && git-describe $sha1)
+				revname=$(unset GIT_DIR && cd "$path" && get_revname $sha1)
 			fi
 			say "+$sha1 $path ($revname)"
 		fi
-- 
1.5.2.2.549.gaeb59

-
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html

[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]

  Powered by Linux