You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Provide guidance on editing PRs prior to merge #129
The GitHub "command line instructions" for PR merging assume you'll be merging and pushing changes from the command line rather than amending the original PR. This means I'm not entirely clear on how to amend the following prior to accepting someone's change:
update ACKs
add a NEWS entry
add a What's New entry
any other tweaks I want to just fix myself rather than pushing back for another round of review
It's an interesting problem that I run into in other projects. I don't want to necessarily block a merge because things like a NEWS file entry are missing, but then I also don't like merging a branch that's missing the things you mention above. I'll usually use the command line to fetch their branch, clean it up, then either push it to master (not an option for CPython repo) or push to a new branch, CI that and land that without squash merging (so the original work is preserved). Not super ideal though.
OK, after trying it, the shallow clone idea is a non-starter, since you'll need the full history if you actually want to rebase the PR branch (which is likely to be essential for the time being, in order to edit and push Misc/NEWS without conflicts).
I'm going to try a different approach making a fresh clone of my local repo (so "origin" is my own main working copy rather than anything on GitHub) and then pulling the PR branch into that by setting up the contributor's fork as a new remote.
(update to your liking the naming scheme) which is useful to at least checkout without having to add the remote. I haven't figured out how to push to a PR without setting a remote, but that helps.
However, I couldn't actually push the resulting rebase back to the original branch.
It does that to me as well, I had to switch git:// to ssh:// (and --force if I rebase).
I would recommend trying hub (and aliasing it to git) that set most of that up automatically.
So given that, you can edit the PR as needed on the contributor's branch, push the updates back to their repo, and then accept the amended PR via squash & merge.
If put in the dev guide, I would suggest --force-with-lease instead of -f, potentially git config --global alias.pushf "push --force-with-lease" once to avoid the long option. It force pushes only if remote have not changed in the meantime.
While I love rebase at my private branch (no one other than me push to it),
I don't like using -f or --force-with-lease on branch shared by more than two people.
It may make trouble, and contributor may not git expert.
So if solving conflict is required, I prefer merge to rebase.
merge commit will be removed when "Squash and merge".
Must admit I don't know how to properly edit other people's code too, and I know I'm not the only one.
Can anyone who has done this successfully, write it up in the devguide? Please? Thanks :)
Ah, you just reminded me I promised @nayafia a write-up of the specifics of the documentation problem here, so I should be able to tackle both of those at the same time.
I think the main requirement before merging that is for someone else (@Mariatta?) to actually try them out and confirm that I didn't miss anything when transcribing the steps I took to edit python/cpython#171
I used merging in master as an example of a change to make, since it came up above, and let me gloss over all the details of making changes, adding them, and committing them with an appropriate message (plus it's important as long as we're still editing Misc/NEWS directly).
@Mariatta suggested attempting to define a git alias for this (akin to the git PR one) in order to avoid having to write out the following 3 commands every time:
I merged the PR with @Mariatta's edits, so closing this - if folks are using this enough to want a git alias, the instructions for creating the pr alias are already there, and adapting them should be relatively straightforward.
Activity
warsaw commentedon Feb 22, 2017
It's an interesting problem that I run into in other projects. I don't want to necessarily block a merge because things like a NEWS file entry are missing, but then I also don't like merging a branch that's missing the things you mention above. I'll usually use the command line to fetch their branch, clean it up, then either push it to master (not an option for CPython repo) or push to a new branch, CI that and land that without squash merging (so the original work is preserved). Not super ideal though.
ncoghlan commentedon Feb 22, 2017
Using python/cpython#171 as my example, it looks like the following command gives me a shallow clone with the PR contents:
(The branch name and repo URL can be accessed by looking at the "command line instructions" on the PR)
Next step will be to actually push the update with the Author overridden to match the original contributor.
ncoghlan commentedon Feb 22, 2017
OK, after trying it, the shallow clone idea is a non-starter, since you'll need the full history if you actually want to rebase the PR branch (which is likely to be essential for the time being, in order to edit and push Misc/NEWS without conflicts).
I'm going to try a different approach making a fresh clone of my local repo (so "origin" is my own main working copy rather than anything on GitHub) and then pulling the PR branch into that by setting up the contributor's fork as a new remote.
ncoghlan commentedon Feb 22, 2017
This worked better for making a local branch that I could rebase:
However, I couldn't actually push the resulting rebase back to the original branch.
Carreau commentedon Feb 22, 2017
you can set the following in your (global)
.gitconfig:That allows you to
(update to your liking the naming scheme) which is useful to at least checkout without having to add the remote. I haven't figured out how to push to a PR without setting a remote, but that helps.
It does that to me as well, I had to switch git:// to ssh:// (and --force if I rebase).
I would recommend trying
hub(and aliasing it to git) that set most of that up automatically.ncoghlan commentedon Feb 22, 2017
I use git hosts other than GitHub, so I have no intention of adopting a GitHub specific client.
Carreau commentedon Feb 22, 2017
hub does work with non-github client, it just add commands that work only with github. But understandable.
ncoghlan commentedon Feb 23, 2017
After comparison with my main CPython checkout, I found the right remote definition to enable updating contributor PRs:
And then a rebase of the PR on master looks like:
So given that, you can edit the PR as needed on the contributor's branch, push the updates back to their repo, and then accept the amended PR via squash & merge.
Carreau commentedon Feb 23, 2017
If put in the dev guide, I would suggest
--force-with-leaseinstead of-f, potentiallygit config --global alias.pushf "push --force-with-lease"once to avoid the long option. It force pushes only if remote have not changed in the meantime.ncoghlan commentedon Feb 23, 2017
Oh, nice, I didn't know about
--force-with-lease. I agree, that would be a much better option when rebasing a shared PR branch.methane commentedon Feb 23, 2017
While I love rebase at my private branch (no one other than me push to it),
I don't like using
-for--force-with-leaseon branch shared by more than two people.It may make trouble, and contributor may not git expert.
So if solving conflict is required, I prefer merge to rebase.
merge commit will be removed when "Squash and merge".
ncoghlan commentedon Feb 23, 2017
That makes sense, and would make that part of the instructions just:
With a note clarifying that the later squash & merge will remove the interim merge commit.
Mariatta commentedon Mar 17, 2017
Must admit I don't know how to properly edit other people's code too, and I know I'm not the only one.
Can anyone who has done this successfully, write it up in the devguide? Please? Thanks :)
ncoghlan commentedon Mar 18, 2017
Ah, you just reminded me I promised @nayafia a write-up of the specifics of the documentation problem here, so I should be able to tackle both of those at the same time.
Issue python#129: Guide to editing PR branches
ncoghlan commentedon Mar 18, 2017
PR submitted here: #150
I think the main requirement before merging that is for someone else (@Mariatta?) to actually try them out and confirm that I didn't miss anything when transcribing the steps I took to edit python/cpython#171
I used merging in master as an example of a change to make, since it came up above, and let me gloss over all the details of making changes, adding them, and committing them with an appropriate message (plus it's important as long as we're still editing
Misc/NEWSdirectly).Mariatta commentedon Mar 18, 2017
Nice! Thanks :)
ncoghlan commentedon Mar 19, 2017
@Mariatta suggested attempting to define a git alias for this (akin to the git PR one) in order to avoid having to write out the following 3 commands every time:
@zware pointed out that given a suitable "push" command, it's possible to re-use the existing
git pralias:If we assume the local branch is named after the PR number, then it would be possible to define a relatively straightforward alias for a push like:
Mariatta commentedon Mar 22, 2017
I was able to edit @ncoghlan PR #150 by following the steps mentioned there 🎉
I updated the instructions to recommend using
git pralias, but did not creategit pr-amendalias.Issue #129: Guide to editing PR branches (#150)
ncoghlan commentedon Mar 22, 2017
I merged the PR with @Mariatta's edits, so closing this - if folks are using this enough to want a git alias, the instructions for creating the
pralias are already there, and adapting them should be relatively straightforward.Issue python#129: Guide to editing PR branches (python#150)