{"thread":{"id":"7244","subject":"[PATCH] update-hook: fix incorrect use of git-describe and sed for finding previous tag","startedAt":"2007-03-14T14:25:52Z","lastAt":"2007-03-16T09:06:40Z","messageCount":2,"participants":["Andy Parkins","Andreas Ericsson"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"37088","messageId":"200703141425.53192.andyparkins@gmail.com","threadId":"7244","inReplyTo":null,"subject":"[PATCH] update-hook: fix incorrect use of git-describe and sed for finding previous tag","fromName":"Andy Parkins","fromEmail":"andyparkins@gmail.com","sentAt":"2007-03-14T14:25:52Z","receivedAt":"2007-03-14T14:25:52Z","isPatch":true,"sender":{"key":"andyparkins@gmail.com","avatar":null},"body":"Previously git-describe would output lines of the form\n v1.1.1-gf509d56\nThe update hook found the dash and stripped it off using\n sed 's/-g.*//'\nThe remainder was then used as the previous tag name.\n\nHowever, git-describe has changed format.  The output is now of the form\n v1.1.1-23-gf509d56\nThe above sed fragment doesn't strip the middle \"-23\", and so the\nprevious tag name used would be \"v1.1.1-23\".  This is incorrect.\n\nSince the hook script was written, git-describe now gained support for\n\"--abbrev=0\", which it uses as a special flag to tell it not to output\nanything other than the nearest tag name.  This patch fixes the problem,\nand prevents any future recurrence by using this new flag rather than\nsed to find the previous tag.\n\nSigned-off-by: Andy Parkins <andyparkins@gmail.com>\n---\n templates/hooks--update |    2 +-\n 1 files changed, 1 insertions(+), 1 deletions(-)\n\ndiff --git a/templates/hooks--update b/templates/hooks--update\nindex 5b82b68..8f6c4fe 100644\n--- a/templates/hooks--update\n+++ b/templates/hooks--update\n@@ -210,7 +210,7 @@ case \"$refname_type\" in\n \t\tfi\n \n \t\t# If this tag succeeds another, then show which tag it replaces\n-\t\tprevtag=$(git describe $newrev^ 2>/dev/null | sed 's/-g.*//')\n+\t\tprevtag=$(git describe --abbrev=0 $newrev^ 2>/dev/null)\n \t\tif [ -n \"$prevtag\" ]; then\n \t\t\techo \"  replaces  $prevtag\"\n \t\tfi\n-- \n1.5.0.3.402.g0c48\n"},{"id":"37216","messageId":"45FA5E20.2050905@op5.se","threadId":"7244","inReplyTo":"200703141425.53192.andyparkins@gmail.com","subject":"Re: [PATCH] update-hook: fix incorrect use of git-describe and sed for finding previous tag","fromName":"Andreas Ericsson","fromEmail":"ae@op5.se","sentAt":"2007-03-16T09:06:40Z","receivedAt":"2007-03-16T09:06:40Z","isPatch":true,"sender":{"key":"ae@op5.se","avatar":"https://gravatar.com/avatar/426e89595c75a8f5252dd0c989e5fabe5bcac616e68557427ad9aef6b0ca342a?d=mp&s=160"},"body":"Andy Parkins wrote:\n> Previously git-describe would output lines of the form\n>  v1.1.1-gf509d56\n> The update hook found the dash and stripped it off using\n>  sed 's/-g.*//'\n> The remainder was then used as the previous tag name.\n> \n> However, git-describe has changed format.  The output is now of the form\n>  v1.1.1-23-gf509d56\n> The above sed fragment doesn't strip the middle \"-23\", and so the\n> previous tag name used would be \"v1.1.1-23\".  This is incorrect.\n> \n> Since the hook script was written, git-describe now gained support for\n> \"--abbrev=0\", which it uses as a special flag to tell it not to output\n> anything other than the nearest tag name.  This patch fixes the problem,\n> and prevents any future recurrence by using this new flag rather than\n> sed to find the previous tag.\n> \n> Signed-off-by: Andy Parkins <andyparkins@gmail.com>\n\nAcked-by: Andreas Ericsson <ae@op5.se>\n\n\n> ---\n>  templates/hooks--update |    2 +-\n>  1 files changed, 1 insertions(+), 1 deletions(-)\n> \n> diff --git a/templates/hooks--update b/templates/hooks--update\n> index 5b82b68..8f6c4fe 100644\n> --- a/templates/hooks--update\n> +++ b/templates/hooks--update\n> @@ -210,7 +210,7 @@ case \"$refname_type\" in\n>  \t\tfi\n>  \n>  \t\t# If this tag succeeds another, then show which tag it replaces\n> -\t\tprevtag=$(git describe $newrev^ 2>/dev/null | sed 's/-g.*//')\n> +\t\tprevtag=$(git describe --abbrev=0 $newrev^ 2>/dev/null)\n>  \t\tif [ -n \"$prevtag\" ]; then\n>  \t\t\techo \"  replaces  $prevtag\"\n>  \t\tfi\n\nI just updated git on our repo server and did this exact change to our update\ntag 15 minutes ago.\n\n-- \nAndreas Ericsson                   andreas.ericsson@op5.se\nOP5 AB                             www.op5.se\nTel: +46 8-230225                  Fax: +46 8-230231\n"}]}