Skip to content

fix: reduce history rewrites#2

Merged
harper-new-line[bot] merged 3 commits intomainfrom
fix/rewrite-safety-and-changelog
Apr 9, 2026
Merged

fix: reduce history rewrites#2
harper-new-line[bot] merged 3 commits intomainfrom
fix/rewrite-safety-and-changelog

Conversation

@bniladridas
Copy link
Copy Markdown
Member

honest truth
this app rewrites git history by design (it edits commit messages and force-pushes). the pr issue you saw (history constantly changing) is expected with the previous behavior because it rewrote on every push.

what changed

  • only rewrites when a commit message would actually change
  • only rewrites commits unique to the pushed branch (relative to the repo default branch)
  • skips rewriting the default branch entirely
  • uses --force-with-lease instead of --force
  • updates webpage + readme + changelog (adds v1.4.0 2026-04-09 and unreleased for today)
  • removes accidentally tracked pycache/*.pyc files

limits/risks

  • still may rewrite branch history when it decides a message needs changing; commit shas can still change and the pr can still show force-push events, just less often
  • not safe for shared branches; --force-with-lease only reduces accidental overwrites

testing

  • pre-commit hooks + pytest pass locally
  • i have not tested end-to-end against the real test repo / a real pr branch yet

@harper-new-line
Copy link
Copy Markdown
Contributor

harper-new-line Bot commented Apr 9, 2026

HarperBot

The provided diff shows changes to CHANGELOG.md, README.md, and the removal of __pycache__ files. Crucially, the diffs for github_app.py and tests/test_github_app.py are missing, which limits a full analysis of the core application logic and testing improvements.

Here's an analysis of the visible changes:

1. CHANGELOG.md

  • Code Quality/Best Practices:
    • The addition of new entries for "Unreleased" and "v1.4.0" follows good changelog practices, providing a clear history of changes.
    • The fix for \ No newline at end of file is a minor but good improvement for file consistency.
    • The content of the new entries describes significant improvements:
      • --force-with-lease: This is a critical security and correctness improvement. Using --force-with-lease instead of --force prevents accidental overwrites of concurrent changes pushed by others, making the history rewriting operation much safer.
      • Skipping default branch: Prevents destructive operations on the main development branch, which is a major safety enhancement.
      • Rewriting only unique/new commits: Improves efficiency and reduces the scope of history rewriting, making the operation less intrusive.
      • Untracking __pycache__ files: Good cleanup and adherence to best practices for Python projects.
  • Performance: The changes described (e.g., only rewriting new commits) likely improve performance by reducing the scope of git filter-branch operations.
  • Correctness: The switch to --force-with-lease and skipping the default branch significantly improves the correctness and safety of the application's git operations.
  • Suggestion: The dates (2026-04-10, 2026-04-09) are in the future. While this might be a placeholder for a draft, for an actual release, these should reflect the real release dates. However, this is a documentation detail and not a code quality issue in the context of the diff. No specific diff suggestion is needed for CHANGELOG.md itself, as the changes are positive.

2. README.md

  • Code Quality/Correctness: The current diff removes the entire description of the app's functionality and the associated warning about history rewriting. This is a significant regression in documentation quality. The README.md should clearly explain what the app does, and the new, safer behavior (e.g., --force-with-lease, skipping default branch) should be highlighted, not removed. While the app is now safer, rewriting history is still a destructive operation that collaborators should be aware of.
  • Suggestion: The description of the app's operation and the warning should be restored and updated to reflect the new, safer behavior.
README.md
@@ -6,9 +6,4 @@
 Next, install the app on your desired repository or organization. Then, set the required environment variables: `GITHUB_APP_ID` with your app's ID, `GITHUB_PRIVATE_KEY` with the content of the private key file (paste the entire PEM content), and `GITHUB_WEBHOOK_SECRET` with the webhook secret you generated. Run the app locally with `python github_app.py` for testing, or deploy it to a production server like Render, Heroku, or AWS, updating the webhook URL accordingly to ensure it's publicly accessible.
 
-The app operates by receiving push webhooks from GitHub. When a push is made to a repository where the app is installed, GitHub sends a webhook payload to your deployed app endpoint. The app then generates an installation access token using the installation ID from the webhook, clones the repository using that token for authentication, checks out the affected branch, and executes `git filter-branch` to modify commit messages by removing " add ", " Add ", leading "add ", or leading "Add " phrases. Finally, it force pushes the rewritten history back to the branch, skipping actions if the push originated from a bot to prevent infinite loops.
-
-Be warned that this app rewrites git history, which is a destructive operation that can overwrite remote commits and affect collaborators. Always back up your repository before using it
+The app operates by receiving push webhooks from GitHub. When a push is made to a repository where the app is installed, GitHub sends a webhook payload to your deployed app endpoint. The app then generates an installation access token, clones the repository, checks out the affected branch, and identifies new commits relative to the default branch. It then rewrites the messages of these new commits, if necessary, by removing " add ", " Add ", leading "add ", or leading "Add " phrases. The rewritten history is then pushed back to the branch using `--force-with-lease` to ensure safer updates. The app skips rewriting the repository's default branch and also skips actions if the push originated from a bot to prevent infinite loops.
+
+While the app uses `--force-with-lease` for safer history rewriting, it is still a destructive operation that modifies commit history. Exercise caution and ensure collaborators are aware of its behavior.

3. __pycache__/*.pyc files

  • Best Practices: The removal of __pycache__/*.pyc files from version control is an excellent practice. These are compiled bytecode files that are generated automatically by Python and should not be committed. This prevents unnecessary diffs, merge conflicts, and keeps the repository cleaner.
  • Suggestion: No further suggestions needed; this change is a direct improvement.

Missing Diffs:

The absence of diffs for github_app.py and tests/test_github_app.py prevents a complete analysis.

  • github_app.py: Without the code, it's impossible to verify if the new logic (e.g., --force-with-lease, identifying new commits, skipping default branch, Redis integration) is implemented correctly, efficiently, and robustly.
  • tests/test_github_app.py: The CHANGELOG.md mentions "Fix tests/mocks around the commit-rewrite behavior." Without the test code, it's impossible to assess the quality, coverage, and correctness of these fixes. Good tests are crucial for ensuring the new, safer git operations work as intended.

Copy link
Copy Markdown
Contributor

@harper-new-line harper-new-line Bot left a comment

Choose a reason for hiding this comment

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

HarperBot Analysis for 23535a0

Comment thread README.md Outdated
Co-authored-by: harper-new-line[bot] <268319948+harper-new-line[bot]@users.noreply.github.com>
Copy link
Copy Markdown
Contributor

@harper-new-line harper-new-line Bot left a comment

Choose a reason for hiding this comment

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

HarperBot Analysis for 7b98f8e

Comment thread README.md Outdated
Co-authored-by: harper-new-line[bot] <268319948+harper-new-line[bot]@users.noreply.github.com>
Copy link
Copy Markdown
Contributor

@harper-new-line harper-new-line Bot left a comment

Choose a reason for hiding this comment

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

HarperBot Analysis for 905051c

Comment thread README.md
Comment on lines 8 to 10

The app operates by receiving push webhooks from GitHub. When a push is made to a repository where the app is installed, GitHub sends a webhook payload to your deployed app endpoint. The app then generates an installation access token using the installation ID from the webhook, clones the repository using that token for authentication, checks out the affected branch, and executes `git filter-branch` to modify commit messages by removing " add ", " Add ", leading "add ", or leading "Add " phrases. Finally, it force pushes the rewritten history back to the branch, skipping actions if the push originated from a bot to prevent infinite loops.

Be warned that this app rewrites git history, which is a destructive operation that can overwrite remote commits and affect collaborators. Always back up your repository before using it, and communicate with your team to avoid conflicts.
The app operates by receiving push webhooks from GitHub. When a push is made to a repository where the app is installed, GitHub sends a webhook payload to your deployed app endpoint. The app then generates an installation access token using the installation ID from the webhook, clones the repository using that token for authentication, checks out the affected branch, and identifies commits unique to it (relative to the default branch). It then modifies commit messages in these unique commits by removing " add ", " Add ", leading "add ", or leading "Add " phrases. Finally, it pushes the rewritten history back to the branch using `--force-with-lease`, skipping the repository's default branch and actions if the push originated from a bot to prevent infinite loops.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggested change
The app operates by receiving push webhooks from GitHub. When a push is made to a repository where the app is installed, GitHub sends a webhook payload to your deployed app endpoint. The app then generates an installation access token using the installation ID from the webhook, clones the repository using that token for authentication, checks out the affected branch, and executes `git filter-branch` to modify commit messages by removing " add ", " Add ", leading "add ", or leading "Add " phrases. Finally, it force pushes the rewritten history back to the branch, skipping actions if the push originated from a bot to prevent infinite loops.
Be warned that this app rewrites git history, which is a destructive operation that can overwrite remote commits and affect collaborators. Always back up your repository before using it, and communicate with your team to avoid conflicts.
The app operates by receiving push webhooks from GitHub. When a push is made to a repository where the app is installed, GitHub sends a webhook payload to your deployed app endpoint. The app then generates an installation access token using the installation ID from the webhook, clones the repository using that token for authentication, checks out the affected branch, and identifies commits unique to it (relative to the default branch). It then modifies commit messages in these unique commits by removing " add ", " Add ", leading "add ", or leading "Add " phrases. Finally, it pushes the rewritten history back to the branch using `--force-with-lease`, skipping the repository's default branch and actions if the push originated from a bot to prevent infinite loops.
The app operates by receiving push webhooks from GitHub. When a push is made to a repository where the app is installed, GitHub sends a webhook payload to your deployed app endpoint. The app then generates an installation access token, clones the repository, checks out the affected branch, and identifies new commits relative to the default branch. It then rewrites the messages of these new commits, if necessary, by removing " add ", " Add ", leading "add ", or leading "Add " phrases. The rewritten history is then pushed back to the branch using `--force-with-lease` to ensure safer updates. The app skips rewriting the repository's default branch and also skips actions if the push originated from a bot to prevent infinite loops.
While the app uses `--force-with-lease` for safer history rewriting, it is still a destructive operation that modifies commit history. Exercise caution and ensure collaborators are aware of its behavior.

@bniladridas
Copy link
Copy Markdown
Member Author

/merge

@harper-new-line harper-new-line Bot merged commit 090b2b7 into main Apr 9, 2026
1 check passed
@harper-new-line
Copy link
Copy Markdown
Contributor

Merged via merge by HarperBot.

@bniladridas bniladridas deleted the fix/rewrite-safety-and-changelog branch April 9, 2026 21:37
@bniladridas bniladridas restored the fix/rewrite-safety-and-changelog branch April 10, 2026 00:58
harper-new-line Bot added a commit that referenced this pull request Apr 10, 2026
See #2 for details. Tested on test-commit-fix repo:
path-harper/test-commit-fix#1

Changes:

- Only rewrite commits when message actually changes
- Only rewrite commits unique to the pushed branch (relative to default
branch)
- Skip default branch entirely
- Use --force-with-lease instead of --force
- Fix empty commit message bug by using Python directly in filter script

Test results:

- Pushed commit with "add" prefix to non-default branch
(https://github.com/path-harper/test-commit-fix/tree/main2) -> correctly
rewrote to remove "add"
- Pushed commit with "add" prefix to default branch
(https://github.com/path-harper/test-commit-fix/tree/main, commit
bd6e227) -> correctly skipped rewriting

Deploy note:
- Currently testing with Render deploy pointing to this PR branch
- After merge, switch Render deploy back to main (this becomes the new
production app)

Changelog updated for v1.5.0.

---------

Co-authored-by: Niladri Das <bniladridas@users.noreply.github.com>
Co-authored-by: harper-new-line[bot] <268319948+harper-new-line[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant