Skip to content
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

replace-fork should not clear uncommitted changes #22348

Merged
merged 1 commit into from
Sep 20, 2021

Conversation

acdlite
Copy link
Collaborator

@acdlite acdlite commented Sep 17, 2021

The replace-fork script depends on ESLint to fix the reconciler imports — .old -> .new or vice versa. If ESLint crashes, it can leave the imports in an incorrect state.

As a convenience, @bvaughn updated the script to automatically run git checkout -- . if the ESLint command fails. An unintended consequence of the strategy is that if the working directory is not clean, then any uncommitted changes will be lost.

We need a better strategy for this that prevents the accidental loss of work. One option is to exit early if the working directory is not clean before you run the script, though that affects the usability of the script.

An ideal solution would reset the working directory back to whatever state it was in before the script ran, perhaps by stashing all the changes and restoring them if the script aborts.

Until we think of something better, I've commented out the branch.

The replace-fork script depends on ESLint to fix the reconciler imports
— `.old` -> `.new` or vice versa. If ESLint crashes, it can leave the
imports in an incorrect state.

As a convenience, @bvaughn updated the script to automatically run
`git checkout -- .` if the ESLint command fails. An unintended
consequence of the strategy is that if the working directory is not
clean, then any uncommitted changes will be lost.

We need a better strategy for this that prevents the accidental loss of
work. One option is to exit early if the working directory is not clean
before you run the script, though that affects the usability of
the script.

An ideal solution would reset the working directory back to whatever
state it was in before the script ran, perhaps by stashing all the
changes and restoring them if the script aborts.

Until we think of something better, I've commmented out the branch.
@facebook-github-bot facebook-github-bot added CLA Signed React Core Team Opened by a member of the React Core Team labels Sep 17, 2021
@sizebot
Copy link

sizebot commented Sep 17, 2021

Comparing: f50ff35...854881d

Critical size changes

Includes critical production bundles, as well as any change greater than 2%:

Name +/- Base Current +/- gzip Base gzip Current gzip
oss-stable/react-dom/cjs/react-dom.production.min.js = 129.49 kB 129.49 kB = 41.26 kB 41.26 kB
oss-experimental/react-dom/cjs/react-dom.production.min.js = 132.31 kB 132.31 kB = 42.21 kB 42.21 kB
facebook-www/ReactDOM-prod.classic.js = 410.86 kB 410.86 kB = 76.01 kB 76.01 kB
facebook-www/ReactDOM-prod.modern.js = 399.43 kB 399.43 kB = 74.29 kB 74.29 kB
facebook-www/ReactDOMForked-prod.classic.js = 410.86 kB 410.86 kB = 76.01 kB 76.01 kB

Significant size changes

Includes any change greater than 0.2%:

(No significant changes)

Generated by 🚫 dangerJS against 854881d

@salazarm
Copy link
Contributor

yesssssss.

@bvaughn
Copy link
Contributor

bvaughn commented Sep 20, 2021

Why not just have the script git add . prior to syncing, and then checkout all unstaged files if ESLint crashes?

@acdlite
Copy link
Collaborator Author

acdlite commented Sep 20, 2021

But then it messes with my git index :( which is part of my workflow

@acdlite
Copy link
Collaborator Author

acdlite commented Sep 20, 2021

If it restores the index back to what it was that would be nice, though

@bvaughn
Copy link
Contributor

bvaughn commented Sep 20, 2021

Well, it could also do the following:

  1. git commit anything staged
  2. git add to stage anything unstaged
  3. Run the copy and lint steps
  4. Cleanup on success by git reset --soft HEAD~1 before commiting
  5. Cleanup on failure by git checkout . && git reset . && git reset --soft HEAD~1 to restore to previous state

@acdlite
Copy link
Collaborator Author

acdlite commented Sep 20, 2021

Do you mind if we leave that for a separate improvement and merge this in the meantime, though? I keep almost losing my work because of the existing behavior.

@bvaughn
Copy link
Contributor

bvaughn commented Sep 20, 2021

Sure

@bvaughn bvaughn merged commit 293059e into facebook:main Sep 20, 2021
@acdlite
Copy link
Collaborator Author

acdlite commented Sep 20, 2021

I think personally the behavior I would like best is if it only ever touched reconciler files (the ones ending in .new or .old, in both the index and the working directory). I use the git index a lot while I'm working on big changes so any solution that relies on staging everything (i.e. git add) is going to negatively affect my workflow.

@bvaughn
Copy link
Contributor

bvaughn commented Sep 20, 2021

So long as it restored the repo to its pre-existing state after a failure, would you have any complaints?

@acdlite
Copy link
Collaborator Author

acdlite commented Sep 20, 2021

If it doesn't stage everything then no :D

Another solution could be to add another command yarn reset-fork <GIT_REV> that resets the target reconciler forks (but nothing else) back to a particular revision, defaulting to HEAD. Then yarn replace-fork can run that one automatically if something fails.

@bvaughn
Copy link
Contributor

bvaughn commented Sep 20, 2021

TBH, I think running replace-fork with unstaged changes is probably always a bad idea and maybe something the script should warn about.

@acdlite
Copy link
Collaborator Author

acdlite commented Sep 20, 2021

Yeah that would also work for me, as long as I can override it somehow 😈

@acdlite
Copy link
Collaborator Author

acdlite commented Sep 20, 2021

This might seem like a weird workflow but it's fairly common for me: I'll have just completed a large change and I want to break it into steps, so I stage the first part, run replace-fork, commit with a message, then repeat.

@acdlite
Copy link
Collaborator Author

acdlite commented Sep 20, 2021

And ESLint crashes (as opposed to errors) aren't that common so I usually don't mind if the old reconciler files are left in a broken state because all I have to do is fix the crash then run the command again

@bvaughn
Copy link
Contributor

bvaughn commented Sep 20, 2021

Yeah, it's not common, but it has caused contributor confusion before. (That's how I became aware of it and made the previous change.) I've posted a follow up #22364 that I think addresses both of our concerns.

zhengjitf pushed a commit to zhengjitf/react that referenced this pull request Apr 15, 2022
The replace-fork script depends on ESLint to fix the reconciler imports
— `.old` -> `.new` or vice versa. If ESLint crashes, it can leave the
imports in an incorrect state.

As a convenience, @bvaughn updated the script to automatically run
`git checkout -- .` if the ESLint command fails. An unintended
consequence of the strategy is that if the working directory is not
clean, then any uncommitted changes will be lost.

We need a better strategy for this that prevents the accidental loss of
work. One option is to exit early if the working directory is not clean
before you run the script, though that affects the usability of
the script.

An ideal solution would reset the working directory back to whatever
state it was in before the script ran, perhaps by stashing all the
changes and restoring them if the script aborts.

Until we think of something better, I've commmented out the branch.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLA Signed React Core Team Opened by a member of the React Core Team
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants