abhinav / git-spice

Manage stacked Git branches
https://abhinav.github.io/git-spice/
GNU General Public License v3.0
228 stars 15 forks source link

Syncing a repo after landing all of the branches in a stack preforms many unecessary steps #398

Closed klnusbaum closed 1 month ago

klnusbaum commented 1 month ago

In my repo, I was a branch for stack X. While I was there, I merged a bunch of branches for Stack Y. I then ran gs rs && gs br. My intent was to delete all of the merged branches in Stack Y, and then restack Stack X on the new master. I noticed that instead of simply deleting all of the branches in Stack Y (now that they were all merged), git-spice proceeded to delete them one-by-one, and do a restack operations for the rest of the stack each time (and for some reason, the deleting of the last two branches failed). See:

INF master: pulled 11 new commit(s)
INF kurtis/p2-new-vars-rc: #7423 was merged
INF kurtis/p3-new-vars-rc-infra: #7424 was merged
INF kurtis/p4-new-vars-rc-b: #7425 was merged
INF kurtis/p5-new-vars-prod-a: #7426 was merged
INF kurtis/p6-new-vars-prod-b: #7427 was merged
INF kurtis/p7-new-vars-prod-c: #7428 was merged
INF kurtis/p8-new-vars-prod-eu: #7429 was merged
INF kurtis/p9-new-vars-rc-eu-a: #7430 was merged
INF kurtis/p3-new-vars-rc-infra: moved upstack onto master
INF kurtis/p4-new-vars-rc-b: restacked on kurtis/p3-new-vars-rc-infra
INF kurtis/p5-new-vars-prod-a: restacked on kurtis/p4-new-vars-rc-b
INF kurtis/p6-new-vars-prod-b: restacked on kurtis/p5-new-vars-prod-a
INF kurtis/p7-new-vars-prod-c: restacked on kurtis/p6-new-vars-prod-b
INF kurtis/p8-new-vars-prod-eu: restacked on kurtis/p7-new-vars-prod-c
INF kurtis/p9-new-vars-rc-eu-a: restacked on kurtis/p8-new-vars-prod-eu
INF kurtis/p2-new-vars-rc: deleted (was 7da7871)
INF kurtis/p4-new-vars-rc-b: moved upstack onto master
INF kurtis/p5-new-vars-prod-a: branch does not need to be restacked.
INF kurtis/p6-new-vars-prod-b: branch does not need to be restacked.
INF kurtis/p7-new-vars-prod-c: branch does not need to be restacked.
INF kurtis/p8-new-vars-prod-eu: branch does not need to be restacked.
INF kurtis/p9-new-vars-rc-eu-a: branch does not need to be restacked.
INF kurtis/p3-new-vars-rc-infra: deleted (was 40fb5fb)
INF kurtis/p5-new-vars-prod-a: moved upstack onto master
INF kurtis/p6-new-vars-prod-b: branch does not need to be restacked.
INF kurtis/p7-new-vars-prod-c: branch does not need to be restacked.
INF kurtis/p8-new-vars-prod-eu: branch does not need to be restacked.
INF kurtis/p9-new-vars-rc-eu-a: branch does not need to be restacked.
INF kurtis/p4-new-vars-rc-b: deleted (was 40fb5fb)
INF kurtis/p6-new-vars-prod-b: moved upstack onto master
INF kurtis/p7-new-vars-prod-c: branch does not need to be restacked.
INF kurtis/p8-new-vars-prod-eu: branch does not need to be restacked.
INF kurtis/p9-new-vars-rc-eu-a: branch does not need to be restacked.
INF kurtis/p5-new-vars-prod-a: deleted (was 40fb5fb)
INF kurtis/p7-new-vars-prod-c: moved upstack onto master
INF kurtis/p8-new-vars-prod-eu: branch does not need to be restacked.
INF kurtis/p9-new-vars-rc-eu-a: branch does not need to be restacked.
INF kurtis/p6-new-vars-prod-b: deleted (was 40fb5fb)
INF kurtis/p8-new-vars-prod-eu: moved upstack onto master
INF kurtis/p9-new-vars-rc-eu-a: branch does not need to be restacked.
INF kurtis/p7-new-vars-prod-c: deleted (was 40fb5fb)
FTL gs: delete branch kurtis/p8-new-vars-prod-eu: get branch: tracked branch kurtis/p9-new-vars-rc-eu-a was deleted out of band

When several or all of the branches in a stack are deleted, I would expect only necessary restacking to occur.

abhinav commented 1 month ago

Yeah, I think the "PR was merged, delete the branch" handling needs to batch-delete the contiguous parts of the stack. It also needs to determine the deletion ordering. I suspected this would be a problem, but hadn't run into it yet:

https://github.com/abhinav/git-spice/blob/83da8d249d92f275752a4778b419a96c0e44f8ec/repo_sync.go#L389-L391