@@ -138,6 +138,7 @@ export const branchSequencer: BranchSequencer = async ({
138138 } ) ;
139139
140140 const cmd = cmds [ 0 ] ;
141+
141142 assert ( cmd . rebaseKind === "stacked" ) ;
142143
143144 const targetCommitSHA : string | null = cmd . commitSHAThatBranchPointsTo ;
@@ -148,9 +149,59 @@ export const branchSequencer: BranchSequencer = async ({
148149
149150 assert ( cmd . targets ?. length ) ;
150151
151- const targetBranch = cmd . targets [ 0 ] . replace ( "refs/heads/" , "" ) ;
152+ let targetBranch = cmd . targets [ 0 ] . replace ( "refs/heads/" , "" ) ;
152153 assert ( targetBranch && typeof targetBranch === "string" ) ;
153154
155+ /**
156+ * if we only have the remote branch, but it's not checked out locally,
157+ * we'd end up in a detached state, and things would break.
158+ *
159+ * thus, we checkout the branch locally if it's not.
160+ */
161+ // if (!Git.Branch.lookup(repo, targetBranch, Git.Branch.BRANCH.LOCAL)) {
162+ // execSyncInRepo();
163+ // }
164+ if ( targetBranch . startsWith ( "refs/remotes/" ) ) {
165+ /**
166+ * TODO - probably should handle this "checkout remote branch locally" logic
167+ * in a better place than here,
168+ *
169+ * especially since this is quite fragile,
170+ * e.g. if multiple remotes exist & have the same branch..
171+ *
172+ * here's a hint that git gives in this situation (& exits w/ 1 so good that errors)
173+ *
174+ * ```
175+ * hint: If you meant to check out a remote tracking branch on, e.g. 'origin',
176+ * hint: you can do so by fully qualifying the name with the --track option:
177+ * hint:
178+ * hint: git checkout --track origin/<name>
179+ * hint:
180+ * hint: If you'd like to always have checkouts of an ambiguous <name> prefer
181+ * hint: one remote, e.g. the 'origin' remote, consider setting
182+ * hint: checkout.defaultRemote=origin in your config.
183+ * fatal: 'fork' matched multiple (2) remote tracking branches
184+ * ```
185+ *
186+ * seems like we should be checking all the branches somewhere early,
187+ * and either checking them out locally,
188+ * or if not possible because multiple remotes, then asking them
189+ * which remote to use (or individual, idk).
190+ *
191+ * tho, this might not always be necessary, so maybe not good
192+ * to ask for something that might not be needed?
193+ * or maybe it is always necessary, then yeah, should handle early.
194+ *
195+ * probably a good spot would be in the `branchSequencer`,
196+ * just not in an individual "checkout",
197+ * but rather - before any checkouts take place --
198+ * by doing the pre-checking logic if branches exists
199+ * before doing the checkouts.
200+ *
201+ */
202+ targetBranch = targetBranch . replace ( / r e f s \/ r e m o t e s \/ [ ^ / ] + \/ / , "" ) ;
203+ }
204+
154205 // console.log({ targetCommitSHA, target: targetBranch });
155206
156207 /**
0 commit comments