Skip to content

Commit d74c08d

Browse files
committed
feat: specify branch to check out from the fork via username:branch
1 parent 4859780 commit d74c08d

File tree

11 files changed

+31
-17
lines changed

11 files changed

+31
-17
lines changed

docs/keybindings/Keybindings_en.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -308,7 +308,7 @@ _Legend: `<c-b>` means ctrl+b, `<a-b>` means alt+b, `B` means shift+b_
308308
| `` n `` | New remote | |
309309
| `` d `` | Remove | Remove the selected remote. Any local branches tracking a remote branch from the remote will be unaffected. |
310310
| `` e `` | Edit | Edit the selected remote's name or URL. |
311-
| `` F `` | Add fork remote | Quickly add a fork remote by replacing the owner in the origin URL. |
311+
| `` F `` | Add fork remote | Quickly add a fork remote by replacing the owner in the origin URL and optionally check out a branch from new remote. |
312312
| `` f `` | Fetch | Fetch updates from the remote repository. This retrieves new commits and branches without merging them into your local branches. |
313313
| `` / `` | Filter the current view by text | |
314314

docs/keybindings/Keybindings_ja.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -334,7 +334,7 @@ _凡例:`<c-b>` はctrl+b、`<a-b>` はalt+b、`B` はshift+bを意味
334334
| `` n `` | 新しいリモート | |
335335
| `` d `` | 削除 | 選択したリモートを削除します。そのリモートからのリモートブランチを追跡しているローカルブランチは影響を受けません。 |
336336
| `` e `` | 編集 | 選択したリモートの名前またはURLを編集します。 |
337-
| `` F `` | Add fork remote | Quickly add a fork remote by replacing the owner in the origin URL. |
337+
| `` F `` | Add fork remote | Quickly add a fork remote by replacing the owner in the origin URL and optionally check out a branch from new remote. |
338338
| `` f `` | フェッチ | リモートリポジトリから更新をフェッチします。これにより、ローカルブランチにマージせずに新しいコミットとブランチを取得します。 |
339339
| `` / `` | 現在のビューをテキストでフィルタリング | |
340340

docs/keybindings/Keybindings_ko.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,7 @@ _Legend: `<c-b>` means ctrl+b, `<a-b>` means alt+b, `B` means shift+b_
258258
| `` n `` | 새로운 Remote 추가 | |
259259
| `` d `` | Remove | Remove the selected remote. Any local branches tracking a remote branch from the remote will be unaffected. |
260260
| `` e `` | Edit | Remote를 수정 |
261-
| `` F `` | Add fork remote | Quickly add a fork remote by replacing the owner in the origin URL. |
261+
| `` F `` | Add fork remote | Quickly add a fork remote by replacing the owner in the origin URL and optionally check out a branch from new remote. |
262262
| `` f `` | Fetch | 원격을 업데이트 |
263263
| `` / `` | Filter the current view by text | |
264264

docs/keybindings/Keybindings_nl.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,7 @@ _Legend: `<c-b>` means ctrl+b, `<a-b>` means alt+b, `B` means shift+b_
286286
| `` n `` | Voeg een nieuwe remote toe | |
287287
| `` d `` | Remove | Remove the selected remote. Any local branches tracking a remote branch from the remote will be unaffected. |
288288
| `` e `` | Edit | Wijzig remote |
289-
| `` F `` | Add fork remote | Quickly add a fork remote by replacing the owner in the origin URL. |
289+
| `` F `` | Add fork remote | Quickly add a fork remote by replacing the owner in the origin URL and optionally check out a branch from new remote. |
290290
| `` f `` | Fetch | Fetch remote |
291291
| `` / `` | Filter the current view by text | |
292292

docs/keybindings/Keybindings_pl.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -382,7 +382,7 @@ _Legenda: `<c-b>` oznacza ctrl+b, `<a-b>` oznacza alt+b, `B` oznacza shift+b_
382382
| `` n `` | Nowy zdalny | |
383383
| `` d `` | Usuń | Usuń wybrany zdalny. Wszelkie lokalne gałęzie śledzące gałąź zdalną z tego zdalnego nie zostaną dotknięte. |
384384
| `` e `` | Edytuj | Edytuj nazwę lub URL wybranego zdalnego. |
385-
| `` F `` | Add fork remote | Quickly add a fork remote by replacing the owner in the origin URL. |
385+
| `` F `` | Add fork remote | Quickly add a fork remote by replacing the owner in the origin URL and optionally check out a branch from new remote. |
386386
| `` f `` | Pobierz | Pobierz aktualizacje z zdalnego repozytorium. Pobiera nowe commity i gałęzie bez scalania ich z lokalnymi gałęziami. |
387387
| `` / `` | Filtruj bieżący widok po tekście | |
388388

docs/keybindings/Keybindings_pt.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -317,7 +317,7 @@ _Legend: `<c-b>` means ctrl+b, `<a-b>` means alt+b, `B` means shift+b_
317317
| `` n `` | Novo controle | |
318318
| `` d `` | Remover | Remover o controle remoto. Quaisquer ramificações locais de rastreamento de um ramo remoto do controle não serão afetadas. |
319319
| `` e `` | Editar | Edit the selected remote's name or URL. |
320-
| `` F `` | Add fork remote | Quickly add a fork remote by replacing the owner in the origin URL. |
320+
| `` F `` | Add fork remote | Quickly add a fork remote by replacing the owner in the origin URL and optionally check out a branch from new remote. |
321321
| `` f `` | Buscar | Fetch updates from the remote repository. This retrieves new commits and branches without merging them into your local branches. |
322322
| `` / `` | Filter the current view by text | |
323323

docs/keybindings/Keybindings_ru.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -354,7 +354,7 @@ _Связки клавиш_
354354
| `` n `` | Добавить новую удалённую ветку | |
355355
| `` d `` | Remove | Remove the selected remote. Any local branches tracking a remote branch from the remote will be unaffected. |
356356
| `` e `` | Edit | Редактировать удалённый репозитории |
357-
| `` F `` | Add fork remote | Quickly add a fork remote by replacing the owner in the origin URL. |
357+
| `` F `` | Add fork remote | Quickly add a fork remote by replacing the owner in the origin URL and optionally check out a branch from new remote. |
358358
| `` f `` | Получить изменения | Получение изменения из удалённого репозитория |
359359
| `` / `` | Filter the current view by text | |
360360

docs/keybindings/Keybindings_zh-CN.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -382,7 +382,7 @@ _图例:`<c-b>` 意味着ctrl+b, `<a-b>意味着Alt+b, `B` 意味着shift+b_
382382
| `` n `` | 添加新的远程仓库 | |
383383
| `` d `` | 删除 | 删除选中的远程。从远程跟踪远程分支的任何本地分支都不会受到影响。 |
384384
| `` e `` | 编辑 | 编辑远程仓库 |
385-
| `` F `` | Add fork remote | Quickly add a fork remote by replacing the owner in the origin URL. |
385+
| `` F `` | Add fork remote | Quickly add a fork remote by replacing the owner in the origin URL and optionally check out a branch from new remote. |
386386
| `` f `` | 抓取 | 抓取远程仓库 |
387387
| `` / `` | 通过文本过滤当前视图 | |
388388

docs/keybindings/Keybindings_zh-TW.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -382,7 +382,7 @@ _說明:`<c-b>` 表示 Ctrl+B、`<a-b>` 表示 Alt+B,`B`表示 Shift+B
382382
| `` n `` | 新增遠端 | |
383383
| `` d `` | Remove | Remove the selected remote. Any local branches tracking a remote branch from the remote will be unaffected. |
384384
| `` e `` | 編輯 | 編輯遠端 |
385-
| `` F `` | Add fork remote | Quickly add a fork remote by replacing the owner in the origin URL. |
385+
| `` F `` | Add fork remote | Quickly add a fork remote by replacing the owner in the origin URL and optionally check out a branch from new remote. |
386386
| `` f `` | 擷取 | 擷取遠端 |
387387
| `` / `` | 搜尋 | |
388388

pkg/gui/controllers/remotes_controller.go

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ func (self *RemotesController) enter(remote *models.Remote) error {
142142
return nil
143143
}
144144

145-
func (self *RemotesController) addRemoteHelper(remoteName string, remoteUrl string) error {
145+
func (self *RemotesController) addRemoteHelper(remoteName string, remoteUrl string, branchToCheckout string) error {
146146
self.c.LogAction(self.c.Tr.Actions.AddRemote)
147147
if err := self.c.Git().Remote.AddRemote(remoteName, remoteUrl); err != nil {
148148
return err
@@ -165,7 +165,7 @@ func (self *RemotesController) addRemoteHelper(remoteName string, remoteUrl stri
165165
}
166166

167167
// Fetch the new remote
168-
return self.fetch(self.c.Contexts().Remotes.GetSelected())
168+
return self.fetchAndCheckout(self.c.Contexts().Remotes.GetSelected(), branchToCheckout)
169169
}
170170

171171
func (self *RemotesController) add() error {
@@ -175,7 +175,7 @@ func (self *RemotesController) add() error {
175175
self.c.Prompt(types.PromptOpts{
176176
Title: self.c.Tr.NewRemoteUrl,
177177
HandleConfirm: func(remoteUrl string) error {
178-
return self.addRemoteHelper(remoteName, remoteUrl)
178+
return self.addRemoteHelper(remoteName, remoteUrl, "")
179179
},
180180
})
181181

@@ -223,6 +223,14 @@ func (self *RemotesController) addFork(baseRemote *models.Remote) error {
223223
self.c.Prompt(types.PromptOpts{
224224
Title: self.c.Tr.AddForkRemoteUsername,
225225
HandleConfirm: func(forkUsername string) error {
226+
branchToCheckout := ""
227+
228+
parts := strings.SplitN(forkUsername, ":", 2)
229+
if len(parts) == 2 {
230+
forkUsername = parts[0]
231+
branchToCheckout = parts[1]
232+
}
233+
226234
self.c.Prompt(types.PromptOpts{
227235
Title: self.c.Tr.NewRemoteName,
228236
InitialContent: forkUsername,
@@ -236,7 +244,7 @@ func (self *RemotesController) addFork(baseRemote *models.Remote) error {
236244
return err
237245
}
238246

239-
return self.addRemoteHelper(remoteName, remoteUrl)
247+
return self.addRemoteHelper(remoteName, remoteUrl, branchToCheckout)
240248
},
241249
})
242250

@@ -318,16 +326,22 @@ func (self *RemotesController) edit(remote *models.Remote) error {
318326
}
319327

320328
func (self *RemotesController) fetch(remote *models.Remote) error {
329+
return self.fetchAndCheckout(remote, "")
330+
}
331+
332+
func (self *RemotesController) fetchAndCheckout(remote *models.Remote, branchName string) error {
321333
return self.c.WithInlineStatus(remote, types.ItemOperationFetching, context.REMOTES_CONTEXT_KEY, func(task gocui.Task) error {
322334
err := self.c.Git().Sync.FetchRemote(task, remote.Name)
323335
if err != nil {
324336
return err
325337
}
326-
338+
if branchName != "" {
339+
err = self.c.Git().Branch.New(branchName, remote.Name+"/"+branchName)
340+
}
327341
self.c.Refresh(types.RefreshOptions{
328342
Scope: []types.RefreshableView{types.BRANCHES, types.REMOTES},
329343
Mode: types.ASYNC,
330344
})
331-
return nil
345+
return err
332346
})
333347
}

0 commit comments

Comments
 (0)