{"thread":{"id":"55789","subject":"git push doesn't use local branch name as default","startedAt":"2021-05-28T06:29:55Z","lastAt":"2021-05-30T16:32:24Z","messageCount":12,"participants":["Mathias Kunter","Elijah Newren","Felipe Contreras"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"425743","messageId":"fcf30899-8e64-5417-f478-14d6aca72544@gmail.com","threadId":"55789","inReplyTo":"3b9bc214-a30a-ba49-af96-7eeaf37b7bbd@gmail.com","subject":"git push doesn't use local branch name as default","fromName":"Mathias Kunter","fromEmail":"mathiaskunter@gmail.com","sentAt":"2021-05-28T06:29:49Z","receivedAt":"2021-05-28T06:29:55Z","isPatch":false,"sender":{"key":"mathiaskunter@gmail.com","avatar":"https://gravatar.com/avatar/131a813ba8d2cb36edb0d102971af5b523bad01aa9c842822e0d068b350bc4e8?d=mp&s=160"},"body":"Felipe,\n\nthanks for your reply.\n\n> Sounds like you want to change the default to `push.default=current`.\n\nYes, but shouldn't `simple` pushing also work? The documentation says \nabout `push.default=simple`:\n\n> When pushing to a remote that is different from the remote you normally\n> pull from, work as `current`.\n\nIf there is no upstream, then there also is no \"remote I normally pull \nfrom\", and thus, according to the doc, `simple` should actually work \nlike `current` in this case. Am I wrong here?\n\nIf `simple` pushing is used, it doesn't seem to make sense for me to \nfallback to `current` on branches which *do* have an upstream, but to \nerror out on branches which do *not* have an upstream.\n\nCheers\nMathias Kunter\n\n\nAm 27.05.21 um 21:51 schrieb Felipe Contreras:\n> Mathias Kunter wrote:\n>> Hi all,\n>>\n>> at https://git-scm.com/docs/git-push#_description it says:\n>>\n>>> When neither the command-line nor the configuration specify what to\n>>> push, the default behavior is used, which corresponds to the simple\n>>> value for push.default: the current branch is pushed to the\n>>> corresponding upstream branch, but as a safety measure, the push is\n>>> aborted if the upstream branch does not have the same name as the local\n>>> one.\n>>\n>> However, on a branch which does *not* have an upstream branch\n>> configured, the command\n>>\n>>> git push <remote_name>\n>>\n>> doesn't use the local branch name as default,\n> \n> Yes it does, but only on the src side of the refspec. Something like:\n> \n>    git push <remote_name> <branch_name>:\n> \n> (invalid refspec)\n> \n> Note the remote side is missing, so git doesn't know where to push to.\n> \n>> Note that it *does* work if the remote branch name is explicitly specified:\n>>\n>>> git push <remote_name> <branch_name>\n> \n> In that case git assumes you mean <branch_name>:<branch_name>.\n> \n> Sounds like you want to change the default to `push.default=current`.\n> \n> Cheers.\n> \n"},{"id":"425744","messageId":"CABPp-BEeqqGwN3=MbWCYnsyryBm3WoaX5GZyXTWy18UiYUT4zg@mail.gmail.com","threadId":"55789","inReplyTo":"fcf30899-8e64-5417-f478-14d6aca72544@gmail.com","subject":"Re: git push doesn't use local branch name as default","fromName":"Elijah Newren","fromEmail":"newren@gmail.com","sentAt":"2021-05-28T07:00:46Z","receivedAt":"2021-05-28T07:01:03Z","isPatch":false,"sender":{"key":"newren@gmail.com","avatar":"https://avatars.githubusercontent.com/u/5455730?v=4"},"body":"On Thu, May 27, 2021 at 11:39 PM Mathias Kunter <mathiaskunter@gmail.com> wrote:\n>\n> Felipe,\n>\n> thanks for your reply.\n>\n> > Sounds like you want to change the default to `push.default=current`.\n>\n> Yes, but shouldn't `simple` pushing also work? The documentation says\n> about `push.default=simple`:\n>\n> > When pushing to a remote that is different from the remote you normally\n> > pull from, work as `current`.\n\nPerhaps this wording should be clarified to read\n\nWhen you have a remote that you normally pull from but you are pushing\nto a different remote then that one, then work as 'current'.\n\n> If there is no upstream, then there also is no \"remote I normally pull\n> from\", and thus, according to the doc, `simple` should actually work\n> like `current` in this case. Am I wrong here?\n\nThe relevant code is\n\n    return (fetch_remote && fetch_remote != remote);\n\nso you only get the \"current\" behavior when fetch_remote is non-NULL.\n"},{"id":"425746","messageId":"f9f38d42-2b93-0d3b-798b-4c6f44eb111d@gmail.com","threadId":"55789","inReplyTo":"CABPp-BEeqqGwN3=MbWCYnsyryBm3WoaX5GZyXTWy18UiYUT4zg@mail.gmail.com","subject":"Re: git push doesn't use local branch name as default","fromName":"Mathias Kunter","fromEmail":"mathiaskunter@gmail.com","sentAt":"2021-05-28T07:44:00Z","receivedAt":"2021-05-28T07:44:14Z","isPatch":false,"sender":{"key":"mathiaskunter@gmail.com","avatar":"https://gravatar.com/avatar/131a813ba8d2cb36edb0d102971af5b523bad01aa9c842822e0d068b350bc4e8?d=mp&s=160"},"body":"> you only get the \"current\" behavior when fetch_remote is non-NULL.\n\nWell, then my suggestion actually is to also use the `current` behavior \nwhen fetch_remote is NULL - i.e. change\n\n> return (fetch_remote && fetch_remote != remote);\n\nto\n\n> return (!fetch_remote || fetch_remote != remote);\n\nI'd argue that if `simple` pushing is used, then the expected behavior \nof the command\n\n> git push <remote_name>\n\non a branch without upstream would actually be to use the `current` \nbehavior instead of bailing out with an error.\n\n\nAm 28.05.21 um 09:00 schrieb Elijah Newren:\n> On Thu, May 27, 2021 at 11:39 PM Mathias Kunter <mathiaskunter@gmail.com> wrote:\n>>\n>> Felipe,\n>>\n>> thanks for your reply.\n>>\n>>> Sounds like you want to change the default to `push.default=current`.\n>>\n>> Yes, but shouldn't `simple` pushing also work? The documentation says\n>> about `push.default=simple`:\n>>\n>>> When pushing to a remote that is different from the remote you normally\n>>> pull from, work as `current`.\n> \n> Perhaps this wording should be clarified to read\n> \n> When you have a remote that you normally pull from but you are pushing\n> to a different remote then that one, then work as 'current'.\n> \n>> If there is no upstream, then there also is no \"remote I normally pull\n>> from\", and thus, according to the doc, `simple` should actually work\n>> like `current` in this case. Am I wrong here?\n> \n> The relevant code is\n> \n>      return (fetch_remote && fetch_remote != remote);\n> \n> so you only get the \"current\" behavior when fetch_remote is non-NULL.\n> \n"},{"id":"425749","messageId":"287483ba-d682-6d04-23fa-22c33ab70376@gmail.com","threadId":"55789","inReplyTo":"f9f38d42-2b93-0d3b-798b-4c6f44eb111d@gmail.com","subject":"Re: git push doesn't use local branch name as default","fromName":"Mathias Kunter","fromEmail":"mathiaskunter@gmail.com","sentAt":"2021-05-28T08:51:22Z","receivedAt":"2021-05-28T08:51:29Z","isPatch":false,"sender":{"key":"mathiaskunter@gmail.com","avatar":"https://gravatar.com/avatar/131a813ba8d2cb36edb0d102971af5b523bad01aa9c842822e0d068b350bc4e8?d=mp&s=160"},"body":"Note that git itself also claims this should be working. If I do a \"git \npush\" on a branch without upstream, I will get:\n\n> fatal: No configured push destination.\n> Either specify the URL from the command-line or configure a remote repository using\n> \n>     git remote add <name> <url>\n> \n> and then push using the remote name\n> \n>     git push <name>\n\nHowever, the advised \"git push <name>\" command won't work on that branch \nwith the default settings of Git. To make it work, `simple` pushing \nwould have to use `current` behavior on a branch without upstream.\n\nPlease consider changing that. Thank you.\n\nCheers\nMathias Kunter\n\n\nAm 28.05.21 um 09:44 schrieb Mathias Kunter:\n>> you only get the \"current\" behavior when fetch_remote is non-NULL.\n> \n> Well, then my suggestion actually is to also use the `current` behavior \n> when fetch_remote is NULL - i.e. change\n> \n>> return (fetch_remote && fetch_remote != remote);\n> \n> to\n> \n>> return (!fetch_remote || fetch_remote != remote);\n> \n> I'd argue that if `simple` pushing is used, then the expected behavior \n> of the command\n> \n>> git push <remote_name>\n> \n> on a branch without upstream would actually be to use the `current` \n> behavior instead of bailing out with an error.\n> \n> \n> Am 28.05.21 um 09:00 schrieb Elijah Newren:\n>> On Thu, May 27, 2021 at 11:39 PM Mathias Kunter \n>> <mathiaskunter@gmail.com> wrote:\n>>>\n>>> Felipe,\n>>>\n>>> thanks for your reply.\n>>>\n>>>> Sounds like you want to change the default to `push.default=current`.\n>>>\n>>> Yes, but shouldn't `simple` pushing also work? The documentation says\n>>> about `push.default=simple`:\n>>>\n>>>> When pushing to a remote that is different from the remote you normally\n>>>> pull from, work as `current`.\n>>\n>> Perhaps this wording should be clarified to read\n>>\n>> When you have a remote that you normally pull from but you are pushing\n>> to a different remote then that one, then work as 'current'.\n>>\n>>> If there is no upstream, then there also is no \"remote I normally pull\n>>> from\", and thus, according to the doc, `simple` should actually work\n>>> like `current` in this case. Am I wrong here?\n>>\n>> The relevant code is\n>>\n>>      return (fetch_remote && fetch_remote != remote);\n>>\n>> so you only get the \"current\" behavior when fetch_remote is non-NULL.\n>>\n"},{"id":"425815","messageId":"60b123f8b0586_5190820868@natae.notmuch","threadId":"55789","inReplyTo":"fcf30899-8e64-5417-f478-14d6aca72544@gmail.com","subject":"RE: git push doesn't use local branch name as default","fromName":"Felipe Contreras","fromEmail":"felipe.contreras@gmail.com","sentAt":"2021-05-28T17:10:16Z","receivedAt":"2021-05-28T17:10:28Z","isPatch":false,"sender":{"key":"felipe.contreras@gmail.com","avatar":"https://avatars.githubusercontent.com/u/8358?v=4"},"body":"Mathias Kunter wrote:\n> Felipe,\n> \n> thanks for your reply.\n> \n> > Sounds like you want to change the default to `push.default=current`.\n> \n> Yes, but shouldn't `simple` pushing also work? The documentation says \n> about `push.default=simple`:\n> \n> > When pushing to a remote that is different from the remote you normally\n> > pull from, work as `current`.\n> \n> If there is no upstream, then there also is no \"remote I normally pull \n> from\",\n\nIf there's no upstream the remote is \"origin\".\n\n> and thus, according to the doc, `simple` should actually work \n> like `current` in this case. Am I wrong here?\n\nOnly if you are not pushing to \"origin\".\n\n> If `simple` pushing is used, it doesn't seem to make sense for me to \n> fallback to `current` on branches which *do* have an upstream, but to \n> error out on branches which do *not* have an upstream.\n\nThat is not the criteria. It depends whether or not you are in a\ntriangular workflow [1].\n\nIf you pull from kernel.org, but push to github.com, then you are in a\ntriangular workflow and the name of the branch is not checked.\n\nThe oposite is a centralized workflow, where you pull and push to the\nsame repository, then git adds an extra check.\n\nIf you don't want to set `push.default`, you can alternatively rename\nyour remote to something other than \"origin\", then your branches with no\nupstram truly would have nowhere to fetch from.\n\nBut then `git fetch` without arguments will not do anything.\n\nCheers.\n\n[1] https://felipec.wordpress.com/2014/05/11/git-triangular-workflows/\n\n-- \nFelipe Contreras\n"},{"id":"425816","messageId":"60b126e8cf42e_51908208d4@natae.notmuch","threadId":"55789","inReplyTo":"CABPp-BEeqqGwN3=MbWCYnsyryBm3WoaX5GZyXTWy18UiYUT4zg@mail.gmail.com","subject":"Re: git push doesn't use local branch name as default","fromName":"Felipe Contreras","fromEmail":"felipe.contreras@gmail.com","sentAt":"2021-05-28T17:22:48Z","receivedAt":"2021-05-28T17:22:54Z","isPatch":false,"sender":{"key":"felipe.contreras@gmail.com","avatar":"https://avatars.githubusercontent.com/u/8358?v=4"},"body":"Elijah Newren wrote:\n> > If there is no upstream, then there also is no \"remote I normally pull\n> > from\", and thus, according to the doc, `simple` should actually work\n> > like `current` in this case. Am I wrong here?\n> \n> The relevant code is\n> \n>     return (fetch_remote && fetch_remote != remote);\n> \n> so you only get the \"current\" behavior when fetch_remote is non-NULL.\n\nfetch_remote is practically never non-NULL.\n\nfetch_remote is remote_get(NULL), which is basically the equivalent of:\n\nremote_get(remote_for_branch(current_branch, ...));\n\nTypically when an upstream branch is not configured, this is the same\nas:\n\nremote_get(\"origin\");\n\nThe only time fetch_remote is NULL is when the configured remote is\ninvalid.\n\nSo you don't get the \"current\" behavior when pushing to \"origin\".\n\nPerhaps:\n\n--- a/Documentation/config/push.txt\n+++ b/Documentation/config/push.txt\n@@ -29,8 +29,8 @@ push.default::\n   different from the local one.\n +\n When pushing to a remote that is different from the remote you normally\n-pull from, work as `current`.  This is the safest option and is suited\n-for beginners.\n+pull from (typically \"origin\"), work as `current`.  This is the safest option\n+and is suited for beginners.\n +\n This mode has become the default in Git 2.0.\n\n-- \nFelipe Contreras\n"},{"id":"425817","messageId":"CABPp-BEd2GAOSSAaUwMLhftiKsbFXmuszH_fXBbTY9nU=yWg9w@mail.gmail.com","threadId":"55789","inReplyTo":"60b126e8cf42e_51908208d4@natae.notmuch","subject":"Re: git push doesn't use local branch name as default","fromName":"Elijah Newren","fromEmail":"newren@gmail.com","sentAt":"2021-05-28T17:44:30Z","receivedAt":"2021-05-28T17:44:45Z","isPatch":false,"sender":{"key":"newren@gmail.com","avatar":"https://avatars.githubusercontent.com/u/5455730?v=4"},"body":"On Fri, May 28, 2021 at 10:22 AM Felipe Contreras\n<felipe.contreras@gmail.com> wrote:\n>\n> Elijah Newren wrote:\n> > > If there is no upstream, then there also is no \"remote I normally pull\n> > > from\", and thus, according to the doc, `simple` should actually work\n> > > like `current` in this case. Am I wrong here?\n> >\n> > The relevant code is\n> >\n> >     return (fetch_remote && fetch_remote != remote);\n> >\n> > so you only get the \"current\" behavior when fetch_remote is non-NULL.\n>\n> fetch_remote is practically never non-NULL.\n>\n> fetch_remote is remote_get(NULL), which is basically the equivalent of:\n>\n> remote_get(remote_for_branch(current_branch, ...));\n>\n> Typically when an upstream branch is not configured, this is the same\n> as:\n>\n> remote_get(\"origin\");\n>\n> The only time fetch_remote is NULL is when the configured remote is\n> invalid.\n\nAh, thanks for correcting and clarifying here.\n\n>\n> So you don't get the \"current\" behavior when pushing to \"origin\".\n>\n> Perhaps:\n>\n> --- a/Documentation/config/push.txt\n> +++ b/Documentation/config/push.txt\n> @@ -29,8 +29,8 @@ push.default::\n>    different from the local one.\n>  +\n>  When pushing to a remote that is different from the remote you normally\n> -pull from, work as `current`.  This is the safest option and is suited\n> -for beginners.\n> +pull from (typically \"origin\"), work as `current`.  This is the safest option\n> +and is suited for beginners.\n\nThis is certainly an improvement.  I wonder if it might still be\nconsidered ambiguous or hard to parse, though.  If so, maybe something\nlike:\n\nIf you have a default remote configured for the current branch and are\npushing to a remote other than that one (or if you have no default\nremote configured and are pushing to a remote other than 'origin'),\nthen work as 'current'.\n\nIt may also be helpful to move the \"This is the safest option and is\nsuited for beginners\" out of its current paragraph and combine it with\nthe \"This mode has become the default\" in the next paragraph.\n"},{"id":"425818","messageId":"60b12dc1f19b1_5190820879@natae.notmuch","threadId":"55789","inReplyTo":"f9f38d42-2b93-0d3b-798b-4c6f44eb111d@gmail.com","subject":"Re: git push doesn't use local branch name as default","fromName":"Felipe Contreras","fromEmail":"felipe.contreras@gmail.com","sentAt":"2021-05-28T17:52:01Z","receivedAt":"2021-05-28T17:53:15Z","isPatch":false,"sender":{"key":"felipe.contreras@gmail.com","avatar":"https://avatars.githubusercontent.com/u/8358?v=4"},"body":"Mathias Kunter wrote:\n> > you only get the \"current\" behavior when fetch_remote is non-NULL.\n> \n> Well, then my suggestion actually is to also use the `current` behavior \n> when fetch_remote is NULL - i.e. change\n> \n> > return (fetch_remote && fetch_remote != remote);\n> \n> to\n> \n> > return (!fetch_remote || fetch_remote != remote);\n\nIt's not quite that easy. You need to see the context of that code:\n\n  static int is_workflow_triangular(struct remote *remote)\n  {\n    struct remote *fetch_remote = remote_get(NULL);\n    return (fetch_remote && fetch_remote != remote);\n  }\n\nThat would affect many pathways.\n\n> I'd argue that if `simple` pushing is used, then the expected behavior \n> of the command\n> \n> > git push <remote_name>\n> \n> on a branch without upstream would actually be to use the `current` \n> behavior instead of bailing out with an error.\n\nI agree, but this mis-mash of modes makes the logic very hard to see.\n\nI'll send patches to cleanup the logic, it makes no sense to have a\nfrankenstein of two modes and that is in fact the default mode. The\nlogic of the default mode should be crystal clear.\n\nCheers.\n\n-- \nFelipe Contreras\n"},{"id":"425820","messageId":"60b13d67cb8a7_e545b20876@natae.notmuch","threadId":"55789","inReplyTo":"CABPp-BEd2GAOSSAaUwMLhftiKsbFXmuszH_fXBbTY9nU=yWg9w@mail.gmail.com","subject":"Re: git push doesn't use local branch name as default","fromName":"Felipe Contreras","fromEmail":"felipe.contreras@gmail.com","sentAt":"2021-05-28T18:58:47Z","receivedAt":"2021-05-28T18:58:52Z","isPatch":false,"sender":{"key":"felipe.contreras@gmail.com","avatar":"https://avatars.githubusercontent.com/u/8358?v=4"},"body":"Elijah Newren wrote:\n> On Fri, May 28, 2021 at 10:22 AM Felipe Contreras\n> <felipe.contreras@gmail.com> wrote:\n\n> > Perhaps:\n> >\n> > --- a/Documentation/config/push.txt\n> > +++ b/Documentation/config/push.txt\n> > @@ -29,8 +29,8 @@ push.default::\n> >    different from the local one.\n> >  +\n> >  When pushing to a remote that is different from the remote you normally\n> > -pull from, work as `current`.  This is the safest option and is suited\n> > -for beginners.\n> > +pull from (typically \"origin\"), work as `current`.  This is the safest option\n> > +and is suited for beginners.\n> \n> This is certainly an improvement.  I wonder if it might still be\n> considered ambiguous or hard to parse, though.\n\nI am sure it is, just like plenty of the official documentation.\n\n> If so, maybe something like:\n> \n> If you have a default remote configured for the current branch\n\nThis is still very hard to parse, especially since there's no command to\n\"configure the remote of a branch\" (AFAIK).\n\n> and are pushing to a remote other than that one\n\nAnd you've lost me.\n\nI have to do a mental model of what's trying to be said:\n\n  x && pushed != x\n\nIf x is nil, then I can't push to it, so this is the same as:\n\n  pushed != x\n\n> (or if you have no default remote configured and are pushing to a\n> remote other than 'origin'),\n\nSo:\n\n  !x && pushed != 'origin'\n\nAltogether:\n\n  (pushed != x) || (!x && pushed != 'origin')\n\nSo:\n\n  pushed != (x || 'origin')\n\nAnd we can use an x that is more friendly to users (and there are\ncommands to set it):\n\n  If you are pushing to a remote that is not the same as the upstream\n  branch, or 'origin'...\n\n> then work as 'current'.\n\nAnd now I have to read what `current` is.\n\nThe current documentation is trying to replicate what the convoluted\ncode is doing, your version is a little better, but not by much.\n\n\nThis is much more straightforward:\n\n  pushes the current branch with the same name on the remote.\n\n  If you are working on a centralized workflow--pushing to the same\n  repository you pull from (typically `origin`)--then you need to\n  configure an upstream branch with the same name.\n\nWhen you describe the situation clearly (and not simply transcribe the\ncode), it becomes clear why users like Mathias don't see the current\nbehavior as sane.\n\nI'm working on some patches so the issue becomes clear for those who\ndon't speak user.\n\nCheers.\n\n-- \nFelipe Contreras\n"},{"id":"425839","messageId":"60b15cd2c4136_2183bc20893@natae.notmuch","threadId":"55789","inReplyTo":"287483ba-d682-6d04-23fa-22c33ab70376@gmail.com","subject":"git push default doesn't make sense","fromName":"Felipe Contreras","fromEmail":"felipe.contreras@gmail.com","sentAt":"2021-05-28T21:12:50Z","receivedAt":"2021-05-28T21:12:55Z","isPatch":false,"sender":{"key":"felipe.contreras@gmail.com","avatar":"https://avatars.githubusercontent.com/u/8358?v=4"},"body":"Mathias Kunter wrote:\n> However, the advised \"git push <name>\" command won't work on that branch \n> with the default settings of Git. To make it work, `simple` pushing \n> would have to use `current` behavior on a branch without upstream.\n> \n> Please consider changing that. Thank you.\n\nOK, after reorganizing the code to actually make it understandable [1],\nI ended up with this:\n\n\tif (centralized) {\n\t\tif (!branch->merge_nr || !branch->merge || !branch->remote_name)\n\t\t\tdie(_(\"The current branch %s has no upstream branch.\\n\"\n\t\t\t    \"To push the current branch and set the remote as upstream, use\\n\"\n\t\t\t    \"\\n\"\n\t\t\t    \"    git push --set-upstream %s %s\\n\"),\n\t\t\t    branch->name,\n\t\t\t    remote->name,\n\t\t\t    branch->name);\n\t\tif (branch->merge_nr != 1)\n\t\t\tdie(_(\"The current branch %s has multiple upstream branches, \"\n\t\t\t    \"refusing to push.\"), branch->name);\n\n\t\t/* Additional safety */\n\t\tif (strcmp(branch->refname, branch->merge[0]->src))\n\t\t\tdie_push_simple(branch, remote);\n\t}\n\trefspec_appendf(&rs, \"%s:%s\", branch->refname, branch->refname);\n\nI agree this doesn't make sense.\n\nIf this works:\n\n  git clone $central .\n  ...\n  git push\n\nThen this should too:\n\n  git clone $central .\n  git checkout -b fix-1\n  ...\n  git push\n\nCloning automatically sets up an upstream branch for \"master\", and\ntherore it passes the safety check of `push.default=simple`, and that is\nmuch more dangerous than pushing any other branch.\n\nWhy do we barf with \"fix-1\", but not \"master\"? Doesn't make sense.\n\nThis is what we want:\n\n\tif (centralized &&\n\t\t(branch->merge_nr && branch->merge && branch->remote_name))\n\t{\n\t\tif (branch->merge_nr != 1)\n\t\t\tdie(_(\"The current branch %s has multiple upstream branches, \"\n\t\t\t    \"refusing to push.\"), branch->name);\n\n\t\t/* Additional safety */\n\t\tif (strcmp(branch->refname, branch->merge[0]->src))\n\t\t\tdie_push_simple(branch, remote);\n\t}\n\trefspec_appendf(&rs, \"%s:%s\", branch->refname, branch->refname);\n\n\nIn other words: `simple` should be the same as `current`, except when\nthere's an upstream branch configured *and* the destination branch has a\ndifferent name.\n\nCheers.\n\n[1] https://lore.kernel.org/git/20210528201014.2175179-1-felipe.contreras@gmail.com/\n\n-- \nFelipe Contreras\n"},{"id":"425929","messageId":"d9e212fa-4c6a-f6ce-eab0-8073a65e96fd@gmail.com","threadId":"55789","inReplyTo":"60b15cd2c4136_2183bc20893@natae.notmuch","subject":"Re: git push default doesn't make sense","fromName":"Mathias Kunter","fromEmail":"mathiaskunter@gmail.com","sentAt":"2021-05-30T16:28:19Z","receivedAt":"2021-05-30T16:28:24Z","isPatch":false,"sender":{"key":"mathiaskunter@gmail.com","avatar":"https://gravatar.com/avatar/131a813ba8d2cb36edb0d102971af5b523bad01aa9c842822e0d068b350bc4e8?d=mp&s=160"},"body":"Am 28.05.21 um 23:12 schrieb Felipe Contreras:\n\n> Cloning automatically sets up an upstream branch for \"master\", and\n> therore it passes the safety check of `push.default=simple`, and that is\n> much more dangerous than pushing any other branch.\n> \n> Why do we barf with \"fix-1\", but not \"master\"? Doesn't make sense.\n> \n> This is what we want:\n> \n> \tif (centralized &&\n> \t\t(branch->merge_nr && branch->merge && branch->remote_name))\n> \t{\n> \t\tif (branch->merge_nr != 1)\n> \t\t\tdie(_(\"The current branch %s has multiple upstream branches, \"\n> \t\t\t    \"refusing to push.\"), branch->name);\n> \n> \t\t/* Additional safety */\n> \t\tif (strcmp(branch->refname, branch->merge[0]->src))\n> \t\t\tdie_push_simple(branch, remote);\n> \t}\n> \trefspec_appendf(&rs, \"%s:%s\", branch->refname, branch->refname);\n> \n> \n> In other words: `simple` should be the same as `current`, except when\n> there's an upstream branch configured *and* the destination branch has a\n> different name.\n\nI guess so. In particular, as a simple git user, I'd expect the \nfollowing to work out of the box, without having to manually adjust the \nconfiguration settings:\n\n   git clone ssh://originUrl .\n   git checkout -b myBranch\n   git push           # expected push to origin/myBranch, but fails\n   git push origin    # expected push to origin/myBranch, but fails\n   git remote add myRemote ssh://myRemoteUrl\n   git push myRemote  # expected push to myRemote/myBranch - works\n\nWill your provided patch fix these failing push commands?\n"},{"id":"425930","messageId":"60b3be1476401_b937208e1@natae.notmuch","threadId":"55789","inReplyTo":"d9e212fa-4c6a-f6ce-eab0-8073a65e96fd@gmail.com","subject":"Re: git push default doesn't make sense","fromName":"Felipe Contreras","fromEmail":"felipe.contreras@gmail.com","sentAt":"2021-05-30T16:32:20Z","receivedAt":"2021-05-30T16:32:24Z","isPatch":false,"sender":{"key":"felipe.contreras@gmail.com","avatar":"https://avatars.githubusercontent.com/u/8358?v=4"},"body":"Mathias Kunter wrote:\n> Am 28.05.21 um 23:12 schrieb Felipe Contreras:\n> \n> > Cloning automatically sets up an upstream branch for \"master\", and\n> > therore it passes the safety check of `push.default=simple`, and that is\n> > much more dangerous than pushing any other branch.\n> > \n> > Why do we barf with \"fix-1\", but not \"master\"? Doesn't make sense.\n> > \n> > This is what we want:\n> > \n> > \tif (centralized &&\n> > \t\t(branch->merge_nr && branch->merge && branch->remote_name))\n> > \t{\n> > \t\tif (branch->merge_nr != 1)\n> > \t\t\tdie(_(\"The current branch %s has multiple upstream branches, \"\n> > \t\t\t    \"refusing to push.\"), branch->name);\n> > \n> > \t\t/* Additional safety */\n> > \t\tif (strcmp(branch->refname, branch->merge[0]->src))\n> > \t\t\tdie_push_simple(branch, remote);\n> > \t}\n> > \trefspec_appendf(&rs, \"%s:%s\", branch->refname, branch->refname);\n> > \n> > \n> > In other words: `simple` should be the same as `current`, except when\n> > there's an upstream branch configured *and* the destination branch has a\n> > different name.\n> \n> I guess so. In particular, as a simple git user, I'd expect the \n> following to work out of the box, without having to manually adjust the \n> configuration settings:\n> \n>    git clone ssh://originUrl .\n>    git checkout -b myBranch\n>    git push           # expected push to origin/myBranch, but fails\n>    git push origin    # expected push to origin/myBranch, but fails\n>    git remote add myRemote ssh://myRemoteUrl\n>    git push myRemote  # expected push to myRemote/myBranch - works\n> \n> Will your provided patch fix these failing push commands?\n\nIt's not really a patch (yet), but yeah: it will.\n\n-- \nFelipe Contreras\n"}]}