{"thread":{"id":"6385","subject":"git-fetch while on \"(no branch)\"","startedAt":"2007-01-15T10:09:50Z","lastAt":"2007-01-15T22:28:54Z","messageCount":7,"participants":["Andy Parkins","Jeff King","Junio C Hamano"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"31741","messageId":"200701151009.51868.andyparkins@gmail.com","threadId":"6385","inReplyTo":null,"subject":"git-fetch while on \"(no branch)\"","fromName":"Andy Parkins","fromEmail":"andyparkins@gmail.com","sentAt":"2007-01-15T10:09:50Z","receivedAt":"2007-01-15T10:09:50Z","isPatch":false,"sender":{"key":"andyparkins@gmail.com","avatar":null},"body":"Hello,\n\nJust ran this while on a detached HEAD.\n\n$ git fetch\nfatal: ref HEAD is not a symbolic ref\nfatal: ref HEAD is not a symbolic ref\nfatal: ref HEAD is not a symbolic ref\nremote: Generating pack...\n...etc...\n\nThe fetch appears to have succeeded anyway, but it's a scary message that \ntells a user something is \"fatal\".  Has this done any damage?\n\n\nAndy\n-- \nDr Andy Parkins, M Eng (hons), MIEE\nandyparkins@gmail.com\n"},{"id":"31767","messageId":"20070115212442.GA7409@coredump.intra.peff.net","threadId":"6385","inReplyTo":"200701151009.51868.andyparkins@gmail.com","subject":"[PATCH] git-{parse-remote,pull}: throw away stderr of git-symbolic-ref","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2007-01-15T21:24:43Z","receivedAt":"2007-01-15T21:24:43Z","isPatch":true,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"We look up the destination of the HEAD symref in order to get the\ndefault remote and merge head for the current branch. However, if we\nhave a detached HEAD, there is no current branch. We handle this\nsituation by looking up branch..remote, which is empty.\nUnfortunately, git-symbolic-ref complained to stderr, potentially\nscaring users.\n\nSigned-off-by: Jeff King <peff@peff.net>\n---\n git-parse-remote.sh |    4 ++--\n git-pull.sh         |    2 +-\n 2 files changed, 3 insertions(+), 3 deletions(-)\n\ndiff --git a/git-parse-remote.sh b/git-parse-remote.sh\nindex d2e4c2b..bc2485f 100755\n--- a/git-parse-remote.sh\n+++ b/git-parse-remote.sh\n@@ -49,7 +49,7 @@ get_remote_url () {\n }\n \n get_default_remote () {\n-\tcurr_branch=$(git-symbolic-ref HEAD | sed -e 's|^refs/heads/||')\n+\tcurr_branch=$(git-symbolic-ref HEAD 2>/dev/null | sed -e 's|^refs/heads/||')\n \torigin=$(git-repo-config --get \"branch.$curr_branch.remote\")\n \techo ${origin:-origin}\n }\n@@ -137,7 +137,7 @@ canon_refs_list_for_fetch () {\n \t\tshift\n \t\tif test \"$remote\" = \"$(get_default_remote)\"\n \t\tthen\n-\t\t\tcurr_branch=$(git-symbolic-ref HEAD | \\\n+\t\t\tcurr_branch=$(git-symbolic-ref HEAD 2>/dev/null | \\\n \t\t\t    sed -e 's|^refs/heads/||')\n \t\t\tmerge_branches=$(git-repo-config \\\n \t\t\t    --get-all \"branch.${curr_branch}.merge\")\ndiff --git a/git-pull.sh b/git-pull.sh\nindex 9592617..f0cc023 100755\n--- a/git-pull.sh\n+++ b/git-pull.sh\n@@ -83,7 +83,7 @@ merge_head=$(sed -e '/\tnot-for-merge\t/d' \\\n \n case \"$merge_head\" in\n '')\n-\tcurr_branch=$(git-symbolic-ref HEAD | \\\n+\tcurr_branch=$(git-symbolic-ref HEAD 2>/dev/null | \\\n \t\tsed -e 's|^refs/heads/||')\n \techo >&2 \"Warning: No merge candidate found because value of config option\n          \\\"branch.${curr_branch}.merge\\\" does not match any remote branch fetched.\"\n-- \n1.5.0.rc1.gd61e-dirty\n"},{"id":"31769","messageId":"7vzm8k0xai.fsf@assigned-by-dhcp.cox.net","threadId":"6385","inReplyTo":"200701151009.51868.andyparkins@gmail.com","subject":"Re: git-fetch while on \"(no branch)\"","fromName":"Junio C Hamano","fromEmail":"junkio@cox.net","sentAt":"2007-01-15T21:56:05Z","receivedAt":"2007-01-15T21:56:05Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Andy Parkins <andyparkins@gmail.com> writes:\n\n> Hello,\n>\n> Just ran this while on a detached HEAD.\n>\n> $ git fetch\n> fatal: ref HEAD is not a symbolic ref\n> fatal: ref HEAD is not a symbolic ref\n> fatal: ref HEAD is not a symbolic ref\n> remote: Generating pack...\n> ...etc...\n>\n> The fetch appears to have succeeded anyway, but it's a scary message that \n> tells a user something is \"fatal\".  Has this done any damage?\n\nI do not think it has done any damage, but that is certainly alarming.\nThis might help (untested, of course).\n\nBy the way, with or without this patch, there currently is no\ngood way to tell failure modes between \"git symbolic-ref HAED\"\nand \"git symbolic-ref HEAD\".  Both says \"is not a symbolic ref\".\n\nWe may want to do something about it.\n\n---\n\n\ndiff --git a/Documentation/git-symbolic-ref.txt b/Documentation/git-symbolic-ref.txt\nindex 4bc35a1..1e818bb 100644\n--- a/Documentation/git-symbolic-ref.txt\n+++ b/Documentation/git-symbolic-ref.txt\n@@ -7,7 +7,7 @@ git-symbolic-ref - read and modify symbolic refs\n \n SYNOPSIS\n --------\n-'git-symbolic-ref' <name> [<ref>]\n+'git-symbolic-ref' [-q] <name> [<ref>]\n \n DESCRIPTION\n -----------\n@@ -23,6 +23,14 @@ A symbolic ref is a regular file that stores a string that\n begins with `ref: refs/`.  For example, your `.git/HEAD` is\n a regular file whose contents is `ref: refs/heads/master`.\n \n+OPTIONS\n+-------\n+\n+-q::\n+\tDo not issue an error message if the <name> is not a\n+\tsymbolic ref but a detached HEAD; instead exit with\n+\tnon-zero status silently.\n+\n NOTES\n -----\n In the past, `.git/HEAD` was a symbolic link pointing at\ndiff --git a/builtin-symbolic-ref.c b/builtin-symbolic-ref.c\nindex d8be052..227c9d4 100644\n--- a/builtin-symbolic-ref.c\n+++ b/builtin-symbolic-ref.c\n@@ -3,9 +3,9 @@\n #include \"refs.h\"\n \n static const char git_symbolic_ref_usage[] =\n-\"git-symbolic-ref name [ref]\";\n+\"git-symbolic-ref [-q] name [ref]\";\n \n-static void check_symref(const char *HEAD)\n+static void check_symref(const char *HEAD, int quiet)\n {\n \tunsigned char sha1[20];\n \tint flag;\n@@ -13,17 +13,41 @@ static void check_symref(const char *HEAD)\n \n \tif (!refs_heads_master)\n \t\tdie(\"No such ref: %s\", HEAD);\n-\telse if (!(flag & REF_ISSYMREF))\n-\t\tdie(\"ref %s is not a symbolic ref\", HEAD);\n+\telse if (!(flag & REF_ISSYMREF)) {\n+\t\tif (!quiet)\n+\t\t\tdie(\"ref %s is not a symbolic ref\", HEAD);\n+\t\telse\n+\t\t\texit(1);\n+\t}\n \tputs(refs_heads_master);\n }\n \n int cmd_symbolic_ref(int argc, const char **argv, const char *prefix)\n {\n+\tint quiet = 0;\n+\n \tgit_config(git_default_config);\n+\n+\twhile (1 < argc) {\n+\t\tconst char *arg = argv[1];\n+\t\tif (arg[0] != '-')\n+\t\t\tbreak;\n+\t\telse if (!strcmp(\"-q\", arg))\n+\t\t\tquiet = 1;\n+\t\telse if (!strcmp(\"--\", arg)) {\n+\t\t\targc--;\n+\t\t\targv++;\n+\t\t\tbreak;\n+\t\t}\n+\t\telse\n+\t\t\tdie(\"unknown option %s\", arg);\n+\t\targc--;\n+\t\targv++;\n+\t}\n+\n \tswitch (argc) {\n \tcase 2:\n-\t\tcheck_symref(argv[1]);\n+\t\tcheck_symref(argv[1], quiet);\n \t\tbreak;\n \tcase 3:\n \t\tcreate_symref(argv[1], argv[2]);\ndiff --git a/git-parse-remote.sh b/git-parse-remote.sh\nindex d2e4c2b..4fc6020 100755\n--- a/git-parse-remote.sh\n+++ b/git-parse-remote.sh\n@@ -49,7 +49,7 @@ get_remote_url () {\n }\n \n get_default_remote () {\n-\tcurr_branch=$(git-symbolic-ref HEAD | sed -e 's|^refs/heads/||')\n+\tcurr_branch=$(git-symbolic-ref -q HEAD | sed -e 's|^refs/heads/||')\n \torigin=$(git-repo-config --get \"branch.$curr_branch.remote\")\n \techo ${origin:-origin}\n }\n@@ -137,7 +137,7 @@ canon_refs_list_for_fetch () {\n \t\tshift\n \t\tif test \"$remote\" = \"$(get_default_remote)\"\n \t\tthen\n-\t\t\tcurr_branch=$(git-symbolic-ref HEAD | \\\n+\t\t\tcurr_branch=$(git-symbolic-ref -q HEAD | \\\n \t\t\t    sed -e 's|^refs/heads/||')\n \t\t\tmerge_branches=$(git-repo-config \\\n \t\t\t    --get-all \"branch.${curr_branch}.merge\")\n"},{"id":"31771","messageId":"20070115220111.GA7933@coredump.intra.peff.net","threadId":"6385","inReplyTo":"7vzm8k0xai.fsf@assigned-by-dhcp.cox.net","subject":"Re: git-fetch while on \"(no branch)\"","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2007-01-15T22:01:11Z","receivedAt":"2007-01-15T22:01:11Z","isPatch":false,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"On Mon, Jan 15, 2007 at 01:56:05PM -0800, Junio C Hamano wrote:\n\n> -'git-symbolic-ref' <name> [<ref>]\n> +'git-symbolic-ref' [-q] <name> [<ref>]\n\nPlease ignore my patch in this thread; yours is much more sensible.\nHowever, if you do go this route, note that git-pull needs to use the\n'-q' flag as well.\n\n-Peff\n"},{"id":"31772","messageId":"7vk5zo0ws1.fsf@assigned-by-dhcp.cox.net","threadId":"6385","inReplyTo":"20070115212442.GA7409@coredump.intra.peff.net","subject":"Re: [PATCH] git-{parse-remote,pull}: throw away stderr of git-symbolic-ref","fromName":"Junio C Hamano","fromEmail":"junkio@cox.net","sentAt":"2007-01-15T22:07:10Z","receivedAt":"2007-01-15T22:07:10Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Jeff King <peff@peff.net> writes:\n\n> We look up the destination of the HEAD symref in order to get the\n> default remote and merge head for the current branch. However, if we\n> have a detached HEAD, there is no current branch. We handle this\n> situation by looking up branch..remote, which is empty.\n> Unfortunately, git-symbolic-ref complained to stderr, potentially\n> scaring users.\n\nI think what I sent out was a moral equivalent, but generally\nspeaking I do not think we should discard stderr output\nindiscriminatingly.\n\n> diff --git a/git-pull.sh b/git-pull.sh\n> index 9592617..f0cc023 100755\n> --- a/git-pull.sh\n> +++ b/git-pull.sh\n> @@ -83,7 +83,7 @@ merge_head=$(sed -e '/\tnot-for-merge\t/d' \\\n>  \n>  case \"$merge_head\" in\n>  '')\n> -\tcurr_branch=$(git-symbolic-ref HEAD | \\\n> +\tcurr_branch=$(git-symbolic-ref HEAD 2>/dev/null | \\\n>  \t\tsed -e 's|^refs/heads/||')\n>  \techo >&2 \"Warning: No merge candidate found because value of config option\n>           \\\"branch.${curr_branch}.merge\\\" does not match any remote branch fetched.\"\n\nI missed this one, but I think this needs a bit more through\nrework.  This is what happens when you say \"git pull origin\"\nwhile your HEAD is detached, and specifying \"branch..merge\" in\nthe configuration should not be the way to define the default\nremote branch to be merged while on a detached HEAD.  In fact, I\nthink there should not be any such default.\n\nI think it makes more sense to say \"your HEAD is detached and\nyou need to explicitly say which branch you would want to merge\nin\" in this case.\n"},{"id":"31777","messageId":"20070115222533.GA12928@coredump.intra.peff.net","threadId":"6385","inReplyTo":"7vk5zo0ws1.fsf@assigned-by-dhcp.cox.net","subject":"[PATCH] git-pull: disallow implicit merging to detached HEAD","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2007-01-15T22:25:33Z","receivedAt":"2007-01-15T22:25:33Z","isPatch":true,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"Instead, we complain to the user and suggest that they explicitly\nspecify the remote and branch. We depend on the exit status of\ngit-symbolic-ref, so let's go ahead and document that.\n\nSigned-off-by: Jeff King <peff@peff.net>\n---\n\nThis is on top of your other patch.\n\n> I think what I sent out was a moral equivalent, but generally\n> speaking I do not think we should discard stderr output\n> indiscriminatingly.\n\nAgreed.\n\n> I think it makes more sense to say \"your HEAD is detached and\n> you need to explicitly say which branch you would want to merge\n> in\" in this case.\n\nSomething like this?\n\n Documentation/git-symbolic-ref.txt |    4 ++++\n git-pull.sh                        |   13 +++++++++++--\n 2 files changed, 15 insertions(+), 2 deletions(-)\n\ndiff --git a/Documentation/git-symbolic-ref.txt b/Documentation/git-symbolic-ref.txt\nindex 1e818bb..fec3b4f 100644\n--- a/Documentation/git-symbolic-ref.txt\n+++ b/Documentation/git-symbolic-ref.txt\n@@ -44,6 +44,10 @@ cumbersome.  On some platforms, `ln -sf` does not even work as\n advertised (horrors).  Therefore symbolic links are now deprecated\n and symbolic refs are used by default.\n \n+git-symbolic-ref will exit with status 0 if the contents of the\n+symbolic ref were printed correctly, with status 1 if the requested\n+name is not a symbolic ref, or 128 if another error occurs.\n+\n Author\n ------\n Written by Junio C Hamano <junkio@cox.net>\ndiff --git a/git-pull.sh b/git-pull.sh\nindex 9592617..3e96569 100755\n--- a/git-pull.sh\n+++ b/git-pull.sh\n@@ -83,8 +83,17 @@ merge_head=$(sed -e '/\tnot-for-merge\t/d' \\\n \n case \"$merge_head\" in\n '')\n-\tcurr_branch=$(git-symbolic-ref HEAD | \\\n-\t\tsed -e 's|^refs/heads/||')\n+\tcurr_branch=$(git-symbolic-ref -q HEAD)\n+\tcase $? in\n+\t  0) ;;\n+\t  1) echo >&2 \"You are not currently on a branch; you must explicitly\"\n+\t     echo >&2 \"indicate which branch you wish to merge with\"\n+\t     echo >&2 \"  git pull <remote> <branch>\"\n+\t     exit 1;;\n+\t  *) exit $?;;\n+\tesac\n+\tcurr_branch=${curr_branch#refs/heads/}\n+\n \techo >&2 \"Warning: No merge candidate found because value of config option\n          \\\"branch.${curr_branch}.merge\\\" does not match any remote branch fetched.\"\n \techo >&2 \"No changes.\"\n-- \n1.5.0.rc1.gb329-dirty\n"},{"id":"31779","messageId":"20070115222854.GA12950@coredump.intra.peff.net","threadId":"6385","inReplyTo":"20070115222533.GA12928@coredump.intra.peff.net","subject":"Re: [PATCH] git-pull: disallow implicit merging to detached HEAD","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2007-01-15T22:28:54Z","receivedAt":"2007-01-15T22:28:54Z","isPatch":true,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"On Mon, Jan 15, 2007 at 05:25:33PM -0500, Jeff King wrote:\n\n> +\t  1) echo >&2 \"You are not currently on a branch; you must explicitly\"\n> +\t     echo >&2 \"indicate which branch you wish to merge with\"\n> +\t     echo >&2 \"  git pull <remote> <branch>\"\n\nUrgh. Apparently using --amend is too challenging for me. I think it is\nslightly clearer for the second line to read:\n  \"specify which branch you wish to merge:\"\n\n-Peff\n"}]}