bitjson/typescript-starter

Please remove 'git reset --hard' from the scripts, it's TOO DANGEROUS

bingtimren opened this issue · 2 comments

  • I'm submitting a ...
    [ ] bug report
    [*] feature request
    [ ] question about the decisions made in the repository
    [ ] question about how to use this project

  • Summary

Please remove 'git reset --hard' from the scripts in package.json, it's TOO DANGEROUS. People may expect npm run scripts never do anything other than building, testing, at least never anything as dangerous as git reset --hard without warning.

If the task requires a clean work directory, check it instead of doing 'git reset --hard'. Let's just say I learnt this in an expensive way. Please remove it, or at least prompt user (to type something long, like what you need to do when you delete a git repository).

@bingtimren thank you very much for opening this issue, and very sorry you lost work. I fixed this in v2.4.5 – I think the root issue was the misleadingly-named all task, which wasn't clearly used for clean-releases. I removed that task, so only the actual npm run reset (and larger npm run prepare-release) task is potentially destructive.

I think that should avoid most accidents, but it would be nice if perhaps the npm run prepare-release task had a "Press enter to reset the project and begin a release..." prompt. Unfortunately, I don't know how to do that in an adequately-cross-platform way without adding another dependency (which I don't think is worth it for this single case).

If anyone has any ideas about how this can be improved, I'd love to hear them (and/or take a PR).

tvkit commented

@bitjson I've been bitten by this too many times. Here's a suggestion that works under git bash for Windows. It was necessary to run the porcelain test via sh. For some reason, calling test from within the script always induced an error.

"porcelain": "sh -c '[[ -z \"$(git status --porcelain)\" ]]' || (echo Warning - pending changes && exit 1)",
"status": "npm run porcelain && echo Ready for release",
"reset": "npm run porcelain && npm run reset-hard",
"reset-hard": "git clean -dfx && git reset --hard && sleep 2 && npm run setup",