update-hook: fix incorrect use of git-describe and sed for finding previous tag
PATCH 1/1 update-hook: fix incorrect use of git-describe and sed for finding previous tag
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.
--- templates/hooks--update | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-)
templates/hooks--update +1 -1
@@ -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
Signature · 1 line
1.5.0.3.402.g0c48
Quoted 11 lines · Andy Parkins
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.
Quoted 7 lines
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 <[email protected]>
Quoted 9 lines
--- templates/hooks--update | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-)templates/hooks--update +0
-0
templates/hooks--update case "$refname_type" in · line 216
Quoted 8 lines
templates/hooks--update +1
-1@@ -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
I just updated git on our repo server and did this exact change to our update tag 15 minutes ago.
Signature · 3 lines
Andreas Ericsson [email protected] OP5 AB www.op5.se Tel: +46 8-230225 Fax: +46 8-230231