From e8db27b0b32b7f7f9ecd98bf1af6023dae2b234d Mon Sep 17 00:00:00 2001 From: Stefan Haller Date: Wed, 20 Mar 2024 08:52:21 +0100 Subject: [PATCH] When creating a new remote, select it and fetch it I'm doing these two things every time I add a new remote, in 100% of the cases, so do them automatically for me. --- pkg/gui/controllers/remotes_controller.go | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/pkg/gui/controllers/remotes_controller.go b/pkg/gui/controllers/remotes_controller.go index 37c1273ed..f15bc1146 100644 --- a/pkg/gui/controllers/remotes_controller.go +++ b/pkg/gui/controllers/remotes_controller.go @@ -145,7 +145,27 @@ func (self *RemotesController) add() error { if err := self.c.Git().Remote.AddRemote(remoteName, remoteUrl); err != nil { return err } - return self.c.Refresh(types.RefreshOptions{Scope: []types.RefreshableView{types.REMOTES}}) + + // Do a sync refresh of the remotes so that we can select + // the new one. Loading remotes is not expensive, so we can + // afford it. + if err := self.c.Refresh(types.RefreshOptions{ + Scope: []types.RefreshableView{types.REMOTES}, + Mode: types.SYNC, + }); err != nil { + return err + } + + // Select the new remote + for idx, remote := range self.c.Model().Remotes { + if remote.Name == remoteName { + self.c.Contexts().Remotes.SetSelection(idx) + break + } + } + + // Fetch the new remote + return self.fetch(self.c.Contexts().Remotes.GetSelected()) }, }) },