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

Various fixes for leaving a messy git state #280

Merged
merged 7 commits into from
Oct 10, 2024
Merged

Various fixes for leaving a messy git state #280

merged 7 commits into from
Oct 10, 2024

Conversation

pbrisbin
Copy link
Member

@pbrisbin pbrisbin commented Oct 10, 2024

The CLI was never very hygienic with the git state it leaves after a local run. As we
refactored things such that the common use case is "local" on GitHub Actions, this
became a problem. It resulted in weird PRs being created by create-pull-request
action.

These fixes should address what I've found so far.


Only commit paths we restyled

ed2f4dd

This avoids unintentionally including other files we may have created,
such as downloaded files or backup files produced by a restyler.

Run git-clean at the end, by default

f25f036

This ensures any files created by the restyling process are cleaned up,
which is important to prevent any create-pull-request action running
after us from including them in its own commit.

Behavior can be disabled by NO_CLEAN / --no-clean.

Prevent empty changesets when restylers offset each other

3ff33ab

Sometimes, two restylers can "fight". One changes code one way and then
another puts it exactly back. When this happens, each restyler will
generate their own commit, but the overall changeset will be empty.

If we don't explicitly check for this, using the create-pull-request
action will still produce a PR because there are commits, even if the
overall diff is empty. This empty PR might just be merged out of habit
or process, triggering the process to repeat again.

So we'll explicitly check:

  • If we made changes,
  • If those changes made commits
  • If there's no diff against our first commit's parent ({sha}^)
  • Then we'll do a git reset --hard back to it

Version bump

ba396c0

This avoids unintentionally including other files we may have created,
such as downloaded files or backup files produced by a restyler.
This ensures any files created by the restyling process are cleaned up,
which is important to prevent any create-pull-request action running
after us from including them in its own commit.

Behavior can be disabled by `NO_CLEAN` / `--no-clean`.
Sometimes, two restylers can "fight". One changes code one way and then
another puts it exactly back. When this happens, each restyler will
generate their own commit, but the overall changeset will be empty.

If we don't explicitly check for this, using the create-pull-request
action will still produce a PR because there are commits, even if the
overall diff is empty. This empty PR might just be merged out of habit
or process, triggering the process to repeat again.

So we'll explicitly check:

- If we made changes,
- If those changes made commits
- If there's no diff against our first commit's parent (`{sha}^`)
- Then we'll do a `git reset --hard` back to it
@pbrisbin pbrisbin changed the title pb/fixes Various fixes for leaving a messy git state Oct 10, 2024
@pbrisbin pbrisbin marked this pull request as ready for review October 10, 2024 12:43
@pbrisbin pbrisbin merged commit 0f7ce69 into main Oct 10, 2024
7 checks passed
@pbrisbin pbrisbin deleted the pb/fixes branch October 10, 2024 13:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant