git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH] git-project-version

From
SBSanti Béjar <sbejar@gmail.com>
Date
Aug 4, 2006, 21:48 UTC
Message-ID
<87bqr0tbo6.fsf@gmail.com>

Introduce an easy way for projects to get its git version. This is something that other projects using git would like to do, and we don't want them all reinventing the wheel.

Signed-off-by: Santi Béjar <sbejar@gmail.com>
---
Hi *,
I would prefer an output with an explicit git string as:
v1.4.2-rc3-git46faaaf
Also I would prefer the dirty state with an ending M as in:
v1.4.2-rc3-git46faaaf-M
to use the same letter of the diff family.
   Santi
 Makefile               |    3 ++-
 git-project-version.sh |    9 +++++++++
 2 files changed, 11 insertions(+), 1 deletions(-)
diff --git a/Makefile b/Makefile
index d662bd6..7c4e360 100644
--- a/Makefile
+++ b/Makefile
@@ -169,7 +169,8 @@ SCRIPT_SH = \
 	git-applymbox.sh git-applypatch.sh git-am.sh \
 	git-merge.sh git-merge-stupid.sh git-merge-octopus.sh \
 	git-merge-resolve.sh git-merge-ours.sh \
-	git-lost-found.sh git-quiltimport.sh
+	git-lost-found.sh git-quiltimport.sh \
+	git-project-version.sh
 
 SCRIPT_PERL = \
 	git-archimport.perl git-cvsimport.perl git-relink.perl \
diff --git a/git-project-version.sh b/git-project-version.sh
new file mode 100755
index 0000000..88b21fa
--- /dev/null
+++ b/git-project-version.sh
@@ -0,0 +1,9 @@
+#!/bin/sh
+# First try git-describe.
+VN=$(git describe --abbrev=4 HEAD 2>/dev/null) ||
+VN=$(git rev-parse --short HEAD | sed -e 's/^/g/')
+
+dirty=$(sh -c 'git diff-index --name-only HEAD' 2>/dev/null) || dirty=
+[ "$dirty" ] && VN="$VN-dirty"
+
+echo $VN
-- 
1.4.2.rc3.g3f0a-dirty
Next: Petr Baudis
Message 1 of 3 in “git-project-version”
  1. git-project-versionSanti Béjar, Aug 4, 2006
  2. Petr BaudisSep 23, 2006
  3. SantiSep 24, 2006

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.