arxanas / git-branchless

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

having trouble restacking when updating a commit at the bottom of a stack #1391

Open Kimeiga opened 2 weeks ago

Kimeiga commented 2 weeks ago

Description of the bug

https://pastebin.com/Wb3A0P0U

so it looks like removing update-refs fixed git sync, but still when i commit to a commit in the bottom of a stack, it doesn't seem to let me restack

my commit and push command is g a aliased to a = "!f() { git add --all && git commit --amend --no-edit && git restack && git submit; }; f"

is there something wrong with this

Expected behavior

the commit to not be duplicated

Actual behavior

the commit gets duplicated and the stack becomes outdated

Version of rustc

rustc 1.78.0 (9b00956e5 2024-04-29)

Automated bug report

Software version

git-branchless 0.9.0

Operating system

macOS 14.6.1 (Darwin 23.6.0)

Command-line

/Users/hakan.alpay/.cargo/bin/git-branchless bug-report 

Environment variables

SHELL=/bin/zsh
EDITOR=nvim

Git version

> git version 
git version 2.39.3 (Apple Git-146)

Hooks

Show 7 hooks ##### Hook `post-applypatch` ``` ``` ##### Hook `post-checkout` ``` ``` ##### Hook `post-commit` ``` ``` ##### Hook `post-merge` ``` ``` ##### Hook `post-rewrite` ``` ``` ##### Hook `pre-auto-gc` ``` ``` ##### Hook `reference-transaction` ``` ```

Events

Show 5 events ##### Event ID: 22790, transaction ID: 11377 (message: prev) 1. `WorkingCopySnapshot { timestamp: 1725472937.510231, event_tx_id: Id(11377), head_oid: 7c8016d6115b7097ce9349e3f966b28aea408eff, commit_oid: NonZeroOid(5f246a113ba8cc676594bc2089c889160bf625ca), ref_name: Some(ReferenceName("refs/heads/redacted-ref-0")) }` ``` : O e7790b9 1h (master) xxxx xxxxxxxx xxxxx xxx |\ | o 3d104fa 22m (redacted-ref-1) xxxxxxxxx xxxxx xxxxxxx xxxx xxxx xxx xxx |\ | o 50149ff 22m (redacted-ref-2) xxxx |\ | o ca45546 22m (redacted-ref-3) xxxxxxxxxxxxxxxxxxx xxxxxxx xxxx xxxx xxx xxx |\ | o cc1b06f 22m (redacted-ref-4) xxxxxxxxx xxxxxxxxxx xxxx xxxxxxxx xxxxx xxxxxxxx xxx xxx |\ | o e0c93d7 22m xxxxxxxx xxxxx xxxxxx xxxxx xxx xxxxxxxxxx xxxxx xxxxxxx xxxxxxxxx | | | o 7c8016d 22m (redacted-ref-0) xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx |\ | o ee70afa 22m (redacted-ref-5) xxxxxxxx xxx xxxxx xxx xxxxxxxxxx xx xxxxx xxxx | | | o 39372a5 22m (redacted-ref-6) xxxxxxxx xxx xxxxx xxxxxxxxxx xxxx xx xxxxxx xxxxx | @ c3b90a7 13m (redacted-ref-7) xxxxxxxx xxxxx xxxxxx xxxxx xxx xxxxxxxxxx xxxxx xxxxxxx xxxxxxxxx ``` ##### Event ID: 22784, transaction ID: 11376 (message: sync) 1. `WorkingCopySnapshot { timestamp: 1725472932.818385, event_tx_id: Id(11376), head_oid: 3e882e79b0d79678fa34eb42a22891163e86e944, commit_oid: NonZeroOid(55d460a2fa3699e081e5a0411383bc57e1beccb7), ref_name: None }` 1. `WorkingCopySnapshot { timestamp: 1725472933.087694, event_tx_id: Id(11376), head_oid: 3e882e79b0d79678fa34eb42a22891163e86e944, commit_oid: NonZeroOid(55d460a2fa3699e081e5a0411383bc57e1beccb7), ref_name: None }` 1. `WorkingCopySnapshot { timestamp: 1725472933.314692, event_tx_id: Id(11376), head_oid: 3e882e79b0d79678fa34eb42a22891163e86e944, commit_oid: NonZeroOid(55d460a2fa3699e081e5a0411383bc57e1beccb7), ref_name: None }` 1. `WorkingCopySnapshot { timestamp: 1725472933.543282, event_tx_id: Id(11376), head_oid: 3e882e79b0d79678fa34eb42a22891163e86e944, commit_oid: NonZeroOid(55d460a2fa3699e081e5a0411383bc57e1beccb7), ref_name: None }` 1. `WorkingCopySnapshot { timestamp: 1725472933.779001, event_tx_id: Id(11376), head_oid: 3e882e79b0d79678fa34eb42a22891163e86e944, commit_oid: NonZeroOid(55d460a2fa3699e081e5a0411383bc57e1beccb7), ref_name: None }` 1. `WorkingCopySnapshot { timestamp: 1725472934.013454, event_tx_id: Id(11376), head_oid: 3e882e79b0d79678fa34eb42a22891163e86e944, commit_oid: NonZeroOid(55d460a2fa3699e081e5a0411383bc57e1beccb7), ref_name: None }` ``` : O e7790b9 1h (master) xxxx xxxxxxxx xxxxx xxx |\ | o 3d104fa 22m (redacted-ref-1) xxxxxxxxx xxxxx xxxxxxx xxxx xxxx xxx xxx |\ | o 50149ff 22m (redacted-ref-2) xxxx |\ | o ca45546 22m (redacted-ref-3) xxxxxxxxxxxxxxxxxxx xxxxxxx xxxx xxxx xxx xxx |\ | o cc1b06f 22m (redacted-ref-4) xxxxxxxxx xxxxxxxxxx xxxx xxxxxxxx xxxxx xxxxxxxx xxx xxx |\ | o e0c93d7 22m xxxxxxxx xxxxx xxxxxx xxxxx xxx xxxxxxxxxx xxxxx xxxxxxx xxxxxxxxx | | | o 7c8016d 22m (redacted-ref-0) xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx |\ | o ee70afa 22m (redacted-ref-5) xxxxxxxx xxx xxxxx xxx xxxxxxxxxx xx xxxxx xxxx | | | o 39372a5 22m (redacted-ref-6) xxxxxxxx xxx xxxxx xxxxxxxxxx xxxx xx xxxxxx xxxxx | @ c3b90a7 13m (redacted-ref-7) xxxxxxxx xxxxx xxxxxx xxxxx xxx xxxxxxxxxx xxxxx xxxxxxx xxxxxxxxx ``` ##### Event ID: 22783, transaction ID: 11370 (message: prev) 1. `WorkingCopySnapshot { timestamp: 1725472900.30404, event_tx_id: Id(11370), head_oid: d81fe052e6129b28e7d66e482b39ad2e545fc2ad, commit_oid: NonZeroOid(a792cd0e665f3b823477f8553bc1e134a8541857), ref_name: Some(ReferenceName("refs/heads/redacted-ref-0")) }` ``` : O e7790b9 1h (master) xxxx xxxxxxxx xxxxx xxx |\ | o 3d104fa 22m (redacted-ref-1) xxxxxxxxx xxxxx xxxxxxx xxxx xxxx xxx xxx |\ | o 50149ff 22m (redacted-ref-2) xxxx |\ | o ca45546 22m (redacted-ref-3) xxxxxxxxxxxxxxxxxxx xxxxxxx xxxx xxxx xxx xxx |\ | o cc1b06f 22m (redacted-ref-4) xxxxxxxxx xxxxxxxxxx xxxx xxxxxxxx xxxxx xxxxxxxx xxx xxx |\ | o e0c93d7 22m xxxxxxxx xxxxx xxxxxx xxxxx xxx xxxxxxxxxx xxxxx xxxxxxx xxxxxxxxx | | | o 7c8016d 22m (redacted-ref-0) xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx |\ | o ee70afa 22m (redacted-ref-5) xxxxxxxx xxx xxxxx xxx xxxxxxxxxx xx xxxxx xxxx | | | o 39372a5 22m (redacted-ref-6) xxxxxxxx xxx xxxxx xxxxxxxxxx xxxx xx xxxxxx xxxxx | @ c3b90a7 13m (redacted-ref-7) xxxxxxxx xxxxx xxxxxx xxxxx xxx xxxxxxxxxx xxxxx xxxxxxx xxxxxxxxx ``` ##### Event ID: 22782, transaction ID: 11365 (message: next) 1. `WorkingCopySnapshot { timestamp: 1725465141.043426, event_tx_id: Id(11365), head_oid: a8d9d07e940abe48745cbcad6a8631430e1e85a7, commit_oid: NonZeroOid(7ae90a2819cb02fab3c107e4e7eaafef636533ae), ref_name: Some(ReferenceName("refs/heads/redacted-ref-7")) }` ``` : O e7790b9 1h (master) xxxx xxxxxxxx xxxxx xxx |\ | o 3d104fa 22m (redacted-ref-1) xxxxxxxxx xxxxx xxxxxxx xxxx xxxx xxx xxx |\ | o 50149ff 22m (redacted-ref-2) xxxx |\ | o ca45546 22m (redacted-ref-3) xxxxxxxxxxxxxxxxxxx xxxxxxx xxxx xxxx xxx xxx |\ | o cc1b06f 22m (redacted-ref-4) xxxxxxxxx xxxxxxxxxx xxxx xxxxxxxx xxxxx xxxxxxxx xxx xxx |\ | o e0c93d7 22m xxxxxxxx xxxxx xxxxxx xxxxx xxx xxxxxxxxxx xxxxx xxxxxxx xxxxxxxxx | | | o 7c8016d 22m (redacted-ref-0) xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx |\ | o ee70afa 22m (redacted-ref-5) xxxxxxxx xxx xxxxx xxx xxxxxxxxxx xx xxxxx xxxx | | | o 39372a5 22m (redacted-ref-6) xxxxxxxx xxx xxxxx xxxxxxxxxx xxxx xx xxxxxx xxxxx | @ c3b90a7 13m (redacted-ref-7) xxxxxxxx xxxxx xxxxxx xxxxx xxx xxxxxxxxxx xxxxx xxxxxxx xxxxxxxxx ``` ##### Event ID: 22781, transaction ID: 11364 (message: move) 1. `WorkingCopySnapshot { timestamp: 1725465135.834757, event_tx_id: Id(11364), head_oid: a8d9d07e940abe48745cbcad6a8631430e1e85a7, commit_oid: NonZeroOid(e4055e7b36b6e36f291059b6888cbe65a01f22b9), ref_name: None }` ``` : O e7790b9 1h (master) xxxx xxxxxxxx xxxxx xxx |\ | o 3d104fa 22m (redacted-ref-1) xxxxxxxxx xxxxx xxxxxxx xxxx xxxx xxx xxx |\ | o 50149ff 22m (redacted-ref-2) xxxx |\ | o ca45546 22m (redacted-ref-3) xxxxxxxxxxxxxxxxxxx xxxxxxx xxxx xxxx xxx xxx |\ | o cc1b06f 22m (redacted-ref-4) xxxxxxxxx xxxxxxxxxx xxxx xxxxxxxx xxxxx xxxxxxxx xxx xxx |\ | o e0c93d7 22m xxxxxxxx xxxxx xxxxxx xxxxx xxx xxxxxxxxxx xxxxx xxxxxxx xxxxxxxxx | | | o 7c8016d 22m (redacted-ref-0) xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx |\ | o ee70afa 22m (redacted-ref-5) xxxxxxxx xxx xxxxx xxx xxxxxxxxxx xx xxxxx xxxx | | | o 39372a5 22m (redacted-ref-6) xxxxxxxx xxx xxxxx xxxxxxxxxx xxxx xx xxxxxx xxxxx | @ c3b90a7 13m (redacted-ref-7) xxxxxxxx xxxxx xxxxxx xxxxx xxx xxxxxxxxxx xxxxx xxxxxxx xxxxxxxxx ```

Version of git-branchless

No response

Version of git

No response

Kimeiga commented 2 weeks ago

image it happens right when i commit

claytonrcarter commented 2 weeks ago
  1. check that the git branchless hooks are all intact and correct, esp if you had conflicts w/ other hooks; it could be that one of them is no longer installed and is not catching the changes
  2. git add --all && git commit --amend --no-edit && git restack something in here may be getting in the way; perhaps try git amend instead, which should replace all 3 of these commands
Kimeiga commented 2 weeks ago
  1. how can I do that, is it sufficient to rerun git branchless init

do you think a precommit script could be causing this? The only thing that makes me doubt that is that this was working before and I still had the same precommit script.

  1. TIL!

although when I did the commands one by one I noticed it duplicated the commit right when i ran git commit --amend --no-edit

claytonrcarter commented 2 weeks ago

how can I do that, is it sufficient to rerun git branchless init Yes I think so, but it may interfere with other hooks you have installed. I can’t remember how it works, sorry. I can say, though, that looking at the output of your bug report, it looks like you may not have any of the relevant hooks in place. (They all report “not found”.) That would explain this behavior

So yes I would either run init again, or perhaps do so in a new repo and compare them hooks there to what you have in this repo, updating accordingly.

do you think a precommit script could be causing this? The only thing that makes me doubt that is that this was working before and I still had the same precommit script.

Probably not. As I recall, branchless only uses the post commit hook, not pre commit.

Kimeiga commented 2 weeks ago

btw if i use git amend here do i want the --reparent flag? i want to cleanly update a commit in the middle of the stack, it looks like this option is necessary to do that? If that's the case btw why is it not the default behavior?

git add --all && git commit --amend --no-edit && git restack something in here may be getting in the way; perhaps try git amend instead, which should replace all 3 of these commands

how can git amend replace git add --all? it looks like you need to git add first

also when i try the reparent flag it doesn't do anything:

~/Projects/web-next/services/consumer-web-next NVG-984_finishing_placement_model*
» git amend --reparent
unknown flag `reparent'
panic: unknown flag `reparent'

goroutine 1 [running]:
main.check(...)
        /Users/runner/work/spr/spr/cmd/amend/main.go:75
main.main()
        /Users/runner/work/spr/spr/cmd/amend/main.go:39 +0x3a8

actually i'm really confused about git amend how come it's not amending the commit that i have checked out as HEAD here?

~/Projects/web-next/services/consumer-web-next NVG-984_finishing_placement_model* 8s
» g s
On branch NVG-984_finishing_placement_model
Your branch is up to date with 'origin/NVG-984_finishing_placement_model'.

Changes to be committed:
  (use "git restore --staged <file>..." to unstage)
        modified:   src/CxComponentCatalog/AdsAndPromos/USI/PlacementModel/PlacementModel.tsx

~/Projects/web-next/services/consumer-web-next NVG-984_finishing_placement_model*
» g amend       
> git rev-parse --show-toplevel
> git log --format=medium --no-color origin/NVG-984_finishing_placement_model..HEAD
No commits to amend

~/Projects/web-next/services/consumer-web-next NVG-984_finishing_placement_model*
» g l    
* a81501915d0  2 weeks ago Hakan Alpay (HEAD -> NVG-984_finishing_placement_model, origin/NVG-984_finishing_placement_model) NVG-984_finishing_placement_model
* 0415a0dfdd7   2 days ago Hakan Alpay (origin/NVG-1022_USI_create_terms_and_conditions_modal_catalog_component, NVG-1022_USI_create_terms_and_conditions_modal_catalog_component) NVG-1022 [USI] Create Terms and Conditions Modal Catalog Component
* 8c319f63a43 13 hours ago Danny Fann (tag: dev-console-email-service_3.361.0, origin/release/dev-console-email-service_3.361.x, origin/publish/8c319f63a4367fcc2a4de3ea6817c7e18df989ff, origin/master, origin/invoice2go_v1_main, origin/i18n_-AsyncTrans-1725629407738, origin/HEAD, master) Temporarily disable email send while looking into PR reviews (#22918)
* d8712f8dd39 16 hours ago James Maher (tag: consumer-web-next_2.3638.0, tag: consumer-web-next-e2e_2.1046.0, origin/release/consumer-web-next_2.3638.x, origin/release/consumer-web-next-e2e_2.1046.x, origin/publish/d8712f8dd39de781fccf05fdc0b65e0193107311) patch: temporarily pause CWN merge queue (#22920)
* eeaace48dea 17 hours ago web-next-automation (origin/publish/82c3ee24079341b74dd1a0628ae1104085f44539) Bump versions [skip ci]
* 8a464844641 17 hours ago web-next-automation Update changelogs [skip ci]
* 82c3ee24079 17 hours ago Jon Collette App developer admin parity update (#22852)
* adbc74af42a 17 hours ago web-next-automation (origin/publish/faeeb48c41fdbd70e3b9a9e0fbb9135aa1a84653) Bump versions [skip ci]
* 38ab8ae5656 17 hours ago web-next-automation Update changelogs [skip ci]
* faeeb48c41f 17 hours ago chrisguan Add strings to i18n (#22726)
claytonrcarter commented 2 weeks ago

do i want the --reparent flag? i want to cleanly update a commit in the middle of the stack

Probably not, but it depends on context. Take a look at https://github.com/arxanas/git-branchless/wiki/Command:-git-amend#forcibly-amending-without-changing-children for more info about --reparent, but the gist is that it instructs the command to, in effect, "update the current commit with the changes, and then rebase the child commits onto the updated commit, but with their exact, unchanged contents". Formatting is a great example of where that's useful, but I have also used in a case where I made a change in the wrong place/commit and wanted to also update the parent commit w/ the change: I updated the parent, but doing a regular rebase would almost certainly have caused a conflict, and because I knew the intended change already existed in the children, I used --reparent to update the parent and then rebase the children with their existing contents, w/o trying to propogate the changes from the newly updated parent.

So, I guess:

how can git amend replace git add --all? it

For me, this is the killer feature of amend (and record):

Basically, it's git commit --amend but with some "do what I mean" added in and some rough edges polished off.

also when i try the reparent flag it doesn't do anything:

The error message isn't coming from git or git-branchless, but from spr. I'm not familiar with spr, but may I assume that it also has an amend command? My hunch is that your alias for amend is pointing at spr, not at git-branchless. What happens if you explicitly call git branchless amend --reparent instead?

actually i'm really confused about git amend how come it's not amending the commit that i have checked out as HEAD here?

I suspect that this is the above issue, with spr. What happens if you try git branchless amend instead?