{"thread":{"id":"49016","subject":"Squash & Merge Implementation","startedAt":"2018-08-03T12:01:30Z","lastAt":"2018-08-03T17:23:28Z","messageCount":3,"participants":["Vadim Belov","Jeff King"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"354375","messageId":"CALr1GiFBm9zJ1v-UWuVLWJJ+zFh-iTKOv=T4KETLN8qkW_0pAg@mail.gmail.com","threadId":"49016","inReplyTo":null,"subject":"Squash & Merge Implementation","fromName":"Vadim Belov","fromEmail":"vadim.belov@gmail.com","sentAt":"2018-08-03T12:01:15Z","receivedAt":"2018-08-03T12:01:30Z","isPatch":false,"sender":{"key":"vadim.belov@gmail.com","avatar":null},"body":"Hello,\nI'm trying to manually implement Github's *Squash&Merge *functionality.\nAfter looking many forums like stackoverflow.com I'm still struggling with\nthe issue.\n\n*The scenario is as follows*:\n- master is a protected branch (configured on github)\n- a service user *svc *is permitted to push to master (configured on github)\n- other users don't have such permissions\n- github PR status check is set to SUCCESS before execution of any set of\ngit commands below\n\n1. This merges successfully without squash:\ngit checkout origin/master\ngit merge ${PR-Branch}\ngit push origin HEAD:master\ngit push origin --delete ${PR-Branch}\n\n2. This closes the PR, but there is no update seen on master:\ngit checkout origin/master\ngit merge --squash --commit ${PR-Branch}\ngit push origin HEAD:master\ngit push origin --delete ${PR-Branch}\n\n3. This fails to push to master with the error \"GH006: Protected branch\nupdate failed\"  (despite that the PR is set to SUCCESS):\ngit checkout origin/master\ngit merge --squash ${PR-Branch}\ngit commit -am\"comment\"\ngit push origin HEAD:${m_mainBranch}\ngit push origin --delete ${m_prBranch}\n\n\nWill appreciate your help on this.\n\nThanks,\nVadim\n"},{"id":"354389","messageId":"20180803134901.GC28939@sigill.intra.peff.net","threadId":"49016","inReplyTo":"CALr1GiFBm9zJ1v-UWuVLWJJ+zFh-iTKOv=T4KETLN8qkW_0pAg@mail.gmail.com","subject":"Re: Squash & Merge Implementation","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2018-08-03T13:49:02Z","receivedAt":"2018-08-03T13:49:05Z","isPatch":false,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"On Fri, Aug 03, 2018 at 03:01:15PM +0300, Vadim Belov wrote:\n\n> 1. This merges successfully without squash:\n> git checkout origin/master\n> git merge ${PR-Branch}\n> git push origin HEAD:master\n> git push origin --delete ${PR-Branch}\n\nRight, this is a normal merge.\n\n> 2. This closes the PR, but there is no update seen on master:\n> git checkout origin/master\n> git merge --squash --commit ${PR-Branch}\n> git push origin HEAD:master\n> git push origin --delete ${PR-Branch}\n\nDoing \"merge --squash --commit\" doesn't do what you expect; namely\n\"--commit\" does not override the non-committing nature of \"--squash\". It\nonly override a \"--no-commit\" found elsewhere.\n\nIMHO this is something that could be improved in Git (i.e., telling the\ndifference between \"the user did not say --no-commit\" and \"the user said\n--commit\" and respecting it for --squash).\n\nBut that explains what you see. The push to master is a noop, since you\ndidn't make a new commit. And then deleting the PR branch on GitHub\nauto-closes the PR.\n\n> 3. This fails to push to master with the error \"GH006: Protected branch\n> update failed\"  (despite that the PR is set to SUCCESS):\n> git checkout origin/master\n> git merge --squash ${PR-Branch}\n> git commit -am\"comment\"\n> git push origin HEAD:${m_mainBranch}\n> git push origin --delete ${m_prBranch}\n\nSo here you _do_ make an actual commit. But that commit doesn't look\nlike a merge to the receiver; it just looks like a single commit that\nhas all the changes there were on PR-Branch.\n\nThe tree of that commit should be the same tree that would result from a\nreal merge. So in theory things like protected-branch status checks\ncould handle that, but I suspect they use the actual commit id (the tree\nid is fine if you're just doing CI, but if you wanted to have a status\ncheck for commit messages, say, you'd obviously want that to be tied to\nthe actual commit object).\n\nI don't offhand recall how that is implemented (and you could also be\nfalling afoul of other checks, like required reviews). But this is a\nGitHub-specific question, and you should probably ask GitHub support to\ngo further.\n\n-Peff\n"},{"id":"354412","messageId":"CALr1GiFjqR+dyP6vCah7H3bhurbcwp2zfrxRfBkd1wnkSQDZCQ@mail.gmail.com","threadId":"49016","inReplyTo":"20180803134901.GC28939@sigill.intra.peff.net","subject":"Re: Squash & Merge Implementation","fromName":"Vadim Belov","fromEmail":"vadim.belov@gmail.com","sentAt":"2018-08-03T17:23:13Z","receivedAt":"2018-08-03T17:23:28Z","isPatch":false,"sender":{"key":"vadim.belov@gmail.com","avatar":null},"body":"Thanks, Peff!\n\nI'm just doing the CI and the status check is for testing each commit to\nthe PR-Branch.\nI'll try to get response from github on this as you suggested.\n\nThanks again,\nVadim\n\nOn Fri, Aug 3, 2018 at 4:49 PM Jeff King <peff@peff.net> wrote:\n\n> On Fri, Aug 03, 2018 at 03:01:15PM +0300, Vadim Belov wrote:\n>\n> > 1. This merges successfully without squash:\n> > git checkout origin/master\n> > git merge ${PR-Branch}\n> > git push origin HEAD:master\n> > git push origin --delete ${PR-Branch}\n>\n> Right, this is a normal merge.\n>\n> > 2. This closes the PR, but there is no update seen on master:\n> > git checkout origin/master\n> > git merge --squash --commit ${PR-Branch}\n> > git push origin HEAD:master\n> > git push origin --delete ${PR-Branch}\n>\n> Doing \"merge --squash --commit\" doesn't do what you expect; namely\n> \"--commit\" does not override the non-committing nature of \"--squash\". It\n> only override a \"--no-commit\" found elsewhere.\n>\n> IMHO this is something that could be improved in Git (i.e., telling the\n> difference between \"the user did not say --no-commit\" and \"the user said\n> --commit\" and respecting it for --squash).\n>\n> But that explains what you see. The push to master is a noop, since you\n> didn't make a new commit. And then deleting the PR branch on GitHub\n> auto-closes the PR.\n>\n> > 3. This fails to push to master with the error \"GH006: Protected branch\n> > update failed\"  (despite that the PR is set to SUCCESS):\n> > git checkout origin/master\n> > git merge --squash ${PR-Branch}\n> > git commit -am\"comment\"\n> > git push origin HEAD:${m_mainBranch}\n> > git push origin --delete ${m_prBranch}\n>\n> So here you _do_ make an actual commit. But that commit doesn't look\n> like a merge to the receiver; it just looks like a single commit that\n> has all the changes there were on PR-Branch.\n>\n> The tree of that commit should be the same tree that would result from a\n> real merge. So in theory things like protected-branch status checks\n> could handle that, but I suspect they use the actual commit id (the tree\n> id is fine if you're just doing CI, but if you wanted to have a status\n> check for commit messages, say, you'd obviously want that to be tied to\n> the actual commit object).\n>\n> I don't offhand recall how that is implemented (and you could also be\n> falling afoul of other checks, like required reviews). But this is a\n> GitHub-specific question, and you should probably ask GitHub support to\n> go further.\n>\n> -Peff\n>\n"}]}