{"thread":{"id":"58498","subject":"[PATCH] branch: description for non-existent branch errors","startedAt":"2022-09-22T22:37:49Z","lastAt":"2022-10-09T05:12:28Z","messageCount":16,"participants":["Rubén Justo","Junio C Hamano","Bagas Sanjaya","Eric Sunshine"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"463482","messageId":"c333cc4b-12a1-82b6-0961-1c42080dad15@gmail.com","threadId":"58498","inReplyTo":null,"subject":"[PATCH] branch: description for non-existent branch errors","fromName":"Rubén Justo","fromEmail":"rjusto@gmail.com","sentAt":"2022-09-22T22:37:42Z","receivedAt":"2022-09-22T22:37:49Z","isPatch":true,"sender":{"key":"rjusto@gmail.com","avatar":"https://avatars.githubusercontent.com/u/5685487?v=4"},"body":"When the repository does not yet has commits, some errors describe that\nthere is no branch:\n\n    $ git init -b first\n\n    $ git --edit-description first\n    fatal: branch 'first' does not exist\n\n    $ git --set-upstream-to=upstream\n    fatal: branch 'first' does not exist\n\n    $ git branch -c second\n    error: refname refs/heads/first not found\n    fatal: Branch copy failed\n\nThat \"first\" branch is unborn but to say it doesn't exists is confusing.\n\nOptions \"-c\" (copy) and \"-m\" (rename) show the same error when the\norigin branch doesn't exists:\n\n    $ git branch -c non-existent-branch second\n    error: refname refs/heads/non-existent-branch not found\n    fatal: Branch copy failed\n\n    $ git branch -m non-existent-branch second\n    error: refname refs/heads/non-existent-branch not found\n    fatal: Branch rename failed\n\nNote that \"--edit-description\" without an explicit argument is already\nconsidering the _empty repository_ circumstance in its error.  Also note\nthat \"-m\" on the initial branch it is an allowed operation.\n\nThis commit makes the error descriptions for those branch operations\nwith unborn or non-existent branches, more informative.\n\nThis is the result of the change:\n\n    $ git init -b first\n\n    $ git --edit-description first\n    fatal: No commit on branch 'first' yet.\n\n    $ git --set-upstream-to=upstream\n    fatal: No commit on branch 'first' yet.\n\n    $ git -c second\n    fatal: No commit on branch 'first' yet.\n\n    $ git [-c/-m] non-existent-branch second\n    fatal: No branch named 'non-existent-branch'.\n\n---\n\nHi all.\n\nI would appreciate some guidance here.\n\nThis patch is based on master but there is already in 'seen' a patch\nsubmitted for 'branch' that produces conflicts with this.  I don't know\nif it is more convenient to submit this patch based on 'seen'\nconsidering that.\n\nI submitted that other patch too and prefer to keep the changes separate\nbut maybe it's better not to and do a rollup with this on that other\npatch.. I don't know how disturbing it is to submit a new patch when it\nis \"waiting for review\".\n\nAnother approach?\n\nThank you.\n\n\nUn saludo.\n\n builtin/branch.c | 14 ++++++++++++--\n 1 file changed, 12 insertions(+), 2 deletions(-)\n\ndiff --git a/builtin/branch.c b/builtin/branch.c\nindex 55cd9a6e99..5ca35064f3 100644\n--- a/builtin/branch.c\n+++ b/builtin/branch.c\n@@ -538,6 +538,13 @@ static void copy_or_rename_branch(const char *oldname, const char *newname, int\n \t\t\tdie(_(\"Invalid branch name: '%s'\"), oldname);\n \t}\n \n+\tif (copy && !ref_exists(oldref.buf)) {\n+\t\tif (!strcmp(head, oldname))\n+\t\t\tdie(_(\"No commit on branch '%s' yet.\"), oldname);\n+\t\telse\n+\t\t\tdie(_(\"No branch named '%s'.\"), oldname);\n+\t}\n+\n \t/*\n \t * A command like \"git branch -M currentbranch currentbranch\" cannot\n \t * cause the worktree to become inconsistent with HEAD, so allow it.\n@@ -805,7 +812,7 @@ int cmd_branch(int argc, const char **argv, const char *prefix)\n \t\tif (!ref_exists(branch_ref.buf)) {\n \t\t\tstrbuf_release(&branch_ref);\n \n-\t\t\tif (!argc)\n+\t\t\tif (!argc || !strcmp(head, branch_name))\n \t\t\t\treturn error(_(\"No commit on branch '%s' yet.\"),\n \t\t\t\t\t     branch_name);\n \t\t\telse\n@@ -848,8 +855,11 @@ int cmd_branch(int argc, const char **argv, const char *prefix)\n \t\t\tdie(_(\"no such branch '%s'\"), argv[0]);\n \t\t}\n \n-\t\tif (!ref_exists(branch->refname))\n+\t\tif (!ref_exists(branch->refname)) {\n+\t\t\tif (!argc || !strcmp(head, branch->name))\n+\t\t\t\tdie(_(\"No commit on branch '%s' yet.\"), branch->name);\n \t\t\tdie(_(\"branch '%s' does not exist\"), branch->name);\n+\t\t}\n \n \t\tdwim_and_setup_tracking(the_repository, branch->name,\n \t\t\t\t\tnew_upstream, BRANCH_TRACK_OVERRIDE,\n-- \n2.36.1\n"},{"id":"463588","messageId":"858edf12-67b1-5e2c-dd2e-3eb476530803@gmail.com","threadId":"58498","inReplyTo":"c333cc4b-12a1-82b6-0961-1c42080dad15@gmail.com","subject":"[PATCH] branch: description for non-existent branch errors","fromName":"Rubén Justo","fromEmail":"rjusto@gmail.com","sentAt":"2022-09-24T22:52:30Z","receivedAt":"2022-09-24T22:52:37Z","isPatch":true,"sender":{"key":"rjusto@gmail.com","avatar":"https://avatars.githubusercontent.com/u/5685487?v=4"},"body":"When the repository does not yet has commits, some errors describe that\nthere is no branch:\n\n    $ git init -b first\n\n    $ git --edit-description first\n    fatal: branch 'first' does not exist\n\n    $ git --set-upstream-to=upstream\n    fatal: branch 'first' does not exist\n\n    $ git branch -c second\n    error: refname refs/heads/first not found\n    fatal: Branch copy failed\n\nThat \"first\" branch is unborn but to say it doesn't exists is confusing.\n\nOptions \"-c\" (copy) and \"-m\" (rename) show the same error when the\norigin branch doesn't exists:\n\n    $ git branch -c non-existent-branch second\n    error: refname refs/heads/non-existent-branch not found\n    fatal: Branch copy failed\n\n    $ git branch -m non-existent-branch second\n    error: refname refs/heads/non-existent-branch not found\n    fatal: Branch rename failed\n\nNote that \"--edit-description\" without an explicit argument is already\nconsidering the _empty repository_ circumstance in its error.  Also note\nthat \"-m\" on the initial branch it is an allowed operation.\n\nThis commit makes the error descriptions for those branch operations\nwith unborn or non-existent branches, more informative.\n\nThis is the result of the change:\n\n    $ git init -b first\n\n    $ git --edit-description first\n    fatal: No commit on branch 'first' yet.\n\n    $ git --set-upstream-to=upstream\n    fatal: No commit on branch 'first' yet.\n\n    $ git -c second\n    fatal: No commit on branch 'first' yet.\n\n    $ git [-c/-m] non-existent-branch second\n    fatal: No branch named 'non-existent-branch'.\n\nSigned-off-by: Rubén Justo <rjusto@gmail.com>\n\n---\n\nJust re-sending with the Signed-off-by label. Sorry.\n\n\n builtin/branch.c | 14 ++++++++++++--\n 1 file changed, 12 insertions(+), 2 deletions(-)\n\ndiff --git a/builtin/branch.c b/builtin/branch.c\nindex 55cd9a6e99..5ca35064f3 100644\n--- a/builtin/branch.c\n+++ b/builtin/branch.c\n@@ -538,6 +538,13 @@ static void copy_or_rename_branch(const char *oldname, const char *newname, int\n \t\t\tdie(_(\"Invalid branch name: '%s'\"), oldname);\n \t}\n \n+\tif (copy && !ref_exists(oldref.buf)) {\n+\t\tif (!strcmp(head, oldname))\n+\t\t\tdie(_(\"No commit on branch '%s' yet.\"), oldname);\n+\t\telse\n+\t\t\tdie(_(\"No branch named '%s'.\"), oldname);\n+\t}\n+\n \t/*\n \t * A command like \"git branch -M currentbranch currentbranch\" cannot\n \t * cause the worktree to become inconsistent with HEAD, so allow it.\n@@ -805,7 +812,7 @@ int cmd_branch(int argc, const char **argv, const char *prefix)\n \t\tif (!ref_exists(branch_ref.buf)) {\n \t\t\tstrbuf_release(&branch_ref);\n \n-\t\t\tif (!argc)\n+\t\t\tif (!argc || !strcmp(head, branch_name))\n \t\t\t\treturn error(_(\"No commit on branch '%s' yet.\"),\n \t\t\t\t\t     branch_name);\n \t\t\telse\n@@ -848,8 +855,11 @@ int cmd_branch(int argc, const char **argv, const char *prefix)\n \t\t\tdie(_(\"no such branch '%s'\"), argv[0]);\n \t\t}\n \n-\t\tif (!ref_exists(branch->refname))\n+\t\tif (!ref_exists(branch->refname)) {\n+\t\t\tif (!argc || !strcmp(head, branch->name))\n+\t\t\t\tdie(_(\"No commit on branch '%s' yet.\"), branch->name);\n \t\t\tdie(_(\"branch '%s' does not exist\"), branch->name);\n+\t\t}\n \n \t\tdwim_and_setup_tracking(the_repository, branch->name,\n \t\t\t\t\tnew_upstream, BRANCH_TRACK_OVERRIDE,\n-- \n2.36.1\n"},{"id":"463656","messageId":"xmqqleq6ovh4.fsf@gitster.g","threadId":"58498","inReplyTo":"858edf12-67b1-5e2c-dd2e-3eb476530803@gmail.com","subject":"Re: [PATCH] branch: description for non-existent branch errors","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2022-09-26T18:12:55Z","receivedAt":"2022-09-26T18:19:51Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Rubén Justo <rjusto@gmail.com> writes:\n\n> When the repository does not yet has commits, some errors describe that\n\n\"has\" -> \"have\".\n\n>  builtin/branch.c | 14 ++++++++++++--\n>  1 file changed, 12 insertions(+), 2 deletions(-)\n\nTests to protect the new behaviour from getting broken by future\ndevelopers are missing.\n\n> diff --git a/builtin/branch.c b/builtin/branch.c\n> index 55cd9a6e99..5ca35064f3 100644\n> --- a/builtin/branch.c\n> +++ b/builtin/branch.c\n> @@ -538,6 +538,13 @@ static void copy_or_rename_branch(const char *oldname, const char *newname, int\n>  \t\t\tdie(_(\"Invalid branch name: '%s'\"), oldname);\n>  \t}\n>  \n> +\tif (copy && !ref_exists(oldref.buf)) {\n> +\t\tif (!strcmp(head, oldname))\n> +\t\t\tdie(_(\"No commit on branch '%s' yet.\"), oldname);\n> +\t\telse\n> +\t\t\tdie(_(\"No branch named '%s'.\"), oldname);\n> +\t}\n\nLet's not make it worse by starting the die() message with capital\nletters, even though the existing \"git branch\" error messages are\nalready mixture that they need to be cleaned up later.\n\nThanks.\n"},{"id":"463685","messageId":"26a5cbe2-d821-e7f6-e56f-4ad90ef2cf2d@gmail.com","threadId":"58498","inReplyTo":"xmqqleq6ovh4.fsf@gitster.g","subject":"Re: [PATCH] branch: description for non-existent branch errors","fromName":"Rubén Justo","fromEmail":"rjusto@gmail.com","sentAt":"2022-09-26T23:35:13Z","receivedAt":"2022-09-26T23:35:29Z","isPatch":true,"sender":{"key":"rjusto@gmail.com","avatar":"https://avatars.githubusercontent.com/u/5685487?v=4"},"body":"On 26/9/22 20:12, Junio C Hamano wrote:\n\nThank you for the review. I will do a reroll with your comments, but about..\n\n>> +\tif (copy && !ref_exists(oldref.buf)) {\n>> +\t\tif (!strcmp(head, oldname))\n>> +\t\t\tdie(_(\"No commit on branch '%s' yet.\"), oldname);\n>> +\t\telse\n>> +\t\t\tdie(_(\"No branch named '%s'.\"), oldname);\n>> +\t}\n> \n> Let's not make it worse by starting the die() message with capital\n> letters, even though the existing \"git branch\" error messages are\n> already mixture that they need to be cleaned up later.\n> \n\nI chose these literals for the errors because they are already translated,\nappear below in that same file. I thought that would make the patch easier to\nreview and apply, for the translators too.\n\nMaybe we can maintain those capitalized literals to have a simpler patch to\nmerge and leave the \"mixtures\" for a posterior patch.  I have already \nidentified a leak in that command:\n\n\tstatic const char *head;\n\t...\n\tint cmd_branch()\n\t...\n\t\thead = resolve_refdup(\"HEAD\", 0, &head_oid, NULL);\n\n\"head\" is leaked but there is no easy free, because some exists are like:\n\n\t\tif (delete) {\n\t\t\tif (!argc)\n\t\t\t\tdie(_(\"branch name required\"));\n\t\t\treturn delete_branches(argc, argv, delete > 1, filter.kind, quiet);\n\nWithout entering in this too much, maybe an atexit() approach, as in some\nothers commands... but maybe a more clear flow.. and that would need some\nchanges that can carry out the \"mixtures\".\n\nAnyway, if you think there is no problem with the new literal in that file,\nI will add it to the reroll with the rest of the comments in your review.\n\nI pointed out in the first mail of this thread, there is already a patch in\n'seen' that touches builtin/branch.c [1].  I would like to keep the patches\nseparated, but I don't know how to proceed: make the change from 'seen', keep\nit from 'master'... Maybe you can give me some guidance in this.\n\nThank you.\n\nUn saludo.\n"},{"id":"463775","messageId":"xmqqedvw1mmu.fsf@gitster.g","threadId":"58498","inReplyTo":"26a5cbe2-d821-e7f6-e56f-4ad90ef2cf2d@gmail.com","subject":"Re: [PATCH] branch: description for non-existent branch errors","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2022-09-27T22:24:41Z","receivedAt":"2022-09-27T22:24:53Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Rubén Justo <rjusto@gmail.com> writes:\n\n> I pointed out in the first mail of this thread, there is already a patch in\n> 'seen' that touches builtin/branch.c [1].  I would like to keep the patches\n> separated, but I don't know how to proceed: make the change from 'seen', keep\n> it from 'master'... Maybe you can give me some guidance in this.\n\nI do not see much problem in keeping them separated.  My trial merge\nof the result of applying this patch on top of 'master', with the\nother topic that has the \"branch description for nth prior checkout\"\npatch does show a minor textual conflict, but the resolution does\nnot look too bad.\n\nCheck near the topic branch of 'seen' after I push out today's\nintegration result in a few hours and see if they look reasonable.\n\nThanks.\n\n\ndiff --cc builtin/branch.c\nindex 5ca35064f3,13d1f028da..2b3884ce61\n--- a/builtin/branch.c\n+++ b/builtin/branch.c\n@@@ -810,19 -807,18 +814,18 @@@ int cmd_branch(int argc, const char **a\n  \n  \t\tstrbuf_addf(&branch_ref, \"refs/heads/%s\", branch_name);\n  \t\tif (!ref_exists(branch_ref.buf)) {\n- \t\t\tstrbuf_release(&branch_ref);\n- \n -\t\t\tif (!argc)\n +\t\t\tif (!argc || !strcmp(head, branch_name))\n- \t\t\t\treturn error(_(\"No commit on branch '%s' yet.\"),\n+ \t\t\t\tret = error(_(\"No commit on branch '%s' yet.\"),\n  \t\t\t\t\t     branch_name);\n  \t\t\telse\n- \t\t\t\treturn error(_(\"No branch named '%s'.\"),\n+ \t\t\t\tret = error(_(\"No branch named '%s'.\"),\n  \t\t\t\t\t     branch_name);\n- \t\t}\n- \t\tstrbuf_release(&branch_ref);\n+ \t\t} else\n+ \t\t\tret = edit_branch_description(branch_name);\n  \n- \t\tif (edit_branch_description(branch_name))\n- \t\t\treturn 1;\n+ \t\tstrbuf_release(&branch_ref);\n+ \t\tstrbuf_release(&buf);\n+ \t\treturn -ret;\n  \t} else if (copy) {\n  \t\tif (!argc)\n  \t\t\tdie(_(\"branch name required\"));\n"},{"id":"463862","messageId":"xmqqbkqzv1l7.fsf@gitster.g","threadId":"58498","inReplyTo":"xmqqedvw1mmu.fsf@gitster.g","subject":"Re: [PATCH] branch: description for non-existent branch errors","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2022-09-28T17:41:08Z","receivedAt":"2022-09-28T17:41:29Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Junio C Hamano <gitster@pobox.com> writes:\n\n> Rubén Justo <rjusto@gmail.com> writes:\n>\n>> I pointed out in the first mail of this thread, there is already a patch in\n>> 'seen' that touches builtin/branch.c [1].  I would like to keep the patches\n>> separated, but I don't know how to proceed: make the change from 'seen', keep\n>> it from 'master'... Maybe you can give me some guidance in this.\n>\n> I do not see much problem in keeping them separated.  My trial merge\n> of the result of applying this patch on top of 'master', with the\n> other topic that has the \"branch description for nth prior checkout\"\n> patch does show a minor textual conflict, but the resolution does\n> not look too bad.\n>\n> Check near the topic branch of 'seen' after I push out today's\n> integration result in a few hours and see if they look reasonable.\n>\n> Thanks.\n\nAh, I forgot to mention.  As to the error messages that begin with a\ncapital letter, to be consistent with violating messages that are\nalready there in builtin/branch.c, let's keep them as they are in\nyour patch.  We can and should clean them up later, perhaps soon\nafter the patch under discussion matures, but I agree with you that\nit can be left outside the scope of this patch.\n\nBut stepping back a bit, in the longer term, we might want to change\nthe behaviour of \"git branch --edit-description\", at least when no\nbranch is specified on the command line and we are on an unborn\nbranch.  It is merely the matter of setting a variable in the\nconfiguration file, so there may not be a strong reason to forbid\n\n    $ git init trash\n    $ cd trash\n    $ git branch --edit-description\n    $ git commit --allow-empty -m initial\n\nwhile allowing the same sequence with the last two commands reversed.\n\nAfter all, renaming a branch with \"branch -m\" does not to require an\nexisting ref that points at a commit, i.e.\n\n    $ git init -b master trash\n    $ cd trash\n    $ git config branch.master.description \"describes master\"\n    $ git branch -m master main\n\ndoes work fine and you end up with branch.main.description at the\nend.\n"},{"id":"463865","messageId":"xmqqzgejtmkd.fsf@gitster.g","threadId":"58498","inReplyTo":"xmqqedvw1mmu.fsf@gitster.g","subject":"Re: [PATCH] branch: description for non-existent branch errors","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2022-09-28T17:50:58Z","receivedAt":"2022-09-28T17:51:08Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Junio C Hamano <gitster@pobox.com> writes:\n\n> Rubén Justo <rjusto@gmail.com> writes:\n>\n>> I pointed out in the first mail of this thread, there is already a patch in\n>> 'seen' that touches builtin/branch.c [1].  I would like to keep the patches\n>> separated, but I don't know how to proceed: make the change from 'seen', keep\n>> it from 'master'... Maybe you can give me some guidance in this.\n>\n> I do not see much problem in keeping them separated.  My trial merge\n> of the result of applying this patch on top of 'master', with the\n> other topic that has the \"branch description for nth prior checkout\"\n> patch does show a minor textual conflict, but the resolution does\n> not look too bad.\n>\n> Check near the topic branch of 'seen' after I push out today's\n> integration result in a few hours and see if they look reasonable.\n>\n> Thanks.\n\nAh, I forgot to mention.  As to the error messages that begin with a\ncapital letter, to be consistent with violating messages that are\nalready there in builtin/branch.c, let's keep them as they are in\nyour patch.  We can and should clean them up later, perhaps soon\nafter the patch under discussion matures, but I agree with you that\nit can be left outside the scope of this patch.\n\nBut stepping back a bit, in the longer term, we might want to change\nthe behaviour of \"git branch --edit-description\", at least when no\nbranch is specified on the command line and we are on an unborn\nbranch.  It is merely the matter of setting a variable in the\nconfiguration file, so there may not be a strong reason to forbid\n\n    $ git init trash\n    $ cd trash\n    $ git branch --edit-description\n    $ git commit --allow-empty -m initial\n\nwhile allowing the same sequence with the last two commands reversed.\n\nAfter all, renaming a branch with \"branch -m\" does not to require an\nexisting ref that points at a commit, i.e.\n\n    $ git init -b master trash\n    $ cd trash\n    $ git config branch.master.description \"describes master\"\n    $ git branch -m master main\n\ndoes work fine and you end up with branch.main.description at the\nend.\n"},{"id":"463891","messageId":"a55cf3b7-218d-3c8b-ae1c-c09d49caeda8@gmail.com","threadId":"58498","inReplyTo":"xmqqzgejtmkd.fsf@gitster.g","subject":"Re: [PATCH] branch: description for non-existent branch errors","fromName":"Rubén Justo","fromEmail":"rjusto@gmail.com","sentAt":"2022-09-28T23:59:35Z","receivedAt":"2022-09-28T23:59:58Z","isPatch":true,"sender":{"key":"rjusto@gmail.com","avatar":"https://avatars.githubusercontent.com/u/5685487?v=4"},"body":"On 28/9/22 19:50, Junio C Hamano wrote:\n\n> But stepping back a bit, in the longer term, we might want to change\n> the behaviour of \"git branch --edit-description\", at least when no\n> branch is specified on the command line and we are on an unborn\n> branch.  It is merely the matter of setting a variable in the\n> configuration file, so there may not be a strong reason to forbid\n> \n>     $ git init trash\n>     $ cd trash\n>     $ git branch --edit-description\n>     $ git commit --allow-empty -m initial\n> \n> while allowing the same sequence with the last two commands reversed.\n> \n> After all, renaming a branch with \"branch -m\" does not to require an\n> existing ref that points at a commit, i.e.\n> \n>     $ git init -b master trash\n>     $ cd trash\n>     $ git config branch.master.description \"describes master\"\n>     $ git branch -m master main\n> \n> does work fine and you end up with branch.main.description at the\n> end.\n \nIndeed. And \"--set-upstream-to\"? I haven't found any reason why we\nshouldn't allow it for an unborn branch too. \"--unset-upstream\"\nalready works.\n\nThose changes I think are worth doing along with the fix for the leak\nof 'static const char *head'.\n\nAnd then the error descriptions.  Not just the capitalization but\nsome similar but different messages too.\n\nI'll reroll this path with the test for the current errors.\n\nThank you.\n\nUn saludo.\n"},{"id":"463894","messageId":"xmqqmtajosek.fsf@gitster.g","threadId":"58498","inReplyTo":"a55cf3b7-218d-3c8b-ae1c-c09d49caeda8@gmail.com","subject":"Re: [PATCH] branch: description for non-existent branch errors","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2022-09-29T01:56:03Z","receivedAt":"2022-09-29T01:56:26Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Rubén Justo <rjusto@gmail.com> writes:\n\n> Those changes I think are worth doing along with the fix for the leak\n> of 'static const char *head'.\n\nLet's not grow the scope of the topic forever.  It will increase the\nchance of new mistakes and throw us into endless iterations.\n\nI think the posted patch plus tests for the new behaviour (i.e. no\nlonger we give a misleading error message) is a good stopping point.\n\nExtending the behaviour to allow some of these operations that\ncurrently fail on an unborn branch may or may not make sense, and\nthat should be discussed separately, possibly for each option.\nAfter the dust from the current one settles.\n\nPersonally, I do not think a \"static const char *\" variable that\nholds onto an allocated piece of memory smaller than 1kB is\nsomething we should worry about.  Leak checkers should also be smart\nenough not to warn about such a variable, shouldn't they?\n\n> And then the error descriptions.  Not just the capitalization but\n> some similar but different messages too.\n\nYup, and that is probably a separate patch after all of the above\nsettles.\n\nThanks.\n"},{"id":"464030","messageId":"930ff836-a5c4-0e85-517d-39645f00cd31@gmail.com","threadId":"58498","inReplyTo":"c333cc4b-12a1-82b6-0961-1c42080dad15@gmail.com","subject":"[PATCH v2] branch: description for non-existent branch errors","fromName":"Rubén Justo","fromEmail":"rjusto@gmail.com","sentAt":"2022-09-30T22:47:30Z","receivedAt":"2022-09-30T22:47:38Z","isPatch":true,"sender":{"key":"rjusto@gmail.com","avatar":"https://avatars.githubusercontent.com/u/5685487?v=4"},"body":"When the repository does not yet have commits, some errors describe that\nthere is no branch:\n\n    $ git init -b first\n\n    $ git branch --edit-description first\n    error: No branch named 'first'.\n\n    $ git branch --set-upstream-to=upstream\n    fatal: branch 'first' does not exist\n\n    $ git branch -c second\n    error: refname refs/heads/first not found\n    fatal: Branch copy failed\n\nThat \"first\" branch is unborn but to say it doesn't exists is confusing.\n\nOptions \"-c\" (copy) and \"-m\" (rename) show the same error when the\norigin branch doesn't exists:\n\n    $ git branch -c non-existent-branch second\n    error: refname refs/heads/non-existent-branch not found\n    fatal: Branch copy failed\n\n    $ git branch -m non-existent-branch second\n    error: refname refs/heads/non-existent-branch not found\n    fatal: Branch rename failed\n\nNote that \"--edit-description\" without an explicit argument is already\nconsidering the _empty repository_ circumstance in its error.  Also note\nthat \"-m\" on the initial branch it is an allowed operation.\n\nThis commit makes the error descriptions for those branch operations\nwith unborn or non-existent branches, more informative.\n\nThis is the result of the change:\n\n    $ git init -b first\n\n    $ git branch --edit-description first\n    error: No commit on branch 'first' yet.\n\n    $ git branch --set-upstream-to=upstream\n    fatal: No commit on branch 'first' yet.\n\n    $ git branch -c second\n    fatal: No commit on branch 'first' yet.\n\n    $ git branch [-c/-m] non-existent-branch second\n    fatal: No branch named 'non-existent-branch'.\n\nSigned-off-by: Rubén Justo <rjusto@gmail.com>\n---\n\nChanges since V1:\n\n * Fixed the message, non precise descriptions.\n * Error renaming non-existent branch was not correct.\n * Tests for the new errors.\n\n\nRange-diff:\n1:  bba7096c4b ! 1:  096c443a29 branch: description for non-existent branch errors\n    @@ Metadata\n      ## Commit message ##\n         branch: description for non-existent branch errors\n     \n    -    When the repository does not yet has commits, some errors describe that\n    +    When the repository does not yet have commits, some errors describe that\n         there is no branch:\n     \n             $ git init -b first\n     \n    -        $ git --edit-description first\n    -        fatal: branch 'first' does not exist\n    +        $ git branch --edit-description first\n    +        error: No branch named 'first'.\n     \n    -        $ git --set-upstream-to=upstream\n    +        $ git branch --set-upstream-to=upstream\n             fatal: branch 'first' does not exist\n     \n             $ git branch -c second\n    @@ Commit message\n     \n             $ git init -b first\n     \n    -        $ git --edit-description first\n    -        fatal: No commit on branch 'first' yet.\n    +        $ git branch --edit-description first\n    +        error: No commit on branch 'first' yet.\n     \n    -        $ git --set-upstream-to=upstream\n    +        $ git branch --set-upstream-to=upstream\n             fatal: No commit on branch 'first' yet.\n     \n    -        $ git -c second\n    +        $ git branch -c second\n             fatal: No commit on branch 'first' yet.\n     \n    -        $ git [-c/-m] non-existent-branch second\n    +        $ git branch [-c/-m] non-existent-branch second\n             fatal: No branch named 'non-existent-branch'.\n     \n         Signed-off-by: Rubén Justo <rjusto@gmail.com>\n    @@ builtin/branch.c: static void copy_or_rename_branch(const char *oldname, const c\n      \t\t\tdie(_(\"Invalid branch name: '%s'\"), oldname);\n      \t}\n      \n    -+\tif (copy && !ref_exists(oldref.buf)) {\n    -+\t\tif (!strcmp(head, oldname))\n    ++\tif ((copy || strcmp(head, oldname)) && !ref_exists(oldref.buf)) {\n    ++\t\tif (copy && !strcmp(head, oldname))\n     +\t\t\tdie(_(\"No commit on branch '%s' yet.\"), oldname);\n     +\t\telse\n     +\t\t\tdie(_(\"No branch named '%s'.\"), oldname);\n    @@ builtin/branch.c: int cmd_branch(int argc, const char **argv, const char *prefix\n      \n      \t\tdwim_and_setup_tracking(the_repository, branch->name,\n      \t\t\t\t\tnew_upstream, BRANCH_TRACK_OVERRIDE,\n    +\n    + ## t/t3202-show-branch.sh ##\n    +@@ t/t3202-show-branch.sh: test_description='test show-branch'\n    + # arbitrary reference time: 2009-08-30 19:20:00\n    + GIT_TEST_DATE_NOW=1251660000; export GIT_TEST_DATE_NOW\n    + \n    ++test_expect_success 'error descriptions on empty repository' '\n    ++\tcurrent=$(git branch --show-current) &&\n    ++\tcat >expect <<-EOF &&\n    ++\terror: No commit on branch '\\''$current'\\'' yet.\n    ++\tEOF\n    ++\ttest_must_fail git branch --edit-description 2>actual &&\n    ++\ttest_cmp expect actual &&\n    ++\ttest_must_fail git branch --edit-description $current 2>actual &&\n    ++\ttest_cmp expect actual\n    ++'\n    ++\n    ++test_expect_success 'fatal descriptions on empty repository' '\n    ++\tcurrent=$(git branch --show-current) &&\n    ++\tcat >expect <<-EOF &&\n    ++\tfatal: No commit on branch '\\''$current'\\'' yet.\n    ++\tEOF\n    ++\ttest_must_fail git branch --set-upstream-to=non-existent 2>actual &&\n    ++\ttest_cmp expect actual &&\n    ++\ttest_must_fail git branch -c new-branch 2>actual &&\n    ++\ttest_cmp expect actual\n    ++'\n    ++\n    + test_expect_success 'setup' '\n    + \ttest_commit initial &&\n    + \tfor i in $(test_seq 1 10)\n    +@@ t/t3202-show-branch.sh: done <<\\EOF\n    + --reflog --current\n    + EOF\n    + \n    ++test_expect_success 'error descriptions on non-existent branch' '\n    ++\tcat >expect <<-EOF &&\n    ++\terror: No branch named '\\''non-existent'\\'.'\n    ++\tEOF\n    ++\ttest_must_fail git branch --edit-description non-existent 2>actual &&\n    ++\ttest_cmp expect actual\n    ++'\n    ++\n    ++test_expect_success 'fatal descriptions on non-existent branch' '\n    ++\tcat >expect <<-EOF &&\n    ++\tfatal: branch '\\''non-existent'\\'' does not exist\n    ++\tEOF\n    ++\ttest_must_fail git branch --set-upstream-to=non-existent non-existent 2>actual &&\n    ++\ttest_cmp expect actual &&\n    ++\n    ++\tcat >expect <<-EOF &&\n    ++\tfatal: No branch named '\\''non-existent'\\''.\n    ++\tEOF\n    ++\ttest_must_fail git branch -c non-existent new-branch 2>actual &&\n    ++\ttest_cmp expect actual &&\n    ++\ttest_must_fail git branch -m non-existent new-branch 2>actual &&\n    ++\ttest_cmp expect actual\n    ++'\n    ++\n    + test_done\n\n builtin/branch.c       | 14 +++++++++++--\n t/t3202-show-branch.sh | 46 ++++++++++++++++++++++++++++++++++++++++++\n 2 files changed, 58 insertions(+), 2 deletions(-)\n\ndiff --git a/builtin/branch.c b/builtin/branch.c\nindex 55cd9a6e99..499ebec99e 100644\n--- a/builtin/branch.c\n+++ b/builtin/branch.c\n@@ -538,6 +538,13 @@ static void copy_or_rename_branch(const char *oldname, const char *newname, int\n \t\t\tdie(_(\"Invalid branch name: '%s'\"), oldname);\n \t}\n \n+\tif ((copy || strcmp(head, oldname)) && !ref_exists(oldref.buf)) {\n+\t\tif (copy && !strcmp(head, oldname))\n+\t\t\tdie(_(\"No commit on branch '%s' yet.\"), oldname);\n+\t\telse\n+\t\t\tdie(_(\"No branch named '%s'.\"), oldname);\n+\t}\n+\n \t/*\n \t * A command like \"git branch -M currentbranch currentbranch\" cannot\n \t * cause the worktree to become inconsistent with HEAD, so allow it.\n@@ -805,7 +812,7 @@ int cmd_branch(int argc, const char **argv, const char *prefix)\n \t\tif (!ref_exists(branch_ref.buf)) {\n \t\t\tstrbuf_release(&branch_ref);\n \n-\t\t\tif (!argc)\n+\t\t\tif (!argc || !strcmp(head, branch_name))\n \t\t\t\treturn error(_(\"No commit on branch '%s' yet.\"),\n \t\t\t\t\t     branch_name);\n \t\t\telse\n@@ -848,8 +855,11 @@ int cmd_branch(int argc, const char **argv, const char *prefix)\n \t\t\tdie(_(\"no such branch '%s'\"), argv[0]);\n \t\t}\n \n-\t\tif (!ref_exists(branch->refname))\n+\t\tif (!ref_exists(branch->refname)) {\n+\t\t\tif (!argc || !strcmp(head, branch->name))\n+\t\t\t\tdie(_(\"No commit on branch '%s' yet.\"), branch->name);\n \t\t\tdie(_(\"branch '%s' does not exist\"), branch->name);\n+\t\t}\n \n \t\tdwim_and_setup_tracking(the_repository, branch->name,\n \t\t\t\t\tnew_upstream, BRANCH_TRACK_OVERRIDE,\ndiff --git a/t/t3202-show-branch.sh b/t/t3202-show-branch.sh\nindex f2b9199007..ea7cfd1951 100755\n--- a/t/t3202-show-branch.sh\n+++ b/t/t3202-show-branch.sh\n@@ -7,6 +7,28 @@ test_description='test show-branch'\n # arbitrary reference time: 2009-08-30 19:20:00\n GIT_TEST_DATE_NOW=1251660000; export GIT_TEST_DATE_NOW\n \n+test_expect_success 'error descriptions on empty repository' '\n+\tcurrent=$(git branch --show-current) &&\n+\tcat >expect <<-EOF &&\n+\terror: No commit on branch '\\''$current'\\'' yet.\n+\tEOF\n+\ttest_must_fail git branch --edit-description 2>actual &&\n+\ttest_cmp expect actual &&\n+\ttest_must_fail git branch --edit-description $current 2>actual &&\n+\ttest_cmp expect actual\n+'\n+\n+test_expect_success 'fatal descriptions on empty repository' '\n+\tcurrent=$(git branch --show-current) &&\n+\tcat >expect <<-EOF &&\n+\tfatal: No commit on branch '\\''$current'\\'' yet.\n+\tEOF\n+\ttest_must_fail git branch --set-upstream-to=non-existent 2>actual &&\n+\ttest_cmp expect actual &&\n+\ttest_must_fail git branch -c new-branch 2>actual &&\n+\ttest_cmp expect actual\n+'\n+\n test_expect_success 'setup' '\n \ttest_commit initial &&\n \tfor i in $(test_seq 1 10)\n@@ -175,4 +197,28 @@ done <<\\EOF\n --reflog --current\n EOF\n \n+test_expect_success 'error descriptions on non-existent branch' '\n+\tcat >expect <<-EOF &&\n+\terror: No branch named '\\''non-existent'\\'.'\n+\tEOF\n+\ttest_must_fail git branch --edit-description non-existent 2>actual &&\n+\ttest_cmp expect actual\n+'\n+\n+test_expect_success 'fatal descriptions on non-existent branch' '\n+\tcat >expect <<-EOF &&\n+\tfatal: branch '\\''non-existent'\\'' does not exist\n+\tEOF\n+\ttest_must_fail git branch --set-upstream-to=non-existent non-existent 2>actual &&\n+\ttest_cmp expect actual &&\n+\n+\tcat >expect <<-EOF &&\n+\tfatal: No branch named '\\''non-existent'\\''.\n+\tEOF\n+\ttest_must_fail git branch -c non-existent new-branch 2>actual &&\n+\ttest_cmp expect actual &&\n+\ttest_must_fail git branch -m non-existent new-branch 2>actual &&\n+\ttest_cmp expect actual\n+'\n+\n test_done\n-- \n2.36.1\n"},{"id":"464040","messageId":"f34912ab-5d1b-6dfb-e079-0e7b135ebe14@gmail.com","threadId":"58498","inReplyTo":"930ff836-a5c4-0e85-517d-39645f00cd31@gmail.com","subject":"Re: [PATCH v2] branch: description for non-existent branch errors","fromName":"Bagas Sanjaya","fromEmail":"bagasdotme@gmail.com","sentAt":"2022-10-01T12:43:27Z","receivedAt":"2022-10-01T12:43:41Z","isPatch":true,"sender":{"key":"bagasdotme@gmail.com","avatar":"https://avatars.githubusercontent.com/u/40219486?v=4"},"body":"On 10/1/22 05:47, Rubén Justo wrote:\n> This commit makes the error descriptions for those branch operations\n> with unborn or non-existent branches, more informative.\n> \n\ns/This commit makes/Make/\n\n-- \nAn old man doll... just what I always wanted! - Clara\n"},{"id":"464058","messageId":"a1cddefd-d555-05a0-a817-c8b10254fd9f@gmail.com","threadId":"58498","inReplyTo":"f34912ab-5d1b-6dfb-e079-0e7b135ebe14@gmail.com","subject":"Re: [PATCH v2] branch: description for non-existent branch errors","fromName":"Rubén Justo","fromEmail":"rjusto@gmail.com","sentAt":"2022-10-02T21:28:27Z","receivedAt":"2022-10-02T21:28:33Z","isPatch":true,"sender":{"key":"rjusto@gmail.com","avatar":"https://avatars.githubusercontent.com/u/5685487?v=4"},"body":"On 1/10/22 14:43, Bagas Sanjaya wrote:\n> On 10/1/22 05:47, Rubén Justo wrote:\n>> This commit makes the error descriptions for those branch operations\n>> with unborn or non-existent branches, more informative.\n>>\n> \n> s/This commit makes/Make/\n> \n\nThanks\n"},{"id":"464407","messageId":"8d627a2c-923f-181f-a03b-15f370c4dd0f@gmail.com","threadId":"58498","inReplyTo":"930ff836-a5c4-0e85-517d-39645f00cd31@gmail.com","subject":"[PATCH v3] branch: description for non-existent branch errors","fromName":"Rubén Justo","fromEmail":"rjusto@gmail.com","sentAt":"2022-10-08T00:39:43Z","receivedAt":"2022-10-08T00:39:51Z","isPatch":true,"sender":{"key":"rjusto@gmail.com","avatar":"https://avatars.githubusercontent.com/u/5685487?v=4"},"body":"When the repository does not yet have commits, some errors describe that\nthere is no branch:\n\n    $ git init -b first\n\n    $ git branch --edit-description first\n    error: No branch named 'first'.\n\n    $ git branch --set-upstream-to=upstream\n    fatal: branch 'first' does not exist\n\n    $ git branch -c second\n    error: refname refs/heads/first not found\n    fatal: Branch copy failed\n\nThat \"first\" branch is unborn but to say it doesn't exists is confusing.\n\nOptions \"-c\" (copy) and \"-m\" (rename) show the same error when the\norigin branch doesn't exists:\n\n    $ git branch -c non-existent-branch second\n    error: refname refs/heads/non-existent-branch not found\n    fatal: Branch copy failed\n\n    $ git branch -m non-existent-branch second\n    error: refname refs/heads/non-existent-branch not found\n    fatal: Branch rename failed\n\nNote that \"--edit-description\" without an explicit argument is already\nconsidering the _empty repository_ circumstance in its error.  Also note\nthat \"-m\" on the initial branch it is an allowed operation.\n\nMake the error descriptions for those branch operations with unborn or\nnon-existent branches, more informative.\n\nThis is the result of the change:\n\n    $ git init -b first\n\n    $ git branch --edit-description first\n    error: No commit on branch 'first' yet.\n\n    $ git branch --set-upstream-to=upstream\n    fatal: No commit on branch 'first' yet.\n\n    $ git branch -c second\n    fatal: No commit on branch 'first' yet.\n\n    $ git branch [-c/-m] non-existent-branch second\n    fatal: No branch named 'non-existent-branch'.\n\nSigned-off-by: Rubén Justo <rjusto@gmail.com>\n---\nRange-diff:\n1:  d8c3242b31 ! 1:  180435ff15 branch: description for non-existent branch errors\n    @@ Commit message\n         considering the _empty repository_ circumstance in its error.  Also note\n         that \"-m\" on the initial branch it is an allowed operation.\n     \n    -    This commit makes the error descriptions for those branch operations\n    -    with unborn or non-existent branches, more informative.\n    +    Make the error descriptions for those branch operations with unborn or\n    +    non-existent branches, more informative.\n     \n         This is the result of the change:\n     \n\n builtin/branch.c       | 14 +++++++++++--\n t/t3202-show-branch.sh | 46 ++++++++++++++++++++++++++++++++++++++++++\n 2 files changed, 58 insertions(+), 2 deletions(-)\n\ndiff --git a/builtin/branch.c b/builtin/branch.c\nindex 55cd9a6e99..499ebec99e 100644\n--- a/builtin/branch.c\n+++ b/builtin/branch.c\n@@ -538,6 +538,13 @@ static void copy_or_rename_branch(const char *oldname, const char *newname, int\n \t\t\tdie(_(\"Invalid branch name: '%s'\"), oldname);\n \t}\n \n+\tif ((copy || strcmp(head, oldname)) && !ref_exists(oldref.buf)) {\n+\t\tif (copy && !strcmp(head, oldname))\n+\t\t\tdie(_(\"No commit on branch '%s' yet.\"), oldname);\n+\t\telse\n+\t\t\tdie(_(\"No branch named '%s'.\"), oldname);\n+\t}\n+\n \t/*\n \t * A command like \"git branch -M currentbranch currentbranch\" cannot\n \t * cause the worktree to become inconsistent with HEAD, so allow it.\n@@ -805,7 +812,7 @@ int cmd_branch(int argc, const char **argv, const char *prefix)\n \t\tif (!ref_exists(branch_ref.buf)) {\n \t\t\tstrbuf_release(&branch_ref);\n \n-\t\t\tif (!argc)\n+\t\t\tif (!argc || !strcmp(head, branch_name))\n \t\t\t\treturn error(_(\"No commit on branch '%s' yet.\"),\n \t\t\t\t\t     branch_name);\n \t\t\telse\n@@ -848,8 +855,11 @@ int cmd_branch(int argc, const char **argv, const char *prefix)\n \t\t\tdie(_(\"no such branch '%s'\"), argv[0]);\n \t\t}\n \n-\t\tif (!ref_exists(branch->refname))\n+\t\tif (!ref_exists(branch->refname)) {\n+\t\t\tif (!argc || !strcmp(head, branch->name))\n+\t\t\t\tdie(_(\"No commit on branch '%s' yet.\"), branch->name);\n \t\t\tdie(_(\"branch '%s' does not exist\"), branch->name);\n+\t\t}\n \n \t\tdwim_and_setup_tracking(the_repository, branch->name,\n \t\t\t\t\tnew_upstream, BRANCH_TRACK_OVERRIDE,\ndiff --git a/t/t3202-show-branch.sh b/t/t3202-show-branch.sh\nindex f2b9199007..ea7cfd1951 100755\n--- a/t/t3202-show-branch.sh\n+++ b/t/t3202-show-branch.sh\n@@ -7,6 +7,28 @@ test_description='test show-branch'\n # arbitrary reference time: 2009-08-30 19:20:00\n GIT_TEST_DATE_NOW=1251660000; export GIT_TEST_DATE_NOW\n \n+test_expect_success 'error descriptions on empty repository' '\n+\tcurrent=$(git branch --show-current) &&\n+\tcat >expect <<-EOF &&\n+\terror: No commit on branch '\\''$current'\\'' yet.\n+\tEOF\n+\ttest_must_fail git branch --edit-description 2>actual &&\n+\ttest_cmp expect actual &&\n+\ttest_must_fail git branch --edit-description $current 2>actual &&\n+\ttest_cmp expect actual\n+'\n+\n+test_expect_success 'fatal descriptions on empty repository' '\n+\tcurrent=$(git branch --show-current) &&\n+\tcat >expect <<-EOF &&\n+\tfatal: No commit on branch '\\''$current'\\'' yet.\n+\tEOF\n+\ttest_must_fail git branch --set-upstream-to=non-existent 2>actual &&\n+\ttest_cmp expect actual &&\n+\ttest_must_fail git branch -c new-branch 2>actual &&\n+\ttest_cmp expect actual\n+'\n+\n test_expect_success 'setup' '\n \ttest_commit initial &&\n \tfor i in $(test_seq 1 10)\n@@ -175,4 +197,28 @@ done <<\\EOF\n --reflog --current\n EOF\n \n+test_expect_success 'error descriptions on non-existent branch' '\n+\tcat >expect <<-EOF &&\n+\terror: No branch named '\\''non-existent'\\'.'\n+\tEOF\n+\ttest_must_fail git branch --edit-description non-existent 2>actual &&\n+\ttest_cmp expect actual\n+'\n+\n+test_expect_success 'fatal descriptions on non-existent branch' '\n+\tcat >expect <<-EOF &&\n+\tfatal: branch '\\''non-existent'\\'' does not exist\n+\tEOF\n+\ttest_must_fail git branch --set-upstream-to=non-existent non-existent 2>actual &&\n+\ttest_cmp expect actual &&\n+\n+\tcat >expect <<-EOF &&\n+\tfatal: No branch named '\\''non-existent'\\''.\n+\tEOF\n+\ttest_must_fail git branch -c non-existent new-branch 2>actual &&\n+\ttest_cmp expect actual &&\n+\ttest_must_fail git branch -m non-existent new-branch 2>actual &&\n+\ttest_cmp expect actual\n+'\n+\n test_done\n-- \n2.32.0\n"},{"id":"464410","messageId":"CAPig+cT+Yeh95p-2PgMDYz+_AxeEA72i-zLuQu11QEyWAt8kiA@mail.gmail.com","threadId":"58498","inReplyTo":"8d627a2c-923f-181f-a03b-15f370c4dd0f@gmail.com","subject":"Re: [PATCH v3] branch: description for non-existent branch errors","fromName":"Eric Sunshine","fromEmail":"sunshine@sunshineco.com","sentAt":"2022-10-08T03:27:33Z","receivedAt":"2022-10-08T03:27:50Z","isPatch":true,"sender":{"key":"sunshine@sunshineco.com","avatar":"https://avatars.githubusercontent.com/u/163641?v=4"},"body":"On Fri, Oct 7, 2022 at 8:49 PM Rubén Justo <rjusto@gmail.com> wrote:\n> [...]\n> Make the error descriptions for those branch operations with unborn or\n> non-existent branches, more informative.\n> [...]\n> Signed-off-by: Rubén Justo <rjusto@gmail.com>\n> ---\n> diff --git a/t/t3202-show-branch.sh b/t/t3202-show-branch.sh\n> @@ -7,6 +7,28 @@ test_description='test show-branch'\n> +test_expect_success 'error descriptions on empty repository' '\n> +       current=$(git branch --show-current) &&\n> +       cat >expect <<-EOF &&\n> +       error: No commit on branch '\\''$current'\\'' yet.\n> +       EOF\n\nIt's a matter of taste, but leaving and re-entering the single-quoted\ncontext, along with escaping, can make for a difficult read. You could\ninstead take advantage of the SQ variable already defined by the test\nscripts:\n\n    echo \"error: No commit on branch $SQ$current$SQ yet.\" >expect &&\n\nNot worth a re-roll, of course.\n\n> +test_expect_success 'fatal descriptions on empty repository' '\n> +       current=$(git branch --show-current) &&\n> +       cat >expect <<-EOF &&\n> +       fatal: No commit on branch '\\''$current'\\'' yet.\n> +       EOF\n\nDitto.\n\n> +test_expect_success 'error descriptions on non-existent branch' '\n> +       cat >expect <<-EOF &&\n> +       error: No branch named '\\''non-existent'\\'.'\n> +       EOF\n\nLikewise.\n\n> +test_expect_success 'fatal descriptions on non-existent branch' '\n> +       cat >expect <<-EOF &&\n> +       fatal: branch '\\''non-existent'\\'' does not exist\n> +       EOF\n\nSame.\n\n> +       test_must_fail git branch --set-upstream-to=non-existent non-existent 2>actual &&\n> +       test_cmp expect actual &&\n> +\n> +       cat >expect <<-EOF &&\n> +       fatal: No branch named '\\''non-existent'\\''.\n> +       EOF\n\nAgain.\n"},{"id":"464421","messageId":"7a332503-d267-6d2c-c2bd-d072411ca408@gmail.com","threadId":"58498","inReplyTo":"CAPig+cT+Yeh95p-2PgMDYz+_AxeEA72i-zLuQu11QEyWAt8kiA@mail.gmail.com","subject":"Re: [PATCH v3] branch: description for non-existent branch errors","fromName":"Rubén Justo","fromEmail":"rjusto@gmail.com","sentAt":"2022-10-08T08:54:12Z","receivedAt":"2022-10-08T08:54:19Z","isPatch":true,"sender":{"key":"rjusto@gmail.com","avatar":"https://avatars.githubusercontent.com/u/5685487?v=4"},"body":"\nOn 8/10/22 5:27, Eric Sunshine wrote:\n> On Fri, Oct 7, 2022 at 8:49 PM Rubén Justo <rjusto@gmail.com> wrote:\n>> [...]\n>> Make the error descriptions for those branch operations with unborn or\n>> non-existent branches, more informative.\n>> [...]\n>> Signed-off-by: Rubén Justo <rjusto@gmail.com>\n>> ---\n>> diff --git a/t/t3202-show-branch.sh b/t/t3202-show-branch.sh\n>> @@ -7,6 +7,28 @@ test_description='test show-branch'\n>> +test_expect_success 'error descriptions on empty repository' '\n>> +       current=$(git branch --show-current) &&\n>> +       cat >expect <<-EOF &&\n>> +       error: No commit on branch '\\''$current'\\'' yet.\n>> +       EOF\n> \n> It's a matter of taste, but leaving and re-entering the single-quoted\n> context, along with escaping, can make for a difficult read. You could\n> instead take advantage of the SQ variable already defined by the test\n> scripts:\n> \n>     echo \"error: No commit on branch $SQ$current$SQ yet.\" >expect &&\n> \n> Not worth a re-roll, of course.\n> \n>> +test_expect_success 'fatal descriptions on empty repository' '\n>> +       current=$(git branch --show-current) &&\n>> +       cat >expect <<-EOF &&\n>> +       fatal: No commit on branch '\\''$current'\\'' yet.\n>> +       EOF\n> \n> Ditto.\n\nThanks, I didn't know about $SQ.\n\n\t'\\''$current'\\'' vs $SQ$current$SQ vs ${SQ}$current${SQ}\n\nI also find ugly that escaping, but I think is harder to read and\nerror prone to use $SQ here.. :-/\n\n"},{"id":"464438","messageId":"xmqq4jwda8oc.fsf@gitster.g","threadId":"58498","inReplyTo":"7a332503-d267-6d2c-c2bd-d072411ca408@gmail.com","subject":"Re: [PATCH v3] branch: description for non-existent branch errors","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2022-10-09T05:05:23Z","receivedAt":"2022-10-09T05:12:28Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Rubén Justo <rjusto@gmail.com> writes:\n\n> Thanks, I didn't know about $SQ.\n>\n> \t'\\''$current'\\'' vs $SQ$current$SQ vs ${SQ}$current${SQ}\n>\n> I also find ugly that escaping, but I think is harder to read and\n> error prone to use $SQ here.. :-/\n\nThe ONLY case when $SQ shines is when the string that comes inside\nthe single-quote pair begins with a non-alnum.  $SQ$current$SQ is\nsemi-readable, but if the string begins with an alnum, then you'd be\nforced to say ${SQ}current${SQ} (the first one must be inside braces\nbecause you do not want to refer to a variable whose name is\nSQcurrent, the second one wants to be inside braces for symmetry),\nwhich is ugly.\n\nThe rhythm of '\\'' is not so bad, once you get used to seeing them.\n${SQ}...${SQ} is a bit too loud.\n"}]}