arxanas / git-branchless

High-velocity, monorepo-scale workflow for Git
Apache License 2.0
3.48k stars 89 forks source link

"git reword" should only rewrite modified commits #1385

Open talios opened 3 months ago

talios commented 3 months ago

Description of the bug

When I have say 9 commits in my stack, and I use "git reword" to only update the LAST commit, git-branchless still rewrites all commits.

Ideally, only the changed (and dependent) commits should get rewritten.

Expected behavior

Only the last (modified) commit should have been rewritten.

Actual behavior

All commits in the stack got rewritten.

Version of rustc

No response

Automated bug report

Software version

git-branchless 0.9.0 (8ffbdab)

Operating system

macOS 14.6.1 (Darwin 23.6.0)

Command-line

/Users/amrk/.cargo/bin/git-branchless bug-report 

Environment variables

SHELL=/usr/local/bin/fish
EDITOR=<not set>

Git version

> git version 
git version 2.46.0

Hooks

Hooks directory: /Users/amrk/IdeaProjects/securemx/smx3/com.smxemail.remediation.manager/.git/hooks

Show 7 hooks ##### Hook `post-applypatch` ``` #!/bin/sh ## START BRANCHLESS CONFIG git branchless hook post-applypatch "$@" ## END BRANCHLESS CONFIG ``` ##### Hook `post-checkout` ``` #!/bin/sh ## START BRANCHLESS CONFIG git branchless hook post-checkout "$@" ## END BRANCHLESS CONFIG ``` ##### Hook `post-commit` ``` #!/bin/sh ## START BRANCHLESS CONFIG git branchless hook post-commit "$@" ## END BRANCHLESS CONFIG ``` ##### Hook `post-merge` ``` #!/bin/sh ## START BRANCHLESS CONFIG git branchless hook post-merge "$@" ## END BRANCHLESS CONFIG ``` ##### Hook `post-rewrite` ``` #!/bin/sh ## START BRANCHLESS CONFIG git branchless hook post-rewrite "$@" ## END BRANCHLESS CONFIG ``` ##### Hook `pre-auto-gc` ``` #!/bin/sh ## START BRANCHLESS CONFIG git branchless hook pre-auto-gc "$@" ## END BRANCHLESS CONFIG ``` ##### Hook `reference-transaction` ``` #!/bin/sh ## START BRANCHLESS CONFIG # Avoid canceling the reference transaction in the case that `branchless` fails # for whatever reason. git branchless hook reference-transaction "$@" || ( echo 'branchless: Failed to process reference transaction!' echo 'branchless: Some events (e.g. branch updates) may have been lost.' echo 'branchless: This is a bug. Please report it.' ) ## END BRANCHLESS CONFIG ```

Events

Show 5 events ##### Event ID: 703, transaction ID: 449 (message: reword) 1. `RefUpdateEvent { timestamp: 1723544445.026751, event_tx_id: Id(449), ref_name: ReferenceName("refs/heads/redacted-ref-0"), old_oid: fcedac8eb2362186f5c119f988afd2acbd018abd, new_oid: 15388a95b0c136430ae249f36b9e85e9b7f414f2, message: None }` 1. `RewriteEvent { timestamp: 1723544445.090125, event_tx_id: Id(449), old_commit_oid: 801d2dd151b17eb0e527f0065d2160fcc3ae018f, new_commit_oid: aefa8582e622e4061ff5fa39929e3f2879e526c7 }` 1. `RewriteEvent { timestamp: 1723544445.090125, event_tx_id: Id(449), old_commit_oid: 8bcda4c473ef01359133d18e67af2b35f76a8419, new_commit_oid: 3cedbdbe44b4386509a20156241d1530c8e640b3 }` 1. `RewriteEvent { timestamp: 1723544445.090125, event_tx_id: Id(449), old_commit_oid: 9faa2f17294fa16e652d2efe652b9e996d1f852b, new_commit_oid: 648f7025269fbd88ff5def0fe7cfaf12c2fb80fd }` 1. `RewriteEvent { timestamp: 1723544445.090125, event_tx_id: Id(449), old_commit_oid: 8980886109addde7ff767b45217e1958e5d3fb5b, new_commit_oid: 8971dbe7f027841df6b3dc6be267d8e83beafe7c }` 1. `RewriteEvent { timestamp: 1723544445.090125, event_tx_id: Id(449), old_commit_oid: fcedac8eb2362186f5c119f988afd2acbd018abd, new_commit_oid: 15388a95b0c136430ae249f36b9e85e9b7f414f2 }` 1. `RewriteEvent { timestamp: 1723544445.090125, event_tx_id: Id(449), old_commit_oid: a621b53ce7a32a19738353e5addff6eb6fd56793, new_commit_oid: c8e03f62ea09c6f9d23f248ddd572706ae6e02b2 }` 1. `RewriteEvent { timestamp: 1723544445.090125, event_tx_id: Id(449), old_commit_oid: eb7ffe8c220a6cc290755cb0ee481d02844b69a2, new_commit_oid: 90bd9cc9dbc512783e889e3f6cf5a43495dfd30d }` 1. `RewriteEvent { timestamp: 1723544445.090125, event_tx_id: Id(449), old_commit_oid: 9eb78551cb689c88016cddfacf607a8ee717347d, new_commit_oid: 49ebb160c44f6d71f6cbe03f49a3ceaa33c75eb8 }` 1. `RewriteEvent { timestamp: 1723544445.090125, event_tx_id: Id(449), old_commit_oid: 8d05f590f037992126569361bcfe406cf7abd93b, new_commit_oid: 65e1c345ef110e017b4f70e258ece548d53a3a72 }` 1. `WorkingCopySnapshot { timestamp: 1723544445.138011, event_tx_id: Id(449), head_oid: fcedac8eb2362186f5c119f988afd2acbd018abd, commit_oid: NonZeroOid(d67225d18ff2a0d8dcca3b826aa5738ea13a8381), ref_name: None }` 1. `RefUpdateEvent { timestamp: 1723544445.25557, event_tx_id: Id(449), ref_name: ReferenceName("HEAD"), old_oid: 0000000000000000000000000000000000000000, new_oid: 15388a95b0c136430ae249f36b9e85e9b7f414f2, message: None }` 1. `RefUpdateEvent { timestamp: 1723544445.534112, event_tx_id: Id(449), ref_name: ReferenceName("HEAD"), old_oid: fcedac8eb2362186f5c119f988afd2acbd018abd, new_oid: 15388a95b0c136430ae249f36b9e85e9b7f414f2, message: None }` ``` O 6737fb1 22d (develop, redacted-ref-1) xxxxxxx xxxxxx | o 49ebb16 4m xxxx xxxxxx xxxxxxx xxxxx | o aefa858 4m xxxx xxx xxxxxx xxxxxxx xxxxxxxxxxxxx xxx xxxx | o 90bd9cc 4m xxxx xxxxxxx xxxxxxxxxxx xxxxx xxx | o 3cedbdb 4m xxxx xxx xxxx xxxxx xxxxxxx xx xxxxxxxxxx | o 648f702 4m xxxx xxx xxxxxxx xxxx xxxxxxxxxxx xxxxxxx | o 8971dbe 4m xxxxxxxxxxxx xxxxxxx xxxxxxxx xxxxx | o c8e03f6 4m xxxxx xxx xxx xxxxxxxxxx xxxxxxx | o 65e1c34 4m xxxxx xxxxxxxx xxxx xxxxxxxxxx xx xxxxxxx | @ 15388a9 4m (redacted-ref-0) xxxx xxx xxxxxxx xxx xxxxxxxxxxx xxx xxxxxxxxxxxxxxxxxx ``` ##### Event ID: 697, transaction ID: 445 (message: amend) 1. `WorkingCopySnapshot { timestamp: 1723537126.932345, event_tx_id: Id(445), head_oid: 2975945e7bbebc40831e1b6ac922fb6cf80ced53, commit_oid: NonZeroOid(44a637cea71164fba4d105bbab88ea08f688271e), ref_name: Some(ReferenceName("refs/heads/redacted-ref-0")) }` 1. `RewriteEvent { timestamp: 1723537126.932345, event_tx_id: Id(445), old_commit_oid: 2975945e7bbebc40831e1b6ac922fb6cf80ced53, new_commit_oid: fcedac8eb2362186f5c119f988afd2acbd018abd }` 1. `RefUpdateEvent { timestamp: 1723537127.07347, event_tx_id: Id(445), ref_name: ReferenceName("refs/heads/redacted-ref-0"), old_oid: 2975945e7bbebc40831e1b6ac922fb6cf80ced53, new_oid: fcedac8eb2362186f5c119f988afd2acbd018abd, message: None }` 1. `WorkingCopySnapshot { timestamp: 1723537127.101924, event_tx_id: Id(445), head_oid: fcedac8eb2362186f5c119f988afd2acbd018abd, commit_oid: NonZeroOid(b380dac42c8be3f10638a4442f35cd8bfd947fda), ref_name: Some(ReferenceName("refs/heads/redacted-ref-0")) }` 1. `RefUpdateEvent { timestamp: 1723537127.247022, event_tx_id: Id(445), ref_name: ReferenceName("HEAD"), old_oid: 0000000000000000000000000000000000000000, new_oid: fcedac8eb2362186f5c119f988afd2acbd018abd, message: None }` 1. `RefUpdateEvent { timestamp: 1723537127.247022, event_tx_id: Id(445), ref_name: ReferenceName("refs/heads/redacted-ref-0"), old_oid: fcedac8eb2362186f5c119f988afd2acbd018abd, new_oid: fcedac8eb2362186f5c119f988afd2acbd018abd, message: None }` ``` O 6737fb1 22d (develop, redacted-ref-1) xxxxxxx xxxxxx | o 49ebb16 4m xxxx xxxxxx xxxxxxx xxxxx | o aefa858 4m xxxx xxx xxxxxx xxxxxxx xxxxxxxxxxxxx xxx xxxx | o 90bd9cc 4m xxxx xxxxxxx xxxxxxxxxxx xxxxx xxx | o 3cedbdb 4m xxxx xxx xxxx xxxxx xxxxxxx xx xxxxxxxxxx | o 648f702 4m xxxx xxx xxxxxxx xxxx xxxxxxxxxxx xxxxxxx | o 8971dbe 4m xxxxxxxxxxxx xxxxxxx xxxxxxxx xxxxx | o c8e03f6 4m xxxxx xxx xxx xxxxxxxxxx xxxxxxx | o 65e1c34 4m xxxxx xxxxxxxx xxxx xxxxxxxxxx xx xxxxxxx | @ 15388a9 4m (redacted-ref-0) xxxx xxx xxxxxxx xxx xxxxxxxxxxx xxx xxxxxxxxxxxxxxxxxx ``` ##### Event ID: 694, transaction ID: 444 (message: record) 1. `RefUpdateEvent { timestamp: 1723537104.158742, event_tx_id: Id(444), ref_name: ReferenceName("HEAD"), old_oid: 0000000000000000000000000000000000000000, new_oid: 2975945e7bbebc40831e1b6ac922fb6cf80ced53, message: None }` 1. `RefUpdateEvent { timestamp: 1723537104.158742, event_tx_id: Id(444), ref_name: ReferenceName("refs/heads/redacted-ref-0"), old_oid: 8d05f590f037992126569361bcfe406cf7abd93b, new_oid: 2975945e7bbebc40831e1b6ac922fb6cf80ced53, message: None }` 1. `CommitEvent { timestamp: 1723537072.0, event_tx_id: Id(444), commit_oid: NonZeroOid(2975945e7bbebc40831e1b6ac922fb6cf80ced53) }` ``` O 6737fb1 22d (develop, redacted-ref-1) xxxxxxx xxxxxx | o 49ebb16 4m xxxx xxxxxx xxxxxxx xxxxx | o aefa858 4m xxxx xxx xxxxxx xxxxxxx xxxxxxxxxxxxx xxx xxxx | o 90bd9cc 4m xxxx xxxxxxx xxxxxxxxxxx xxxxx xxx | o 3cedbdb 4m xxxx xxx xxxx xxxxx xxxxxxx xx xxxxxxxxxx | o 648f702 4m xxxx xxx xxxxxxx xxxx xxxxxxxxxxx xxxxxxx | o 8971dbe 4m xxxxxxxxxxxx xxxxxxx xxxxxxxx xxxxx | o c8e03f6 4m xxxxx xxx xxx xxxxxxxxxx xxxxxxx | o 65e1c34 4m xxxxx xxxxxxxx xxxx xxxxxxxxxx xx xxxxxxx | @ 15388a9 4m (redacted-ref-0) xxxx xxx xxxxxxx xxx xxxxxxxxxxx xxx xxxxxxxxxxxxxxxxxx ``` ##### Event ID: 688, transaction ID: 443 (message: amend) 1. `WorkingCopySnapshot { timestamp: 1723523833.178152, event_tx_id: Id(443), head_oid: 8e24ce086e781ddf0b687061585b5eb037f31aa1, commit_oid: NonZeroOid(9b2716e2a9ba30c229db68cab05d84d75831e181), ref_name: Some(ReferenceName("refs/heads/redacted-ref-0")) }` 1. `RewriteEvent { timestamp: 1723523833.178152, event_tx_id: Id(443), old_commit_oid: 8e24ce086e781ddf0b687061585b5eb037f31aa1, new_commit_oid: 8d05f590f037992126569361bcfe406cf7abd93b }` 1. `RefUpdateEvent { timestamp: 1723523833.353396, event_tx_id: Id(443), ref_name: ReferenceName("refs/heads/redacted-ref-0"), old_oid: 8e24ce086e781ddf0b687061585b5eb037f31aa1, new_oid: 8d05f590f037992126569361bcfe406cf7abd93b, message: None }` 1. `WorkingCopySnapshot { timestamp: 1723523833.380721, event_tx_id: Id(443), head_oid: 8d05f590f037992126569361bcfe406cf7abd93b, commit_oid: NonZeroOid(ca51571af82fb3d3c52f4c6600a1c21cda57cea7), ref_name: Some(ReferenceName("refs/heads/redacted-ref-0")) }` 1. `RefUpdateEvent { timestamp: 1723523833.519455, event_tx_id: Id(443), ref_name: ReferenceName("HEAD"), old_oid: 0000000000000000000000000000000000000000, new_oid: 8d05f590f037992126569361bcfe406cf7abd93b, message: None }` 1. `RefUpdateEvent { timestamp: 1723523833.519455, event_tx_id: Id(443), ref_name: ReferenceName("refs/heads/redacted-ref-0"), old_oid: 8d05f590f037992126569361bcfe406cf7abd93b, new_oid: 8d05f590f037992126569361bcfe406cf7abd93b, message: None }` ``` O 6737fb1 22d (develop, redacted-ref-1) xxxxxxx xxxxxx | o 49ebb16 4m xxxx xxxxxx xxxxxxx xxxxx | o aefa858 4m xxxx xxx xxxxxx xxxxxxx xxxxxxxxxxxxx xxx xxxx | o 90bd9cc 4m xxxx xxxxxxx xxxxxxxxxxx xxxxx xxx | o 3cedbdb 4m xxxx xxx xxxx xxxxx xxxxxxx xx xxxxxxxxxx | o 648f702 4m xxxx xxx xxxxxxx xxxx xxxxxxxxxxx xxxxxxx | o 8971dbe 4m xxxxxxxxxxxx xxxxxxx xxxxxxxx xxxxx | o c8e03f6 4m xxxxx xxx xxx xxxxxxxxxx xxxxxxx | o 65e1c34 4m xxxxx xxxxxxxx xxxx xxxxxxxxxx xx xxxxxxx | @ 15388a9 4m (redacted-ref-0) xxxx xxx xxxxxxx xxx xxxxxxxxxxx xxx xxxxxxxxxxxxxxxxxx ``` ##### Event ID: 685, transaction ID: 442 (message: record) 1. `RefUpdateEvent { timestamp: 1723522809.762482, event_tx_id: Id(442), ref_name: ReferenceName("HEAD"), old_oid: 0000000000000000000000000000000000000000, new_oid: 8e24ce086e781ddf0b687061585b5eb037f31aa1, message: None }` 1. `RefUpdateEvent { timestamp: 1723522809.762482, event_tx_id: Id(442), ref_name: ReferenceName("refs/heads/redacted-ref-0"), old_oid: a621b53ce7a32a19738353e5addff6eb6fd56793, new_oid: 8e24ce086e781ddf0b687061585b5eb037f31aa1, message: None }` 1. `CommitEvent { timestamp: 1723522662.0, event_tx_id: Id(442), commit_oid: NonZeroOid(8e24ce086e781ddf0b687061585b5eb037f31aa1) }` ``` O 6737fb1 22d (develop, redacted-ref-1) xxxxxxx xxxxxx | o 49ebb16 4m xxxx xxxxxx xxxxxxx xxxxx | o aefa858 4m xxxx xxx xxxxxx xxxxxxx xxxxxxxxxxxxx xxx xxxx | o 90bd9cc 4m xxxx xxxxxxx xxxxxxxxxxx xxxxx xxx | o 3cedbdb 4m xxxx xxx xxxx xxxxx xxxxxxx xx xxxxxxxxxx | o 648f702 4m xxxx xxx xxxxxxx xxxx xxxxxxxxxxx xxxxxxx | o 8971dbe 4m xxxxxxxxxxxx xxxxxxx xxxxxxxx xxxxx | o c8e03f6 4m xxxxx xxx xxx xxxxxxxxxx xxxxxxx | o 65e1c34 4m xxxxx xxxxxxxx xxxx xxxxxxxxxx xx xxxxxxx | @ 15388a9 4m (redacted-ref-0) xxxx xxx xxxxxxx xxx xxxxxxxxxxx xxx xxxxxxxxxxxxxxxxxx ```

Version of git-branchless

No response

Version of git

No response

arxanas commented 1 month ago

It might be straightforward to fix. I think you have to actually do less work and remove the special-purpose checks in the git reword code, and add the check to the general rebase engine to skip the rewrite if the commit is being replaced with itself.