Skip to content

Move prepush scripts to precommit #3026

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

Merged
merged 3 commits into from
May 7, 2020
Merged

Move prepush scripts to precommit #3026

merged 3 commits into from
May 7, 2020

Conversation

hsubox76
Copy link
Contributor

@hsubox76 hsubox76 commented May 6, 2020

Moved prepush scripts (prettier, license, api-report) to run on precommit. Since they now run on staged and not committed files, they only git add and do not create commits. Some changes have been made to properly diff staged files against master, or staged files against unstaged files, as appropriate.

Also attempts to fetch origin/master before diffing to reduce anomalies caused by stale clones.

@google-oss-bot
Copy link
Contributor

google-oss-bot commented May 6, 2020

Binary Size Report

Affected SDKs

No changes between base commit (8143c83) and head commit (bc37e82).

Test Logs

@@ -115,26 +115,24 @@ async function doLicenseCommit(changedFiles) {
symbol: '✅'
});

const hasDiff = await git.diff();
// Diff unstaged (prettier writes) against staged.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

license writes?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.

@@ -59,7 +82,18 @@ $ git stash pop
await doLicenseCommit(changedFiles);

// Generate API reports
await doApiReportsCommit();
await doApiReportsCommit(changedFiles);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove Commit from the function names?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.


// Diff staged changes against last commit. Don't do an empty commit.
const postDiff = await git.diff(['--cached']);
if (!postDiff) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems this condition will never be true since we are committing something from the staging area to begin with.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is a case I ran into while testing where if you only make formatting changes, and they are wrong, and Prettier reformats them back the way they were, there is no longer a diff between your changes and the last commit. I don't think this would ever happen on push but it could happen on a small commit if you did a lot of undos and don't realize the only remaining changes are formatting.

@hsubox76
Copy link
Contributor Author

hsubox76 commented May 6, 2020

Removed API report step because it has been removed in #3030

hsubox76 added 3 commits May 7, 2020 10:34
Fetch master branch before diffing

Each process diff unstaged against staged

Make sure API report uses same diff

Revert firestore file

Restore merge-base behavior

Clearer comment
@hsubox76 hsubox76 merged commit 1753148 into master May 7, 2020
@firebase firebase locked and limited conversation to collaborators Jun 7, 2020
@hsubox76 hsubox76 deleted the ch-precommit branch June 18, 2020 21:09
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants