{"thread":{"id":"47271","subject":"[PATCH] rebase: rebasing can also be done when HEAD is detached","startedAt":"2017-11-21T15:26:36Z","lastAt":"2017-12-16T09:04:41Z","messageCount":18,"participants":["Kaartic Sivaraam","Junio C Hamano"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"333100","messageId":"20171121152533.3793-1-kaartic.sivaraam@gmail.com","threadId":"47271","inReplyTo":null,"subject":"[PATCH] rebase: rebasing can also be done when HEAD is detached","fromName":"Kaartic Sivaraam","fromEmail":"kaartic.sivaraam@gmail.com","sentAt":"2017-11-21T15:25:33Z","receivedAt":"2017-11-21T15:26:36Z","isPatch":true,"sender":{"key":"kaartic.sivaraam@gmail.com","avatar":"https://avatars.githubusercontent.com/u/12448084?v=4"},"body":"In a repository when attempting to rebase when the HEAD is detached\nand it is already up to date with upstream (so there's nothing to do),\nthe following message is shown\n\n        Current branch HEAD is up to date.\n\nwhich is clearly wrong as HEAD is not a branch.\n\nHandle the special case of HEAD correctly to give a more precise\nerror message.\n\nSigned-off-by: Kaartic Sivaraam <kaartic.sivaraam@gmail.com>\n---\n In this patch, I basically assumed that there would be no\n branch named \"HEAD\". To the cotrary if it did, it would make\n 'git' throw spurious ambiguity messages, in general. So, I\n guess it's not worth trying to check if HEAD is a branch or\n not and handle that specially.\n\n git-rebase.sh | 14 ++++++++++++--\n 1 file changed, 12 insertions(+), 2 deletions(-)\n\ndiff --git a/git-rebase.sh b/git-rebase.sh\nindex 6344e8d5e..933df832a 100755\n--- a/git-rebase.sh\n+++ b/git-rebase.sh\n@@ -598,11 +598,21 @@ then\n \t\ttest -z \"$switch_to\" ||\n \t\tGIT_REFLOG_ACTION=\"$GIT_REFLOG_ACTION: checkout $switch_to\" \\\n \t\t\tgit checkout -q \"$switch_to\" --\n-\t\tsay \"$(eval_gettext \"Current branch \\$branch_name is up to date.\")\"\n+\t\tif test \"$branch_name\" = \"HEAD\"\n+\t\tthen\n+\t\t\tsay \"$(eval_gettext \"HEAD is up to date.\")\"\n+\t\telse\n+\t\t\tsay \"$(eval_gettext \"Current branch \\$branch_name is up to date.\")\"\n+\t\tfi\n \t\tfinish_rebase\n \t\texit 0\n \telse\n-\t\tsay \"$(eval_gettext \"Current branch \\$branch_name is up to date, rebase forced.\")\"\n+\t\tif test \"$branch_name\" = \"HEAD\"\n+\t\tthen\n+\t\t\tsay \"$(eval_gettext \"HEAD is up to date, rebase forced.\")\"\n+\t\telse\n+\t\t\tsay \"$(eval_gettext \"Current branch \\$branch_name is up to date, rebase forced.\")\"\n+\t\tfi\n \tfi\n fi\n \n-- \n2.15.0.345.gf926f18f3\n\n"},{"id":"333222","messageId":"xmqq60a3xdpw.fsf@gitster.mtv.corp.google.com","threadId":"47271","inReplyTo":"20171121152533.3793-1-kaartic.sivaraam@gmail.com","subject":"Re: [PATCH] rebase: rebasing can also be done when HEAD is detached","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2017-11-22T02:13:31Z","receivedAt":"2017-11-22T02:13:37Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Kaartic Sivaraam <kaartic.sivaraam@gmail.com> writes:\n\n> In a repository when attempting to rebase when the HEAD is detached\n> and it is already up to date with upstream (so there's nothing to do),\n> the following message is shown\n>\n>         Current branch HEAD is up to date.\n>\n> which is clearly wrong as HEAD is not a branch.\n>\n> Handle the special case of HEAD correctly to give a more precise\n> error message.\n>\n> Signed-off-by: Kaartic Sivaraam <kaartic.sivaraam@gmail.com>\n> ---\n>  In this patch, I basically assumed that there would be no\n>  branch named \"HEAD\".\n\nPerhaps time to learn \"git symbolic-ref HEAD\" and use it instead of\ndepending on the name?\n"},{"id":"333616","messageId":"20171127172104.5796-1-kaartic.sivaraam@gmail.com","threadId":"47271","inReplyTo":"xmqq60a3xdpw.fsf@gitster.mtv.corp.google.com","subject":"[PATCH v2 0/3] rebase: give precise error message","fromName":"Kaartic Sivaraam","fromEmail":"kaartic.sivaraam@gmail.com","sentAt":"2017-11-27T17:21:01Z","receivedAt":"2017-11-27T17:21:40Z","isPatch":true,"sender":{"key":"kaartic.sivaraam@gmail.com","avatar":"https://avatars.githubusercontent.com/u/12448084?v=4"},"body":"Junio C Hamano <gitster@pobox.com> writes:\n> Perhaps time to learn \"git symbolic-ref HEAD\" and use it instead of\n> depending on the name?\n\nGood point. Helped remove the assumption that there's no branch named HEAD.\n(and indirectly led to 2 additional patches and the 3 questions found below ;-)\n\n\nThis started as a small fix to make 'git rebase' give a precise\nerror message when a rebase was done with a detached HEAD. Now it\nincludes a few cleanups that I caught while analysing the code.\n\nThere were a few weird observations when I was anlaysing the code.\nThey are listed below. Please give your thoughts about them.\n\nThe commands I use below were run on my local clone of 'git' and 'origin'\nin this context refers to the git mirror at GitHub.\n\n1. \"git rebase <upstream> <remote_branch>\" does nothing\n\nI tried to play around with rebase by trying out various combinations while\nanalysing and found the following to have not effect even though the output\ndoesn't say anything about that,\n\n$ git rebase origin/next origin/maint \nFirst, rewinding head to replay your work on top of it...\nFast-forwarded origin/maint to origin/next.\n\nIOW, updating a remote branch with a remote upstream had no effect.\nThough trying to update a remote branch with a remote upstream doesn't\nseem to be very meaningful, the output says it HAS updated the remote\nwhich seems to be misleading. What should be done about this?\n\n2. It's possible to do \"git rebase <upstream> <commit>\"\n\n$ git origin/next f926f18f3dda0c52e794b2de0911f1b046c7dadf\"\n\nThis checks out the commit(detaches HEAD) tries to rebase origin/next\nfrom there.\n\nThis behaviour doesn't seems to be documented. It says that only a 'branch'\ncan be specified. (The error message updated in 1/3 previously reported that\nthe 'branch' name is invalid rather than stating the 'ref (branch/commit) is\ninvlid')\n\n git rebase [...] [<upstream> [<branch>]]\n git rebase [...] --root [<branch>]\n ...\n\nShouldn't it have said that we can give any <ref> apart from <branch> instead of\nsaying we could give only a <branch>. If intentional, why?\n\n3. \"git rebase <upstream> <commit>\" shows misleading message\n\n$ git origin/next f926f18f3dda0c52e794b2de0911f1b046c7dadf\"\nCurrent branch f926f18f3dda0c52e794b2de0911f1b046c7dadf is up to date.\n\nAs it's clear the commit is not a branch. What should be done to fix this?\n\n\nKaartic Sivaraam (3):\n  rebase: use a more appropriate variable name\n  rebase: distinguish user input by quoting it\n  rebase: rebasing can also be done when HEAD is detached\n\n git-rebase.sh | 46 +++++++++++++++++++++++++++++++---------------\n 1 file changed, 31 insertions(+), 15 deletions(-)\n\n-- \n2.15.0.345.gf926f18f3\n\n"},{"id":"333617","messageId":"20171127172104.5796-2-kaartic.sivaraam@gmail.com","threadId":"47271","inReplyTo":"20171127172104.5796-1-kaartic.sivaraam@gmail.com","subject":"[PATCH v2 1/3] rebase: use a more appropriate variable name","fromName":"Kaartic Sivaraam","fromEmail":"kaartic.sivaraam@gmail.com","sentAt":"2017-11-27T17:21:02Z","receivedAt":"2017-11-27T17:21:42Z","isPatch":true,"sender":{"key":"kaartic.sivaraam@gmail.com","avatar":"https://avatars.githubusercontent.com/u/12448084?v=4"},"body":"The variable name \"branch_name\" used to indicate the <branch> parameter\nin \"git rebase <upstream> <branch>\" is misleading as it seems to indicate\nthat it holds only a \"branch name\" although at times it might actually hold\nany valid <ref> (branch/commit).\n\nSo, use a more suitable name for that variable.\n\nSigned-off-by: Kaartic Sivaraam <kaartic.sivaraam@gmail.com>\n---\n git-rebase.sh | 32 ++++++++++++++++++--------------\n 1 file changed, 18 insertions(+), 14 deletions(-)\n\ndiff --git a/git-rebase.sh b/git-rebase.sh\nindex 6344e8d5e..a675cf691 100755\n--- a/git-rebase.sh\n+++ b/git-rebase.sh\n@@ -518,36 +518,40 @@ case \"$onto_name\" in\n esac\n \n # If the branch to rebase is given, that is the branch we will rebase\n-# $branch_name -- branch being rebased, or HEAD (already detached)\n+# $branch_or_commit -- branch/commit being rebased, or HEAD (already detached)\n # $orig_head -- commit object name of tip of the branch before rebasing\n # $head_name -- refs/heads/<that-branch> or \"detached HEAD\"\n switch_to=\n case \"$#\" in\n 1)\n \t# Is it \"rebase other $branchname\" or \"rebase other $commit\"?\n-\tbranch_name=\"$1\"\n+\tbranch_or_commit=\"$1\"\n \tswitch_to=\"$1\"\n \n-\tif git show-ref --verify --quiet -- \"refs/heads/$1\" &&\n-\t   orig_head=$(git rev-parse -q --verify \"refs/heads/$1\")\n+\t# Is it a local branch?\n+\tif git show-ref --verify --quiet -- \"refs/heads/$branch_or_commit\" &&\n+\t   orig_head=$(git rev-parse -q --verify \"refs/heads/$branch_or_commit\")\n \tthen\n-\t\thead_name=\"refs/heads/$1\"\n-\telif orig_head=$(git rev-parse -q --verify \"$1\")\n+\t\thead_name=\"refs/heads/$branch_or_commit\"\n+\n+\t# If not is it a valid ref (branch or commit)?\n+\telif orig_head=$(git rev-parse -q --verify \"$branch_or_commit\")\n \tthen\n \t\thead_name=\"detached HEAD\"\n+\n \telse\n-\t\tdie \"$(eval_gettext \"fatal: no such branch: \\$branch_name\")\"\n+\t\tdie \"$(eval_gettext \"fatal: no such branch/commit: \\$branch_or_commit\")\"\n \tfi\n \t;;\n 0)\n \t# Do not need to switch branches, we are already on it.\n-\tif branch_name=$(git symbolic-ref -q HEAD)\n+\tif branch_or_commit=$(git symbolic-ref -q HEAD)\n \tthen\n-\t\thead_name=$branch_name\n-\t\tbranch_name=$(expr \"z$branch_name\" : 'zrefs/heads/\\(.*\\)')\n+\t\thead_name=$branch_or_commit\n+\t\tbranch_or_commit=$(expr \"z$branch_or_commit\" : 'zrefs/heads/\\(.*\\)')\n \telse\n \t\thead_name=\"detached HEAD\"\n-\t\tbranch_name=HEAD ;# detached\n+\t\tbranch_or_commit=\"HEAD\"\n \tfi\n \torig_head=$(git rev-parse --verify HEAD) || exit\n \t;;\n@@ -598,11 +602,11 @@ then\n \t\ttest -z \"$switch_to\" ||\n \t\tGIT_REFLOG_ACTION=\"$GIT_REFLOG_ACTION: checkout $switch_to\" \\\n \t\t\tgit checkout -q \"$switch_to\" --\n-\t\tsay \"$(eval_gettext \"Current branch \\$branch_name is up to date.\")\"\n+\t\tsay \"$(eval_gettext \"Current branch \\$branch_or_commit is up to date.\")\"\n \t\tfinish_rebase\n \t\texit 0\n \telse\n-\t\tsay \"$(eval_gettext \"Current branch \\$branch_name is up to date, rebase forced.\")\"\n+\t\tsay \"$(eval_gettext \"Current branch \\$branch_or_commit is up to date, rebase forced.\")\"\n \tfi\n fi\n \n@@ -632,7 +636,7 @@ git update-ref ORIG_HEAD $orig_head\n # we just fast-forwarded.\n if test \"$mb\" = \"$orig_head\"\n then\n-\tsay \"$(eval_gettext \"Fast-forwarded \\$branch_name to \\$onto_name.\")\"\n+\tsay \"$(eval_gettext \"Fast-forwarded \\$branch_or_commit to \\$onto_name.\")\"\n \tmove_to_original_branch\n \tfinish_rebase\n \texit 0\n-- \n2.15.0.345.gf926f18f3\n\n"},{"id":"333618","messageId":"20171127172104.5796-3-kaartic.sivaraam@gmail.com","threadId":"47271","inReplyTo":"20171127172104.5796-1-kaartic.sivaraam@gmail.com","subject":"[PATCH v2 2/3] rebase: distinguish user input by quoting it","fromName":"Kaartic Sivaraam","fromEmail":"kaartic.sivaraam@gmail.com","sentAt":"2017-11-27T17:21:03Z","receivedAt":"2017-11-27T17:21:48Z","isPatch":true,"sender":{"key":"kaartic.sivaraam@gmail.com","avatar":"https://avatars.githubusercontent.com/u/12448084?v=4"},"body":"Signed-off-by: Kaartic Sivaraam <kaartic.sivaraam@gmail.com>\n---\n git-rebase.sh | 4 ++--\n 1 file changed, 2 insertions(+), 2 deletions(-)\n\ndiff --git a/git-rebase.sh b/git-rebase.sh\nindex a675cf691..3f8d99e99 100755\n--- a/git-rebase.sh\n+++ b/git-rebase.sh\n@@ -477,7 +477,7 @@ then\n \t\t;;\n \tesac\n \tupstream=$(peel_committish \"${upstream_name}\") ||\n-\tdie \"$(eval_gettext \"invalid upstream \\$upstream_name\")\"\n+\tdie \"$(eval_gettext \"invalid upstream '\\$upstream_name'\")\"\n \tupstream_arg=\"$upstream_name\"\n else\n \tif test -z \"$onto\"\n@@ -540,7 +540,7 @@ case \"$#\" in\n \t\thead_name=\"detached HEAD\"\n \n \telse\n-\t\tdie \"$(eval_gettext \"fatal: no such branch/commit: \\$branch_or_commit\")\"\n+\t\tdie \"$(eval_gettext \"fatal: no such branch/commit '\\$branch_or_commit'\")\"\n \tfi\n \t;;\n 0)\n-- \n2.15.0.345.gf926f18f3\n\n"},{"id":"333619","messageId":"20171127172104.5796-4-kaartic.sivaraam@gmail.com","threadId":"47271","inReplyTo":"20171127172104.5796-1-kaartic.sivaraam@gmail.com","subject":"[PATCH v2 3/3] rebase: rebasing can also be done when HEAD is detached","fromName":"Kaartic Sivaraam","fromEmail":"kaartic.sivaraam@gmail.com","sentAt":"2017-11-27T17:21:04Z","receivedAt":"2017-11-27T17:21:50Z","isPatch":true,"sender":{"key":"kaartic.sivaraam@gmail.com","avatar":"https://avatars.githubusercontent.com/u/12448084?v=4"},"body":"Attempting to rebase when the HEAD is detached and is already\nup to date with upstream (so there's nothing to do), the\nfollowing message is shown\n\n        Current branch HEAD is up to date.\n\nwhich is clearly wrong as HEAD is not a branch.\n\nHandle the special case of HEAD correctly to give a more precise\nerror message.\n\nSigned-off-by: Kaartic Sivaraam <kaartic.sivaraam@gmail.com>\n---\n\n git-rebase.sh | 16 ++++++++++++++--\n 1 file changed, 14 insertions(+), 2 deletions(-)\n\ndiff --git a/git-rebase.sh b/git-rebase.sh\nindex 3f8d99e99..9cce1483a 100755\n--- a/git-rebase.sh\n+++ b/git-rebase.sh\n@@ -602,11 +602,23 @@ then\n \t\ttest -z \"$switch_to\" ||\n \t\tGIT_REFLOG_ACTION=\"$GIT_REFLOG_ACTION: checkout $switch_to\" \\\n \t\t\tgit checkout -q \"$switch_to\" --\n-\t\tsay \"$(eval_gettext \"Current branch \\$branch_or_commit is up to date.\")\"\n+\t\tif test \"$branch_or_commit\" = \"HEAD\" &&\n+\t\t\t !(git symbolic-ref -q HEAD)\n+\t\tthen\n+\t\t\tsay \"$(eval_gettext \"HEAD is up to date.\")\"\n+\t\telse\n+\t\t\tsay \"$(eval_gettext \"Current branch \\$branch_or_commit is up to date.\")\"\n+\t\tfi\n \t\tfinish_rebase\n \t\texit 0\n \telse\n-\t\tsay \"$(eval_gettext \"Current branch \\$branch_or_commit is up to date, rebase forced.\")\"\n+\t\tif test \"$branch_or_commit\" = \"HEAD\" &&\n+\t\t\t !(git symbolic-ref -q HEAD)\n+\t\tthen\n+\t\t\tsay \"$(eval_gettext \"HEAD is up to date, rebase forced.\")\"\n+\t\telse\n+\t\t\tsay \"$(eval_gettext \"Current branch \\$branch_or_commit is up to date, rebase forced.\")\"\n+\t\tfi\n \tfi\n fi\n \n-- \n2.15.0.345.gf926f18f3\n\n"},{"id":"333668","messageId":"xmqqpo8387hz.fsf@gitster.mtv.corp.google.com","threadId":"47271","inReplyTo":"20171127172104.5796-1-kaartic.sivaraam@gmail.com","subject":"Re: [PATCH v2 0/3] rebase: give precise error message","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2017-11-28T02:25:12Z","receivedAt":"2017-11-28T02:25:18Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Kaartic Sivaraam <kaartic.sivaraam@gmail.com> writes:\n\n> 1. \"git rebase <upstream> <remote_branch>\" does nothing\n\nNot limited to \"rebase\", you do not muck with remote-tracking branch\nin your local repository, so it would be a bug if the above updated\nwhere the remote-tracking branch points at.\n\nThe form of \"git rebase\" with one extra argument (i.e. not rebasing\nthe history that leads to the current checkout) is mere shorthand of\nchecking that extra thing out before doing the rebase, i.e.\n\n\t$ git rebase origin/next origin/maint\n\nfirst checks out origin/maint (you'd get on a detached HEAD) and\nrebase the history leading to the detached HEAD on top of\norigin/next.  If it fast-forwards (and it should if you are talking\nabout 'maint' and 'next' I publish), you'll end up sitting on a\ndetached HEAD that points at origin/next.\n\nThere is nothing to see here.\n\n> 2. It's possible to do \"git rebase <upstream> <commit>\"\n\nAgain, that's designed behaviour you can trigger by giving <commit>\n(not <branch>).  Very handy when you do not trust your upstream or\nyourself's ability to resolve potential conflicts as a trial run\nbefore really committing to perform the rebase, e.g.\n\n\t$ git rebase origin master^0\n\n"},{"id":"333669","messageId":"xmqqlgir8770.fsf@gitster.mtv.corp.google.com","threadId":"47271","inReplyTo":"20171127172104.5796-4-kaartic.sivaraam@gmail.com","subject":"Re: [PATCH v2 3/3] rebase: rebasing can also be done when HEAD is detached","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2017-11-28T02:31:47Z","receivedAt":"2017-11-28T02:31:54Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Kaartic Sivaraam <kaartic.sivaraam@gmail.com> writes:\n\n> +\t\tif test \"$branch_or_commit\" = \"HEAD\" &&\n> +\t\t\t !(git symbolic-ref -q HEAD)\n\nDid you need a subshell here?  Now with a proper test with\n\"symbolic-ref -q HEAD\", I wonder if you'd need to check if the\noriginal was named HEAD in the first place (I do not feel strongly\nenough to say that checking is wrong, at least not yet, but the\nabove does make me wonder), and instead something like\n\n\tif ! git symbolic-ref -q HEAD\n\tthen\n\t\t...\n\nmight be sufficient.  I dunno.\n\nI find what 2/3 and 3/3 want to do quite sensible.  They depend on\n1/3, which I find is more a needless churn than a clean-up, which is\nunfortunate, though.\n\nThanks.\n"},{"id":"333688","messageId":"1511877882.10193.2.camel@gmail.com","threadId":"47271","inReplyTo":"xmqqpo8387hz.fsf@gitster.mtv.corp.google.com","subject":"Re: [PATCH v2 0/3] rebase: give precise error message","fromName":"Kaartic Sivaraam","fromEmail":"kaartic.sivaraam@gmail.com","sentAt":"2017-11-28T14:04:42Z","receivedAt":"2017-11-28T14:04:57Z","isPatch":true,"sender":{"key":"kaartic.sivaraam@gmail.com","avatar":"https://avatars.githubusercontent.com/u/12448084?v=4"},"body":"On Tue, 2017-11-28 at 11:25 +0900, Junio C Hamano wrote:\n> Kaartic Sivaraam <kaartic.sivaraam@gmail.com> writes:\n> \n> > 1. \"git rebase <upstream> <remote_branch>\" does nothing\n> \n> Not limited to \"rebase\", you do not muck with remote-tracking branch\n> in your local repository, so it would be a bug if the above updated\n> where the remote-tracking branch points at.\n> \n> The form of \"git rebase\" with one extra argument (i.e. not rebasing\n> the history that leads to the current checkout) is mere shorthand of\n> checking that extra thing out before doing the rebase, i.e.\n> \n> \t$ git rebase origin/next origin/maint\n> \n> first checks out origin/maint (you'd get on a detached HEAD) and\n> rebase the history leading to the detached HEAD on top of\n> origin/next.  If it fast-forwards (and it should if you are talking\n> about 'maint' and 'next' I publish), you'll end up sitting on a\n> detached HEAD that points at origin/next.\n> \n> There is nothing to see here.\n> \n\nYou're right. It was my mistake. It seems I didn't notice that I was\nalready on 'origin/next' before I did,\n\n \t$ git rebase origin/next origin/maint\n\nSo (obviously) I thought it did nothing, sorry.\n\n\n> > 2. It's possible to do \"git rebase <upstream> <commit>\"\n> \n> Again, that's designed behaviour you can trigger by giving <commit>\n> (not <branch>).  Very handy when you do not trust your upstream or\n> yourself's ability to resolve potential conflicts as a trial run\n> before really committing to perform the rebase, e.g.\n> \n> \t$ git rebase origin master^0\n> \n\nI can't comment about usefulness as I haven't used rebase in this way\nbut I'm pretty sure that this should be mentioned in the\n\"Documentation\" to help those might be in bare need of syntax like this\nto discover it.\n\nSomething like the following diff with additional changes to other\nplaces that refer to <branch>,\n\ndiff --git a/Documentation/git-rebase.txt b/Documentation/git-rebase.txt\nindex 67d48e688..ba4a545bf 100644\n--- a/Documentation/git-rebase.txt\n+++ b/Documentation/git-rebase.txt\n@@ -9,9 +9,9 @@ SYNOPSIS\n --------\n [verse]\n 'git rebase' [-i | --interactive] [options] [--exec <cmd>] [--onto <newbase>]\n-       [<upstream> [<branch>]]\n+       [<upstream> [<ref>]]\n 'git rebase' [-i | --interactive] [options] [--exec <cmd>] [--onto <newbase>]\n-       --root [<branch>]\n+       --root [<ref>]\n 'git rebase' --continue | --skip | --abort | --quit | --edit-todo\n \n DESCRIPTION\n\n\nIf <ref> is the correct substitute <branch>, I could try to send a\npatch that fixes this.\n\n\n-- \nKaartic\n"},{"id":"333700","messageId":"1511885730.10193.8.camel@gmail.com","threadId":"47271","inReplyTo":"xmqqlgir8770.fsf@gitster.mtv.corp.google.com","subject":"Re: [PATCH v2 3/3] rebase: rebasing can also be done when HEAD is detached","fromName":"Kaartic Sivaraam","fromEmail":"kaartic.sivaraam@gmail.com","sentAt":"2017-11-28T16:15:30Z","receivedAt":"2017-11-28T17:16:42Z","isPatch":true,"sender":{"key":"kaartic.sivaraam@gmail.com","avatar":"https://avatars.githubusercontent.com/u/12448084?v=4"},"body":"On Tue, 2017-11-28 at 11:31 +0900, Junio C Hamano wrote:\n> Kaartic Sivaraam <kaartic.sivaraam@gmail.com> writes:\n> \n> > +\t\tif test \"$branch_or_commit\" = \"HEAD\" &&\n> > +\t\t\t !(git symbolic-ref -q HEAD)\n> \n> Did you need a subshell here? \n\nNo. That's a consequence of me not remembering that I would span a sub-\nshell with a simple '()' when I was doing that part. (partial\ntransition from C to shell)\n\n\n>  Now with a proper test with\n> \"symbolic-ref -q HEAD\", I wonder if you'd need to check if the\n> original was named HEAD in the first place (I do not feel strongly\n> enough to say that checking is wrong, at least not yet, but the\n> above does make me wonder), and instead something like\n> \n> \tif ! git symbolic-ref -q HEAD\n> \tthen\n> \t\t...\n> \n> might be sufficient.  I dunno.\n> \n\nIt does  seem you're right. The only thing we would be losing is the\nshort-circuiting when $branch_or_commit is not HEAD (which I suspect to\nbe the case most of the time). So, I'm not sure if I should remove the\ncheck (of course, I'll change the check to avoid spawning a sub-shell).\n\n\nThanks, \nKaartic\n"},{"id":"333713","messageId":"xmqqzi7654hx.fsf@gitster.mtv.corp.google.com","threadId":"47271","inReplyTo":"1511877882.10193.2.camel@gmail.com","subject":"Re: [PATCH v2 0/3] rebase: give precise error message","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2017-11-29T00:10:34Z","receivedAt":"2017-11-29T00:10:43Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Kaartic Sivaraam <kaartic.sivaraam@gmail.com> writes:\n\n> Something like the following diff with additional changes to other\n> places that refer to <branch>,\n>\n> diff --git a/Documentation/git-rebase.txt b/Documentation/git-rebase.txt\n> index 67d48e688..ba4a545bf 100644\n> --- a/Documentation/git-rebase.txt\n> +++ b/Documentation/git-rebase.txt\n> @@ -9,9 +9,9 @@ SYNOPSIS\n>  --------\n>  [verse]\n>  'git rebase' [-i | --interactive] [options] [--exec <cmd>] [--onto <newbase>]\n> -       [<upstream> [<branch>]]\n> +       [<upstream> [<ref>]]\n>  'git rebase' [-i | --interactive] [options] [--exec <cmd>] [--onto <newbase>]\n> -       --root [<branch>]\n> +       --root [<ref>]\n>  'git rebase' --continue | --skip | --abort | --quit | --edit-todo\n>  \n>  DESCRIPTION\n>\n>\n> If <ref> is the correct substitute <branch>, I could try to send a\n> patch that fixes this.\n\nI do not think the above is a good change in the first place for at\nleast two reasons.  By saying <ref>, the updated text says \"not just\nbranches but you can also give tags and remote-tracking branches\".\nIn reality, however, it can take any commit-ish, as the \"no we are\nnot rebasing the current checkout\" form of the command is merely a\nshort-hand to check it out first [*1*].  It gives appearance that\nthe change is making it more broad, but not making it broad enough.\nAt the same time, more than 90% of the time, people give a branch\nname there.  Saying \"branch-or-commit\" for a short description of\nthe command line (which is what synopsis section is) does not add\nthat much value.  The body text of the description where we refer to\nthe <branch> parameter of course need to be updated to say \"in\naddition, instead of a branch name, you can give a commit-ish that\nis *not* a branch name.  When you do so, instead of checking out the\nbranch, the HEAD is detached at that commit before the history\nleading to it is rebased.\"\n\nAnd because we have to say \"it can be a non-branch commit-ish and\nhere is what happens when you do so\" anyway, I think the current\nsynopsis as-is would be better than making it less clear and more\nscary by replacing <branch> with other things like <commit-ish> or\n[<branch> | <commit-ish>].\n\n\n[Footnote]\n\n*1* As my \"log --first-parent --oneline master..pu\" is a strand of\n    pearls each of which is a merge of a topic branch,\n\n    $ git rebase -i master pu~$n^2\n\n    can be a handy way to make a trial rebase (after double checking\n    the result of \"git tbdiff\", I may do \"git checkout -B topic\" to\n    overwrite the original or I may discard the result of rebasing).\n"},{"id":"333765","messageId":"1511925118.2486.2.camel@gmail.com","threadId":"47271","inReplyTo":"xmqqzi7654hx.fsf@gitster.mtv.corp.google.com","subject":"Re: [PATCH v2 0/3] rebase: give precise error message","fromName":"Kaartic Sivaraam","fromEmail":"kaartic.sivaraam@gmail.com","sentAt":"2017-11-29T03:11:58Z","receivedAt":"2017-11-29T03:12:10Z","isPatch":true,"sender":{"key":"kaartic.sivaraam@gmail.com","avatar":"https://avatars.githubusercontent.com/u/12448084?v=4"},"body":"On Wed, 2017-11-29 at 09:10 +0900, Junio C Hamano wrote:\n> Kaartic Sivaraam <kaartic.sivaraam@gmail.com> writes:\n> \n> > If <ref> is the correct substitute <branch>, I could try to send a\n> > patch that fixes this.\n> \n> I do not think the above is a good change in the first place for at\n> least two reasons.  By saying <ref>, the updated text says \"not just\n> branches but you can also give tags and remote-tracking branches\".\n\nI used <ref> as you could actually use tags, remote-tracking branches\nand even \"notes\" (i.e.) any kind of <ref> for the <branch> part. That's\nhow the code for rebasing works currently (specifically the elif part),\n\n\tif git show-ref --verify --quiet -- \"refs/heads/$1\" &&\n\t   orig_head=$(git rev-parse -q --verify \"refs/heads/$1\")\n\tthen\n\t\thead_name=\"refs/heads/$1\"\n\telif orig_head=$(git rev-parse -q --verify \"$1\")\n\tthen\n\t\thead_name=\"detached HEAD\"\n\telse\n\t\tdie \"$(eval_gettext \"fatal: no such branch: \\$branch_name\")\"\n\tfi\n\nWhich means that you could not only do,\n\n\t$ git rebase origin/next refs/remotes/origin/maint\n\nYou could even get creative and do,\n\n\t$ git rebase origin/next refs/notes/$something\n\nIt just works (of course, I couldn't understand what it did)! I didn't\nwant to lie to the user. So, I used <ref>. So, should we just update\nthe <branch> part of the doc or should we update the code for 'rebase'?\nI'm unsure.\n\n> In reality, however, it can take any commit-ish, as the \"no we are\n> not rebasing the current checkout\" form of the command is merely a\n> short-hand to check it out first [*1*].  It gives appearance that\n> the change is making it more broad, but not making it broad enough.\n> At the same time, more than 90% of the time, people give a branch\n> name there.  Saying \"branch-or-commit\" for a short description of\n> the command line (which is what synopsis section is) does not add\n> that much value.  The body text of the description where we refer to\n> the <branch> parameter of course need to be updated to say \"in\n> addition, instead of a branch name, you can give a commit-ish that\n> is *not* a branch name.  When you do so, instead of checking out the\n> branch, the HEAD is detached at that commit before the history\n> leading to it is rebased.\"\n> \n> And because we have to say \"it can be a non-branch commit-ish and\n> here is what happens when you do so\" anyway, I think the current\n> synopsis as-is would be better than making it less clear and more\n> scary by replacing <branch> with other things like <commit-ish> or\n> [<branch> | <commit-ish>].\n> \n> \n> [Footnote]\n> \n> *1* As my \"log --first-parent --oneline master..pu\" is a strand of\n>     pearls each of which is a merge of a topic branch,\n> \n>     $ git rebase -i master pu~$n^2\n> \n>     can be a handy way to make a trial rebase (after double checking\n>     the result of \"git tbdiff\", I may do \"git checkout -B topic\" to\n>     overwrite the original or I may discard the result of rebasing).\n\n"},{"id":"333772","messageId":"xmqqshcx4m54.fsf@gitster.mtv.corp.google.com","threadId":"47271","inReplyTo":"1511925118.2486.2.camel@gmail.com","subject":"Re: [PATCH v2 0/3] rebase: give precise error message","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2017-11-29T06:47:03Z","receivedAt":"2017-11-29T06:47:11Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Kaartic Sivaraam <kaartic.sivaraam@gmail.com> writes:\n\n>> I do not think the above is a good change in the first place for at\n>> least two reasons.  By saying <ref>, the updated text says \"not just\n>> branches but you can also give tags and remote-tracking branches\".\n>\n> I used <ref> as you could actually use tags, remote-tracking branches\n> and even \"notes\" ...\n> ...\n> It just works (of course, I couldn't understand what it did)! I didn't\n> want to lie to the user. So, I used <ref>. So, should we just update\n> the <branch> part of the doc or should we update the code for 'rebase'?\n> I'm unsure.\n\nBy saying <ref>, you are not covering these cases\n\n\tgit rebase master HEAD^0\n\tgit rebase master pu^2\n\nwhere the command gets non refs.\n\nMost of the time, people use a <branch>, and rare cases like these\nwhat a user can give is not restricted to a <ref>, so there is *no*\nvalue in replacing <branch> with <ref>.  If we needed to replace it\nwith something, replacing <branch> with [<branch> | <commit-ish>] is\nnot wrong per-se, but I do not think it is an improvement.\n\nAs <branch> is merely a kind of <commit-ish>, it may be tempting to\ninstead replace <branch> with <commit-ish>, but I do not think it is\na good idea, either.  No matter what you write there in the synopsis\n(and let's call it X), the description would have to say \"when X is\nthe name of a branch, that branch is checked out, its history gets\nrebased, and at the end, the tip of that branch points at the\nresult.  When X is not a branch but just a commit-ish, the HEAD is\ndetached at that commit, its history gets rebased and you'll be left\nin that state\".  Having <branch> in that sentence is clear enough\nand any intelligent reader would understand what we mean by that\nnotation: we are showing there can be various things that can come\non the command line depicted in the SYNOPSIS section at the point\nwhere we have a placeholder called <branch>, and the argument does\nnot necessarily have to be the name of a branch.\n\n\n"},{"id":"333902","messageId":"20171201060935.19749-1-kaartic.sivaraam@gmail.com","threadId":"47271","inReplyTo":"xmqqlgir8770.fsf@gitster.mtv.corp.google.com","subject":"[PATCH v3 3/3] rebase: rebasing can also be done when HEAD is detached","fromName":"Kaartic Sivaraam","fromEmail":"kaartic.sivaraam@gmail.com","sentAt":"2017-12-01T06:09:35Z","receivedAt":"2017-12-01T06:10:13Z","isPatch":true,"sender":{"key":"kaartic.sivaraam@gmail.com","avatar":"https://avatars.githubusercontent.com/u/12448084?v=4"},"body":"Attempting to rebase when the HEAD is detached and is already\nup to date with upstream (so there's nothing to do), the\nfollowing message is shown\n\n        Current branch HEAD is up to date.\n\nwhich is clearly wrong as HEAD is not a branch.\n\nHandle the special case of HEAD correctly to give a more precise\nerror message.\n\nSigned-off-by: Kaartic Sivaraam <kaartic.sivaraam@gmail.com>\n---\n\nChanges in v2:\n\n\t- avoided unnecesarily spawning a subshell in a conditional\n\n\n git-rebase.sh | 16 ++++++++++++++--\n 1 file changed, 14 insertions(+), 2 deletions(-)\n\ndiff --git a/git-rebase.sh b/git-rebase.sh\nindex 3f8d99e99..1886167e0 100755\n--- a/git-rebase.sh\n+++ b/git-rebase.sh\n@@ -602,11 +602,23 @@ then\n \t\ttest -z \"$switch_to\" ||\n \t\tGIT_REFLOG_ACTION=\"$GIT_REFLOG_ACTION: checkout $switch_to\" \\\n \t\t\tgit checkout -q \"$switch_to\" --\n-\t\tsay \"$(eval_gettext \"Current branch \\$branch_or_commit is up to date.\")\"\n+\t\tif test \"$branch_or_commit\" = \"HEAD\" &&\n+\t\t\t ! git symbolic-ref -q HEAD\n+\t\tthen\n+\t\t\tsay \"$(eval_gettext \"HEAD is up to date.\")\"\n+\t\telse\n+\t\t\tsay \"$(eval_gettext \"Current branch \\$branch_or_commit is up to date.\")\"\n+\t\tfi\n \t\tfinish_rebase\n \t\texit 0\n \telse\n-\t\tsay \"$(eval_gettext \"Current branch \\$branch_or_commit is up to date, rebase forced.\")\"\n+\t\tif test \"$branch_or_commit\" = \"HEAD\" &&\n+\t\t\t ! git symbolic-ref -q HEAD\n+\t\tthen\n+\t\t\tsay \"$(eval_gettext \"HEAD is up to date, rebase forced.\")\"\n+\t\telse\n+\t\t\tsay \"$(eval_gettext \"Current branch \\$branch_or_commit is up to date, rebase forced.\")\"\n+\t\tfi\n \tfi\n fi\n \n-- \n2.15.0.531.g2ccb3012c\n\n"},{"id":"334917","messageId":"20171216090319.11902-1-kaartic.sivaraam@gmail.com","threadId":"47271","inReplyTo":"20171127172104.5796-1-kaartic.sivaraam@gmail.com","subject":"[PATCH v5 0/3] rebase: give precise error messages","fromName":"Kaartic Sivaraam","fromEmail":"kaartic.sivaraam@gmail.com","sentAt":"2017-12-16T09:03:16Z","receivedAt":"2017-12-16T09:04:17Z","isPatch":true,"sender":{"key":"kaartic.sivaraam@gmail.com","avatar":"https://avatars.githubusercontent.com/u/12448084?v=4"},"body":"The tip of the v4 of this patch can be found at [1]. It was a revamp\nsent by Junio mostly touching [PATCH v2 1/3] of the series. I've updated\nit a little to add in something of my taste ;-)\n\nThere's only one concern that still bothers me a little. With the current\ncode you would see the following,\n\n    $ git rebase origin/maint 3013dff86\n    Current branch 3013dff86 is up to date.\n\nThat doesn't look good, does it? How about we overcome the issue of\nhandling this case and the HEAD case done in 3/3 by simplifying the\nmessage as shown in the following diff,\n\ndiff --git a/git-rebase.sh b/git-rebase.sh\nindex 0f379ba2b..4d5400034 100755\n--- a/git-rebase.sh\n+++ b/git-rebase.sh\n@@ -601,11 +601,11 @@ then\n                test -z \"$switch_to\" ||\n                GIT_REFLOG_ACTION=\"$GIT_REFLOG_ACTION: checkout $switch_to\" \\\n                        git checkout -q \"$switch_to\" --\n-               say \"$(eval_gettext \"Current branch \\$branch_name is up to date.\")\"\n+               say \"$(eval_gettext \"\\$branch_name is up to date.\")\"\n                finish_rebase\n                exit 0\n        else\n-               say \"$(eval_gettext \"Current branch \\$branch_name is up to date, rebase forced.\")\"\n+               say \"$(eval_gettext \"\\$branch_name is up to date, rebase forced.\")\"\n        fi\n fi\n\nI guess this one is much better than 3/3 of this series as it handles\nany kind of case by making no assumptions.\n\nThoughts ??\n\n\nNote: In case you're wondering where's v3 of this series, there wasn't\na v3 series but there was a v3 PATCH of 3/3 [2].\n\nReferences:\n\n[1]: <xmqq1sjxt3tz.fsf@gitster.mtv.corp.google.com>\n\n[2]: <20171201060935.19749-1-kaartic.sivaraam@gmail.com>\n\nHere's the interdiff between v4 and v5,\n\ndiff --git a/git-rebase.sh b/git-rebase.sh\nindex f3dd86443..fd72a35c6 100755\n--- a/git-rebase.sh\n+++ b/git-rebase.sh\n@@ -518,7 +518,7 @@ case \"$onto_name\" in\n esac\n \n # If the branch to rebase is given, that is the branch we will rebase\n-# $branch_name -- branch being rebased, or HEAD (already detached)\n+# $branch_name -- branch/commit being rebased, or HEAD (already detached)\n # $orig_head -- commit object name of tip of the branch before rebasing\n # $head_name -- refs/heads/<that-branch> or \"detached HEAD\"\n switch_to=\n@@ -602,7 +602,7 @@ then\n                GIT_REFLOG_ACTION=\"$GIT_REFLOG_ACTION: checkout $switch_to\" \\\n                        git checkout -q \"$switch_to\" --\n                if test \"$branch_name\" = \"HEAD\" &&\n-                        !(git symbolic-ref -q HEAD)\n+                        ! git symbolic-ref -q HEAD\n                then\n                        say \"$(eval_gettext \"HEAD is up to date.\")\"\n                else\n@@ -612,7 +612,7 @@ then\n                exit 0\n        else\n                if test \"$branch_name\" = \"HEAD\" &&\n-                        !(git symbolic-ref -q HEAD)\n+                        ! git symbolic-ref -q HEAD\n                then\n                        say \"$(eval_gettext \"HEAD is up to date, rebase forced.\")\"\n                else\n\n\n\nKaartic Sivaraam (3):\n  rebase: consistently use branch_name variable\n  rebase: distinguish user input by quoting it\n  rebase: rebasing can also be done when HEAD is detached\n\n git-rebase.sh | 35 +++++++++++++++++++++++++----------\n 1 file changed, 25 insertions(+), 10 deletions(-)\n\n-- \n2.15.0.531.g2ccb3012c\n\n"},{"id":"334918","messageId":"20171216090319.11902-2-kaartic.sivaraam@gmail.com","threadId":"47271","inReplyTo":"20171216090319.11902-1-kaartic.sivaraam@gmail.com","subject":"[PATCH v5 1/3] rebase: consistently use branch_name variable","fromName":"Kaartic Sivaraam","fromEmail":"kaartic.sivaraam@gmail.com","sentAt":"2017-12-16T09:03:17Z","receivedAt":"2017-12-16T09:04:30Z","isPatch":true,"sender":{"key":"kaartic.sivaraam@gmail.com","avatar":"https://avatars.githubusercontent.com/u/12448084?v=4"},"body":"The variable \"branch_name\" holds the <branch> parameter in \"git\nrebase <upstream> <branch>\", but one codepath did not use it after\nassigning $1 to it (instead it kept using $1).  Make it use the\nvariable consistently.\n\nAlso, update an error message to say there is no such branch or\ncommit, as we are expecting either of them, and not limiting\nourselves to a branch name.\n\nSigned-off-by: Kaartic Sivaraam <kaartic.sivaraam@gmail.com>\nSigned-off-by: Junio C Hamano <gitster@pobox.com>\nSigned-off-by: Kaartic Sivaraam <kaartic.sivaraam@gmail.com>\n---\n git-rebase.sh | 17 ++++++++++-------\n 1 file changed, 10 insertions(+), 7 deletions(-)\n\ndiff --git a/git-rebase.sh b/git-rebase.sh\nindex 60b70f3de..a299bcc52 100755\n--- a/git-rebase.sh\n+++ b/git-rebase.sh\n@@ -518,7 +518,7 @@ case \"$onto_name\" in\n esac\n \n # If the branch to rebase is given, that is the branch we will rebase\n-# $branch_name -- branch being rebased, or HEAD (already detached)\n+# $branch_name -- branch/commit being rebased, or HEAD (already detached)\n # $orig_head -- commit object name of tip of the branch before rebasing\n # $head_name -- refs/heads/<that-branch> or \"detached HEAD\"\n switch_to=\n@@ -528,15 +528,18 @@ case \"$#\" in\n \tbranch_name=\"$1\"\n \tswitch_to=\"$1\"\n \n-\tif git show-ref --verify --quiet -- \"refs/heads/$1\" &&\n-\t   orig_head=$(git rev-parse -q --verify \"refs/heads/$1\")\n+\t# Is it a local branch?\n+\tif git show-ref --verify --quiet -- \"refs/heads/$branch_name\" &&\n+\t   orig_head=$(git rev-parse -q --verify \"refs/heads/$branch_name\")\n \tthen\n-\t\thead_name=\"refs/heads/$1\"\n-\telif orig_head=$(git rev-parse -q --verify \"$1\")\n+\t\thead_name=\"refs/heads/$branch_name\"\n+\t# If not is it a valid ref (branch or commit)?\n+\telif orig_head=$(git rev-parse -q --verify \"$branch_name\")\n \tthen\n \t\thead_name=\"detached HEAD\"\n+\n \telse\n-\t\tdie \"$(eval_gettext \"fatal: no such branch: \\$branch_name\")\"\n+\t\tdie \"$(eval_gettext \"fatal: no such branch/commit: \\$branch_name\")\"\n \tfi\n \t;;\n 0)\n@@ -547,7 +550,7 @@ case \"$#\" in\n \t\tbranch_name=$(expr \"z$branch_name\" : 'zrefs/heads/\\(.*\\)')\n \telse\n \t\thead_name=\"detached HEAD\"\n-\t\tbranch_name=HEAD ;# detached\n+\t\tbranch_name=HEAD\n \tfi\n \torig_head=$(git rev-parse --verify HEAD) || exit\n \t;;\n-- \n2.15.0.531.g2ccb3012c\n\n"},{"id":"334919","messageId":"20171216090319.11902-3-kaartic.sivaraam@gmail.com","threadId":"47271","inReplyTo":"20171216090319.11902-1-kaartic.sivaraam@gmail.com","subject":"[PATCH v5 2/3] rebase: distinguish user input by quoting it","fromName":"Kaartic Sivaraam","fromEmail":"kaartic.sivaraam@gmail.com","sentAt":"2017-12-16T09:03:18Z","receivedAt":"2017-12-16T09:04:37Z","isPatch":true,"sender":{"key":"kaartic.sivaraam@gmail.com","avatar":"https://avatars.githubusercontent.com/u/12448084?v=4"},"body":"Signed-off-by: Kaartic Sivaraam <kaartic.sivaraam@gmail.com>\nSigned-off-by: Junio C Hamano <gitster@pobox.com>\nSigned-off-by: Kaartic Sivaraam <kaartic.sivaraam@gmail.com>\n---\n git-rebase.sh | 4 ++--\n 1 file changed, 2 insertions(+), 2 deletions(-)\n\ndiff --git a/git-rebase.sh b/git-rebase.sh\nindex a299bcc52..0f379ba2b 100755\n--- a/git-rebase.sh\n+++ b/git-rebase.sh\n@@ -477,7 +477,7 @@ then\n \t\t;;\n \tesac\n \tupstream=$(peel_committish \"${upstream_name}\") ||\n-\tdie \"$(eval_gettext \"invalid upstream \\$upstream_name\")\"\n+\tdie \"$(eval_gettext \"invalid upstream '\\$upstream_name'\")\"\n \tupstream_arg=\"$upstream_name\"\n else\n \tif test -z \"$onto\"\n@@ -539,7 +539,7 @@ case \"$#\" in\n \t\thead_name=\"detached HEAD\"\n \n \telse\n-\t\tdie \"$(eval_gettext \"fatal: no such branch/commit: \\$branch_name\")\"\n+\t\tdie \"$(eval_gettext \"fatal: no such branch/commit '\\$branch_name'\")\"\n \tfi\n \t;;\n 0)\n-- \n2.15.0.531.g2ccb3012c\n\n"},{"id":"334920","messageId":"20171216090319.11902-4-kaartic.sivaraam@gmail.com","threadId":"47271","inReplyTo":"20171216090319.11902-1-kaartic.sivaraam@gmail.com","subject":"[PATCH v5 3/3] rebase: rebasing can also be done when HEAD is detached","fromName":"Kaartic Sivaraam","fromEmail":"kaartic.sivaraam@gmail.com","sentAt":"2017-12-16T09:03:19Z","receivedAt":"2017-12-16T09:04:41Z","isPatch":true,"sender":{"key":"kaartic.sivaraam@gmail.com","avatar":"https://avatars.githubusercontent.com/u/12448084?v=4"},"body":"Attempting to rebase when the HEAD is detached and is already\nup to date with upstream (so there's nothing to do), the\nfollowing message is shown\n\n        Current branch HEAD is up to date.\n\nwhich is clearly wrong as HEAD is not a branch.\n\nHandle the special case of HEAD correctly to give a more precise\nerror message.\n\nSigned-off-by: Kaartic Sivaraam <kaartic.sivaraam@gmail.com>\nSigned-off-by: Junio C Hamano <gitster@pobox.com>\nSigned-off-by: Kaartic Sivaraam <kaartic.sivaraam@gmail.com>\n---\n git-rebase.sh | 16 ++++++++++++++--\n 1 file changed, 14 insertions(+), 2 deletions(-)\n\ndiff --git a/git-rebase.sh b/git-rebase.sh\nindex 0f379ba2b..fd72a35c6 100755\n--- a/git-rebase.sh\n+++ b/git-rebase.sh\n@@ -601,11 +601,23 @@ then\n \t\ttest -z \"$switch_to\" ||\n \t\tGIT_REFLOG_ACTION=\"$GIT_REFLOG_ACTION: checkout $switch_to\" \\\n \t\t\tgit checkout -q \"$switch_to\" --\n-\t\tsay \"$(eval_gettext \"Current branch \\$branch_name is up to date.\")\"\n+\t\tif test \"$branch_name\" = \"HEAD\" &&\n+\t\t\t ! git symbolic-ref -q HEAD\n+\t\tthen\n+\t\t\tsay \"$(eval_gettext \"HEAD is up to date.\")\"\n+\t\telse\n+\t\t\tsay \"$(eval_gettext \"Current branch \\$branch_name is up to date.\")\"\n+\t\tfi\n \t\tfinish_rebase\n \t\texit 0\n \telse\n-\t\tsay \"$(eval_gettext \"Current branch \\$branch_name is up to date, rebase forced.\")\"\n+\t\tif test \"$branch_name\" = \"HEAD\" &&\n+\t\t\t ! git symbolic-ref -q HEAD\n+\t\tthen\n+\t\t\tsay \"$(eval_gettext \"HEAD is up to date, rebase forced.\")\"\n+\t\telse\n+\t\t\tsay \"$(eval_gettext \"Current branch \\$branch_name is up to date, rebase forced.\")\"\n+\t\tfi\n \tfi\n fi\n \n-- \n2.15.0.531.g2ccb3012c\n\n"}]}