- Notifications
You must be signed in to change notification settings - Fork 121
feat: implement autorebase for PRs with multiple commits#473
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Uh oh!
There was an error while loading. Please reload this page.
Conversation
codecovbot commented Aug 14, 2020 • edited
Loading Uh oh!
There was an error while loading. Please reload this page.
edited
Uh oh!
There was an error while loading. Please reload this page.
Codecov Report
@@ Coverage Diff @@## master #473 +/- ## ======================================= Coverage 82.59% 82.59% ======================================= Files 34 34 Lines 1660 1660 ======================================= Hits 1371 1371 Misses 289 289 Continue to review full report at Codecov.
|
600ab8f to 458935aCompare
mmarchini left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lgtm with comments addressed (especially removing the check, the others are just nit)
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
458935a to 7bba412Comparemmarchini commented Aug 15, 2020 • edited
Loading Uh oh!
There was an error while loading. Please reload this page.
edited
Uh oh!
There was an error while loading. Please reload this page.
Humm, just tried to use this and it ended up rather confusing... $ git node land --autorebase 34671✔ Done loading data for nodejs/node/pull/34671----------------------------------- PR info ------------------------------------Title errors: improve ERR_INVALID_OPT_VALUE message (#34671) ⚠ Could not retrieve the email or name of the PR author's from user's GitHub profile!Branch lundibundi:improve-errors-opt-value -> nodejs:masterLabels author ready, child_process, errors, netCommits 2 - errors: improve ERR_INVALID_OPT_VALUE error - fixup! errors: improve ERR_INVALID_OPT_VALUE errorCommitters 1 - Denys Otrishko <[email protected]>------------------------------ Generated metadata ------------------------------PR-URL: https://github.com/nodejs/node/pull/34671Reviewed-By: James M Snell <[email protected]>Reviewed-By: Rich Trott <[email protected]>Reviewed-By: Mary Marchini <[email protected]>-------------------------------------------------------------------------------- ℹ Last Full PR CI on 2020-08-14T11:29:16Z: https://ci.nodejs.org/job/node-test-pull-request/32788/✔ Build data downloaded ℹ This PR was created on Fri, 07 Aug 2020 19:50:06 GMT ✔ Approvals: 3 ✔ - James M Snell (@jasnell) (TSC): https://github.com/nodejs/node/pull/34671#pullrequestreview-463577321 ✔ - Rich Trott (@Trott) (TSC): https://github.com/nodejs/node/pull/34671#pullrequestreview-463906392 ✔ - Mary Marchini (@mmarchini) (TSC): https://github.com/nodejs/node/pull/34671#pullrequestreview-467939143--------------------------------------------------------------------------------? This PR should be ready to land, do you want to continue? Yes ✔ No git am in progress ✔ No git rebase in progress--------------------------------------------------------------------------------? Do you want to try reset the local master branch to upstream/master? Yes⠴ Bringing upstream/master up to date...From github.com:nodejs/node * branch master -> FETCH_HEAD✔ upstream/master is now up-to-date✔ Downloaded patch to /home/mmarchini/workspace/nodejs/node-master/.ncu/34671/patch--------------------------------------------------------------------------------Applying: errors: improve ERR_INVALID_OPT_VALUE errorerror: patch failed: lib/internal/errors.js:1114error: lib/internal/errors.js: patch does not applyPatch failed at 0001 errors: improve ERR_INVALID_OPT_VALUE errorhint: Use 'git am --show-current-patch' to see the failed patchWhen you have resolved this problem, run "git am --continue".If you prefer to skip this patch, run "git am --skip" instead.To restore the original branch and stop patching, run "git am --abort".--------------------------------------------------------------------------------? The normal `git am` failed. Do you want to retry with 3-way merge? YesApplying: errors: improve ERR_INVALID_OPT_VALUE errorUsing index info to reconstruct a base tree...M lib/internal/errors.jsM lib/net.jsFalling back to patching base and 3-way merge...Auto-merging lib/net.jsAuto-merging lib/internal/errors.jsApplying: fixup! errors: improve ERR_INVALID_OPT_VALUE error ✔ Patches appliedThere are 2 commits in the PR. Attempring autorebase.Executing: git-node land --amend--------------------------------- New Message ----------------------------------errors: improve ERR_INVALID_OPT_VALUE error* use util.inspect for value presentation* allow to optionally specify error reasonPR-URL: https://github.com/nodejs/node/pull/34671Reviewed-By: James M Snell <[email protected]>Reviewed-By: Rich Trott <[email protected]>Reviewed-By: Mary Marchini <[email protected]>--------------------------------------------------------------------------------? Use this message? Yes[detached HEAD d6c25a1a19] errors: improve ERR_INVALID_OPT_VALUE error Author: Denys Otrishko <[email protected]> Date: Fri Aug 7 20:31:20 2020 +0300 9 files changed, 45 insertions(+), 26 deletions(-)Successfully rebased and updated refs/heads/master.After the rebase, it doesn't give any instructions on how to advance ( Also, it doesn't respect |
mmarchini left a comment • edited
Loading Uh oh!
There was an error while loading. Please reload this page.
edited
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
requesting changes explicitly to avoid confusion when using this flag
lib/landing_session.js Outdated
| cli.log(`There are ${subjects.length} commits in the PR. `+ | ||
| 'Attempting autorebase.'); | ||
| const{ upstream, branch }=this; | ||
| constmsgAmend='-x "git-node land --amend"'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This fixes the interaction with --yes:
| constmsgAmend='-x "git-node land --amend"'; | |
| constmsgAmend= | |
| `-x "git-node land --amend ${cli.assumeYes ? '--yes' : ''}"`; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, that's where it was, thanks.
mmarchini commented Aug 15, 2020 • edited
Loading Uh oh!
There was an error while loading. Please reload this page.
edited
Uh oh!
There was an error while loading. Please reload this page.
Ok, this should do it: diff --git a/lib/landing_session.js b/lib/landing_session.js index 0f239cb..ec06e55 100644 --- a/lib/landing_session.js+++ b/lib/landing_session.js@@ -7,7 +7,7 @@ const{} = require('./deprecations'); const{- runAsync, runSync, forceRunAsync+ runAsync, runSync, forceRunAsync, runAsyncBase } = require('./run'); const Session = require('./session'); const{shortSha } = require('./utils'); @@ -167,15 +167,33 @@ class LandingSession extends Session{cli.log(`There are ${subjects.length} commits in the PR. ` + 'Attempring autorebase.'); const{upstream, branch } = this; - const msgAmend = '-x "git-node land --amend"';- await runAsync('git',- ['rebase', `${upstream}/${branch}`, '-i', '--autosquash', msgAmend],-{- spawnArgs:{- shell: true,- env:{...process.env, GIT_SEQUENCE_EDITOR: ':' }- }- });+ const msgAmend =+ `-x "git-node land --amend ${cli.assumeYes ? '--yes' : ''}"`;+ try{+ await runAsyncBase('git',+ ['rebase', `${upstream}/${branch}`, '-i', '--autosquash', msgAmend],+{+ spawnArgs:{+ shell: true,+ env:{...process.env, GIT_SEQUENCE_EDITOR: ':' }+ }+ });+ return this.final();+ } catch{+ await runAsync('git',+ ['rebase', '--abort'],+{+ spawnArgs:{+ shell: true,+ env:{...process.env, GIT_SEQUENCE_EDITOR: ':' }+ }+ });+ const suggestion = this.getRebaseSuggestion(subjects);+ cli.log(`Couldn't rebase ${subjects.length} commits in the PR automatically`);+ cli.log('Please run the following commands to complete landing\n\n' ++ `$ ${suggestion}\n` ++ '$ git-node land --continue');+ } } else{const suggestion = this.getRebaseSuggestion(subjects); cli.log(`There are ${subjects.length} commits in the PR`); diff --git a/lib/run.js b/lib/run.js index 63ae10d..8bebc16 100644 --- a/lib/run.js+++ b/lib/run.js@@ -26,6 +26,8 @@ function runAsyncBase(cmd, args, options ={}){})} +exports.runAsyncBase = runAsyncBase;+ exports.forceRunAsync = function(cmd, args, options){return runAsyncBase(cmd, args, options).catch((error) =>{if (error.message !== IGNORE){It fixes interaction with --yes, calls |
lundibundi commented Aug 15, 2020 • edited
Loading Uh oh!
There was an error while loading. Please reload this page.
edited
Uh oh!
There was an error while loading. Please reload this page.
Didn't get to check the After implementing it this way, I'm thinking whether we should just ask (via cli.prompt) whether to make a rebase instead of making it an option? |
mmarchini commented Aug 15, 2020
You can open test PRs to nodejs/node-auto-test :)
I think for this version we can keep as a flag and in the future when we're more confident it works as expected we can change to a question |
lundibundi commented Aug 15, 2020
On the other hand got to check the |
mmarchini commented Aug 15, 2020
Yes, in the diff I suggested exporting runAsyncBase and using it, but if force works I'm happy with it too.
To run the command it's fine to use |
6705daa to 56a91f6Compare56a91f6 to 38dac57Comparelundibundi commented Aug 18, 2020
Rebased to fix conflicts. This is ready for review. |
mmarchini commented Aug 18, 2020
Code LGTM. Started testing but couldn't find any PR on nodejs/node to test this, and when I tried on nodejs/node-auto-test I hit some issues. Will try again later or tomorrow. |
mmarchini commented Aug 20, 2020
Ok, it's hard to find a PR that passes all checks and has a properly formatted |
richardlau commented Aug 20, 2020
|
mmarchini commented Aug 20, 2020
Landing so I can rebase and land #487 as well to test with nodejs/node#34798. |
mmarchini commented Aug 20, 2020
It works, nice! |
This will allow to land commits with multiple commits and also properly handle proper `fixup` commits. Refs: nodejs/node-core-utils#473 PR-URL: nodejs#34969 Reviewed-By: Mary Marchini <[email protected]> Reviewed-By: Luigi Pinca <[email protected]> Reviewed-By: Shelley Vohr <[email protected]>
This will allow to land commits with multiple commits and also properly handle proper `fixup` commits. Refs: nodejs/node-core-utils#473 PR-URL: #34969 Reviewed-By: Mary Marchini <[email protected]> Reviewed-By: Luigi Pinca <[email protected]> Reviewed-By: Shelley Vohr <[email protected]>
This will allow to land commits with multiple commits and also properly handle proper `fixup` commits. Refs: nodejs/node-core-utils#473 PR-URL: #34969 Reviewed-By: Mary Marchini <[email protected]> Reviewed-By: Luigi Pinca <[email protected]> Reviewed-By: Shelley Vohr <[email protected]>
This will allow to land commits with multiple commits and also properly handle proper `fixup` commits. Refs: nodejs/node-core-utils#473 PR-URL: #34969 Reviewed-By: Mary Marchini <[email protected]> Reviewed-By: Luigi Pinca <[email protected]> Reviewed-By: Shelley Vohr <[email protected]>
This basically adds
--autorebasethat will run interactive rebase with--autosquashoption to handle!fixupcommits (but refuse to landsquash!as those require msg editing) andgit-node land --amendfor each commit.Hopefully this will allow us to land PRs with multiple commits in
commit-queue.Couldn't find a way to write tests for landing, did I miss it somewhere?
Also, anyone knows a better way to run
git-landwithout the need forshell: trueoption?/cc @nodejs/node-core-utils