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

[PATCH] update-hook: fix incorrect use of git-describe and sed for finding previous tag

From
APAndy Parkins <andyparkins@gmail.com>
Date
Mar 14, 2007, 14:25 UTC
Message-ID
<200703141425.53192.andyparkins@gmail.com>
Previously git-describe would output lines of the form
 v1.1.1-gf509d56
The update hook found the dash and stripped it off using
 sed 's/-g.*//'
The remainder was then used as the previous tag name.
However, git-describe has changed format.  The output is now of the form
 v1.1.1-23-gf509d56
The above sed fragment doesn't strip the middle "-23", and so the
previous tag name used would be "v1.1.1-23".  This is incorrect.

Since the hook script was written, git-describe now gained support for "--abbrev=0", which it uses as a special flag to tell it not to output anything other than the nearest tag name. This patch fixes the problem, and prevents any future recurrence by using this new flag rather than sed to find the previous tag.

Signed-off-by: Andy Parkins <andyparkins@gmail.com>
---
 templates/hooks--update |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
diff --git a/templates/hooks--update b/templates/hooks--update
index 5b82b68..8f6c4fe 100644
--- a/templates/hooks--update
+++ b/templates/hooks--update
@@ -210,7 +210,7 @@ case "$refname_type" in
 		fi
 
 		# If this tag succeeds another, then show which tag it replaces
-		prevtag=$(git describe $newrev^ 2>/dev/null | sed 's/-g.*//')
+		prevtag=$(git describe --abbrev=0 $newrev^ 2>/dev/null)
 		if [ -n "$prevtag" ]; then
 			echo "  replaces  $prevtag"
 		fi
-- 
1.5.0.3.402.g0c48
Next: Andreas Ericsson
Message 1 of 2 in “update-hook: fix incorrect use of git-describe and sed for finding previous tag”
  1. update-hook: fix incorrect use of git-describe and sed for finding previous tagAndy Parkins, Mar 14, 2007
  2. Andreas EricssonMar 16, 2007

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.