Commit c3653a2
committed
Create/update the remote stack on sync and fix false "Stack synced"
`gh stack sync` reported "Stack synced" even when it had not created or
updated the stack object on GitHub. After running `gh stack init` to
adopt existing branches and then opening PRs outside the CLI, `gh stack
sync` detected the open PRs and printed "Stack synced" — but no stack had
ever been created on the server.
There were two distinct bugs:
1. Sync never reconciled the remote stack object. `runSync` called
`syncStackPRs`, which only *reads* PR state and links PRs to local
branches; it never called the create/update path. So the branches were
rebased and pushed and the PRs were detected, but the stack on GitHub
was never created.
2. The final message was unconditional. `runSync` always printed "Stack
synced", which is supposed to mean "the stack object on GitHub now
reflects the local stack" — something that can only be true when two or
more open PRs exist and the remote stack was actually created/updated.
Fix
Reconcile the remote stack from sync, and make the closing message reflect
what actually happened.
* cmd/sync.go
- Add a reconciliation step (5b) after PR-state sync: when the stack has
two or more open PRs, link them into a stack on GitHub via the new
`syncRemoteStack` helper. It inspects existing stacks first and:
- short-circuits quietly when a remote stack already lists exactly
these PRs (records the ID, prints "Stack already up to date on
GitHub") so routine syncs don't issue a redundant, misleading
update;
- otherwise delegates to `syncStack` to create a new stack, adopt an
untracked one, or update a partially-formed one.
Sync never opens PRs — that remains `gh stack submit`'s job.
- Replace the unconditional "Stack synced" with a result-driven message:
"Stack synced" when the remote stack object was created/updated/in
sync, otherwise "Branches synced" (fewer than two PRs, stacked PRs
unavailable, a cross-stack divergence, or no GitHub client).
- Update the command's long description to document the stack-object
step and the two possible closing messages.
* cmd/submit.go
- Thread a `synced bool` return through the existing, tested stack
helpers so sync can tell whether the remote stack object now matches
local: `syncStack`, `createNewStack`, and `updateStack` now return
`bool`; `adoptRemoteStack` returns `(handled, synced)`; and
`handleCreate422` returns `bool` (true only when the PRs are already
stacked together). Extract the shared `stackPRNumbers` helper.
- This is additive: submit's single call site ignores the new return
value, so submit's behavior, output, and tests are unchanged. Reusing
these helpers (instead of duplicating the 404/422 handling in sync)
keeps the create/adopt/update logic in one tested place.
Tests
* cmd/sync_test.go — six new cases covering the reconciliation matrix:
- TestSync_CreatesRemoteStackWhenPRsExist: open PRs but no remote stack
-> CreateStack is called and the new ID is persisted to the stack file;
output contains "Stack created on GitHub" and "Stack synced".
- TestSync_AdoptsExistingEqualRemoteStack: a matching remote stack ->
no create/update, ID recorded, "Stack synced".
- TestSync_UpdatesPartialRemoteStack: a subset stack -> UpdateStack with
the full PR list, "Stack synced".
- TestSync_FewerThanTwoPRs_BranchesSynced: one PR -> no stack API calls,
"Branches synced", not "Stack synced".
- TestSync_StacksUnavailable_BranchesSynced: 404 on create -> warns,
"Branches synced".
- TestSync_PRsSpanMultipleStacks_BranchesSynced: PRs across two stacks ->
divergence warning, no create/update, "Branches synced".
Docs
Document the new stack-object step and the "Stack synced" vs "Branches
synced" distinction in:
- README.md
- docs/src/content/docs/reference/cli.md
- skills/gh-stack/SKILL.md
- docs/src/content/docs/introduction/overview.md
- docs/src/content/docs/guides/stacked-prs.md
- docs/src/content/docs/guides/workflows.md1 parent a9fa574 commit c3653a2
9 files changed
Lines changed: 401 additions & 48 deletions
File tree
- cmd
- docs/src/content/docs
- guides
- introduction
- reference
- skills/gh-stack
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
323 | 323 | | |
324 | 324 | | |
325 | 325 | | |
326 | | - | |
| 326 | + | |
| 327 | + | |
327 | 328 | | |
328 | 329 | | |
329 | 330 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
684 | 684 | | |
685 | 685 | | |
686 | 686 | | |
687 | | - | |
688 | | - | |
689 | | - | |
690 | | - | |
691 | | - | |
692 | | - | |
693 | | - | |
694 | | - | |
695 | | - | |
696 | | - | |
| 687 | + | |
| 688 | + | |
| 689 | + | |
| 690 | + | |
697 | 691 | | |
698 | 692 | | |
699 | 693 | | |
700 | 694 | | |
701 | 695 | | |
702 | 696 | | |
| 697 | + | |
| 698 | + | |
| 699 | + | |
| 700 | + | |
| 701 | + | |
| 702 | + | |
| 703 | + | |
| 704 | + | |
| 705 | + | |
| 706 | + | |
| 707 | + | |
| 708 | + | |
| 709 | + | |
| 710 | + | |
| 711 | + | |
703 | 712 | | |
704 | 713 | | |
705 | 714 | | |
706 | | - | |
| 715 | + | |
707 | 716 | | |
708 | 717 | | |
709 | 718 | | |
710 | | - | |
711 | | - | |
| 719 | + | |
712 | 720 | | |
713 | 721 | | |
714 | 722 | | |
715 | 723 | | |
716 | 724 | | |
717 | 725 | | |
718 | | - | |
719 | | - | |
| 726 | + | |
| 727 | + | |
720 | 728 | | |
721 | 729 | | |
722 | | - | |
| 730 | + | |
723 | 731 | | |
724 | 732 | | |
725 | 733 | | |
| |||
728 | 736 | | |
729 | 737 | | |
730 | 738 | | |
731 | | - | |
732 | | - | |
733 | | - | |
734 | | - | |
735 | | - | |
| 739 | + | |
| 740 | + | |
| 741 | + | |
| 742 | + | |
| 743 | + | |
| 744 | + | |
736 | 745 | | |
737 | 746 | | |
738 | 747 | | |
739 | 748 | | |
740 | | - | |
| 749 | + | |
741 | 750 | | |
742 | 751 | | |
743 | 752 | | |
| |||
748 | 757 | | |
749 | 758 | | |
750 | 759 | | |
751 | | - | |
| 760 | + | |
752 | 761 | | |
753 | 762 | | |
754 | 763 | | |
755 | 764 | | |
756 | | - | |
| 765 | + | |
757 | 766 | | |
758 | 767 | | |
759 | 768 | | |
| |||
763 | 772 | | |
764 | 773 | | |
765 | 774 | | |
766 | | - | |
| 775 | + | |
767 | 776 | | |
768 | 777 | | |
769 | 778 | | |
| |||
773 | 782 | | |
774 | 783 | | |
775 | 784 | | |
776 | | - | |
| 785 | + | |
777 | 786 | | |
778 | 787 | | |
779 | 788 | | |
780 | | - | |
781 | | - | |
| 789 | + | |
782 | 790 | | |
783 | 791 | | |
784 | 792 | | |
| |||
800 | 808 | | |
801 | 809 | | |
802 | 810 | | |
803 | | - | |
| 811 | + | |
| 812 | + | |
804 | 813 | | |
805 | 814 | | |
806 | 815 | | |
| |||
809 | 818 | | |
810 | 819 | | |
811 | 820 | | |
812 | | - | |
| 821 | + | |
813 | 822 | | |
814 | 823 | | |
815 | 824 | | |
| |||
818 | 827 | | |
819 | 828 | | |
820 | 829 | | |
821 | | - | |
| 830 | + | |
822 | 831 | | |
823 | 832 | | |
824 | 833 | | |
| |||
827 | 836 | | |
828 | 837 | | |
829 | 838 | | |
830 | | - | |
| 839 | + | |
831 | 840 | | |
832 | 841 | | |
| 842 | + | |
833 | 843 | | |
834 | 844 | | |
835 | 845 | | |
836 | 846 | | |
837 | | - | |
| 847 | + | |
| 848 | + | |
838 | 849 | | |
839 | 850 | | |
840 | 851 | | |
841 | 852 | | |
842 | | - | |
| 853 | + | |
843 | 854 | | |
844 | 855 | | |
845 | 856 | | |
846 | 857 | | |
847 | 858 | | |
848 | | - | |
| 859 | + | |
849 | 860 | | |
850 | 861 | | |
851 | 862 | | |
852 | 863 | | |
853 | | - | |
| 864 | + | |
854 | 865 | | |
855 | 866 | | |
| 867 | + | |
856 | 868 | | |
857 | 869 | | |
| 870 | + | |
858 | 871 | | |
859 | 872 | | |
860 | 873 | | |
| |||
863 | 876 | | |
864 | 877 | | |
865 | 878 | | |
866 | | - | |
| 879 | + | |
| 880 | + | |
| 881 | + | |
| 882 | + | |
867 | 883 | | |
868 | 884 | | |
869 | 885 | | |
| |||
872 | 888 | | |
873 | 889 | | |
874 | 890 | | |
875 | | - | |
| 891 | + | |
876 | 892 | | |
877 | 893 | | |
878 | 894 | | |
879 | 895 | | |
880 | | - | |
| 896 | + | |
881 | 897 | | |
882 | 898 | | |
883 | 899 | | |
884 | 900 | | |
885 | 901 | | |
886 | | - | |
| 902 | + | |
887 | 903 | | |
888 | 904 | | |
889 | 905 | | |
890 | 906 | | |
| 907 | + | |
891 | 908 | | |
892 | 909 | | |
893 | 910 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3 | 3 | | |
4 | 4 | | |
5 | 5 | | |
| 6 | + | |
6 | 7 | | |
7 | 8 | | |
8 | 9 | | |
9 | 10 | | |
10 | 11 | | |
| 12 | + | |
11 | 13 | | |
12 | 14 | | |
13 | 15 | | |
| |||
33 | 35 | | |
34 | 36 | | |
35 | 37 | | |
| 38 | + | |
| 39 | + | |
36 | 40 | | |
37 | 41 | | |
38 | 42 | | |
39 | 43 | | |
40 | 44 | | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
41 | 52 | | |
42 | 53 | | |
43 | 54 | | |
| |||
220 | 231 | | |
221 | 232 | | |
222 | 233 | | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
223 | 246 | | |
224 | 247 | | |
225 | 248 | | |
| |||
316 | 339 | | |
317 | 340 | | |
318 | 341 | | |
319 | | - | |
| 342 | + | |
| 343 | + | |
| 344 | + | |
| 345 | + | |
| 346 | + | |
| 347 | + | |
| 348 | + | |
| 349 | + | |
320 | 350 | | |
321 | 351 | | |
322 | 352 | | |
| 353 | + | |
| 354 | + | |
| 355 | + | |
| 356 | + | |
| 357 | + | |
| 358 | + | |
| 359 | + | |
| 360 | + | |
| 361 | + | |
| 362 | + | |
| 363 | + | |
| 364 | + | |
| 365 | + | |
| 366 | + | |
| 367 | + | |
| 368 | + | |
| 369 | + | |
| 370 | + | |
| 371 | + | |
| 372 | + | |
| 373 | + | |
| 374 | + | |
| 375 | + | |
| 376 | + | |
| 377 | + | |
| 378 | + | |
| 379 | + | |
| 380 | + | |
| 381 | + | |
| 382 | + | |
| 383 | + | |
| 384 | + | |
| 385 | + | |
| 386 | + | |
| 387 | + | |
| 388 | + | |
| 389 | + | |
| 390 | + | |
323 | 391 | | |
324 | 392 | | |
325 | 393 | | |
| |||
0 commit comments