{"thread":{"id":"12996","subject":"Re: [PATCH] git-fetch: Don't trigger a bus error when given the refspec \"tag\"","startedAt":"2008-04-05T18:28:53Z","lastAt":"2008-04-05T18:46:44Z","messageCount":3,"participants":["Johannes Schindelin","Kevin Ballard"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"299042","messageId":"1207420133-23631-1-git-send-email-kevin@sb.org","threadId":"12996","inReplyTo":null,"subject":"[PATCH] git-fetch: Don't trigger a bus error when given the refspec \"tag\"","fromName":"Kevin Ballard","fromEmail":"kevin@sb.org","sentAt":"2008-04-05T18:28:53Z","receivedAt":"2008-04-05T18:28:53Z","isPatch":true,"sender":{"key":"kevin@sb.org","avatar":"https://avatars.githubusercontent.com/u/714?v=4"},"body":"When git-fetch encounters the refspec \"tag\" it assumes that the next\nargument will be a tag name. If there is no next argument, it should\ndie gracefully instead of erroring.\n\nSigned-off-by: Kevin Ballard <kevin@sb.org>\n---\n builtin-fetch.c |    2 ++\n 1 files changed, 2 insertions(+), 0 deletions(-)\n\ndiff --git a/builtin-fetch.c b/builtin-fetch.c\nindex a11548c..5841b3e 100644\n--- a/builtin-fetch.c\n+++ b/builtin-fetch.c\n@@ -637,6 +637,8 @@ int cmd_fetch(int argc, const char **argv, const char *prefix)\n \t\t\tif (!strcmp(argv[i], \"tag\")) {\n \t\t\t\tchar *ref;\n \t\t\t\ti++;\n+\t\t\t\tif (i >= argc)\n+\t\t\t\t\tdie(\"You need to specify a tag name.\");\n \t\t\t\tref = xmalloc(strlen(argv[i]) * 2 + 22);\n \t\t\t\tstrcpy(ref, \"refs/tags/\");\n \t\t\t\tstrcat(ref, argv[i]);\n-- \n1.5.5.rc3.dirty\n\n"},{"id":"73707","messageId":"alpine.DEB.1.00.0804051931480.12583@eeepc-johanness","threadId":"12996","inReplyTo":"1207420133-23631-1-git-send-email-kevin@sb.org","subject":"Re: [PATCH] git-fetch: Don't trigger a bus error when given the refspec \"tag\"","fromName":"Johannes Schindelin","fromEmail":"johannes.schindelin@gmx.de","sentAt":"2008-04-05T18:33:22Z","receivedAt":"2008-04-05T18:33:22Z","isPatch":true,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"Hi,\n\nOn Sat, 5 Apr 2008, Kevin Ballard wrote:\n\n> diff --git a/builtin-fetch.c b/builtin-fetch.c\n> index a11548c..5841b3e 100644\n> --- a/builtin-fetch.c\n> +++ b/builtin-fetch.c\n> @@ -637,6 +637,8 @@ int cmd_fetch(int argc, const char **argv, const char *prefix)\n>  \t\t\tif (!strcmp(argv[i], \"tag\")) {\n>  \t\t\t\tchar *ref;\n>  \t\t\t\ti++;\n> +\t\t\t\tif (i >= argc)\n> +\t\t\t\t\tdie(\"You need to specify a tag name.\");\n\nWould it not be better to check in the if() above?  IOW\n\n\t\t\tif (i + 1 < argc && !strcmp(argv[i], \"tag\")) {\n\nHmm?\n\nCiao,\nDscho\n"},{"id":"73708","messageId":"9FD2C650-C9DD-41E1-AE27-684A82E1D700@sb.org","threadId":"12996","inReplyTo":"alpine.DEB.1.00.0804051931480.12583@eeepc-johanness","subject":"Re: [PATCH] git-fetch: Don't trigger a bus error when given the refspec \"tag\"","fromName":"Kevin Ballard","fromEmail":"kevin@sb.org","sentAt":"2008-04-05T18:46:44Z","receivedAt":"2008-04-05T18:46:44Z","isPatch":true,"sender":{"key":"kevin@sb.org","avatar":"https://avatars.githubusercontent.com/u/714?v=4"},"body":"On Apr 5, 2008, at 2:33 PM, Johannes Schindelin wrote:\n> Hi,\n>\n> On Sat, 5 Apr 2008, Kevin Ballard wrote:\n>\n>> diff --git a/builtin-fetch.c b/builtin-fetch.c\n>> index a11548c..5841b3e 100644\n>> --- a/builtin-fetch.c\n>> +++ b/builtin-fetch.c\n>> @@ -637,6 +637,8 @@ int cmd_fetch(int argc, const char **argv,  \n>> const char *prefix)\n>> \t\t\tif (!strcmp(argv[i], \"tag\")) {\n>> \t\t\t\tchar *ref;\n>> \t\t\t\ti++;\n>> +\t\t\t\tif (i >= argc)\n>> +\t\t\t\t\tdie(\"You need to specify a tag name.\");\n>\n> Would it not be better to check in the if() above?  IOW\n>\n> \t\t\tif (i + 1 < argc && !strcmp(argv[i], \"tag\")) {\n>\n> Hmm?\n\nSo that `git fetch origin tag` will try and fetch the branch named  \ntag? Given that we treat \"tag foo\" as shorthand for refs/tags/foo:refs/ \ntags/foo it seems like it would be unexpected to treat \"tag\" as just a  \nplain ref. I much prefer to die in this situation, let the user fix  \nthe refspec to mean exactly what they want (either by adding a tag  \nname, or by using tag: if they really want a branch named tag).\n\n-Kevin\n\n-- \nKevin Ballard\nhttp://kevin.sb.org\nkevin@sb.org\nhttp://www.tildesoft.com\n"}]}