Thunderbird/Rebasing Patches and Prettier Formatting

From MozillaWiki
Jump to: navigation, search

How to rebase patches from before the Prettier auto-formatting to after it

This is for the Mercurial "bookmarks" workflow. Something similar should work for Mercurial Queues.

The idea is to run prettier to apply its formatting to your changeset before rebasing it on tip. Then the formatting in your changeset will match that on tip, and then your rebased patch will only contain your actual changes, not any of the prettier formatting changes, and will apply cleanly.

Here is a patch that will help. Intended use is below. https://bug1572047.bmoattachments.org/attachment.cgi?id=9090066

First export patches for each of your changesets so you have a backup to fall back on.

A. Simplest case: one patch/changeset to rebase:

- Check out the changeset just before the changeset that you want to rebase

 hg up 12312

- Apply this patch that sets up the eslint and prettier config files for running prettier:

 hg import https://bug1572047.bmoattachments.org/attachment.cgi?id=9090066

- Find the changeset you want to rebase, and first rebase it onto the changeset you just created whey you applyied that patch. The changeset will be called: "Update eslint and prettier config for rebasing patches".

 hg rebase -s xxx -d xxx

- Check out the changeset you want to rebase.

 hg up 123123

- For each file that's changed in your patch, run prettier. In the comm/ directory:

 ../mach eslint path/to/the/file.js --fix

- Do an amend to add the prettier reformatting to your changeset.

 hg commit --amend

- Now you are ready to rebase your changeset on tip,

 hg rebase -s 1234 -d tip

- Finally, create a new patch from your changeset.

- You can now delete the "Update eslint and prettier config for rebasing patches" changeset since its work is done.

B. More than one patch/changeset to rebase:

Same procedure as above, but when running prettier on the files in each of your changesets, do the changesets in reverse order.

So if I'm here with my changesets A, B, and C that I've just rebased on the "update-prettier-config" changeset:

 update-prettier-config -> A -> B -> C

Then I would do this:

- checkout C

- run prettier to reformat the files in C

- |hg commit --amend| to update C with the prettier formatting

- checkout B

- run prettier to reformat the files in B

- |hg commit --amend| to update B with the prettier formatting

- |hg evolve -a| so that C is rebased on B (address any merge conflicts that occur)

- checkout A

- run prettier to reformat the files in A

- |hg commit --amend| to update A with the prettier formatting

- |hg evolve -a| so that B and C are rebased on A (address any merge conflicts that occur)

Now you're ready to rebase your changesets on tip.

Note: it's a good idea to run |mach eslint path/to/file.js| as you go to make sure the file is formatted. Especially if you have any merge conflicts. (After fixing some merge conflicts I had to do that.)