1
0
mirror of https://github.com/jesseduffield/lazygit.git synced 2025-04-17 12:06:38 +02:00

When adding a new remote, select it and fetch it (#3401)

- **PR Description**

I'm doing these two things every time I add a new remote, in 100% of the
cases, so do them automatically for me.
This commit is contained in:
Stefan Haller 2024-03-22 08:19:45 +01:00 committed by GitHub
commit 9b5269b490
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -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())
},
})
},