1
0
mirror of https://github.com/jesseduffield/lazygit.git synced 2025-01-22 05:29:44 +02:00

simplify fetch

This commit is contained in:
Jesse Duffield 2022-01-06 22:05:18 +11:00
parent 93729ba61b
commit 0d3e5e6a1d
3 changed files with 19 additions and 11 deletions

View File

@ -127,8 +127,9 @@ func (gui *Gui) handleGitFetch() error {
if err := gui.createLoaderPanel(gui.Tr.FetchWait); err != nil {
return err
}
go utils.Safe(func() {
err := gui.fetch(true, "Fetch")
err := gui.fetch()
gui.handleCredentialsPopup(err)
_ = gui.refreshSidePanels(refreshOptions{mode: ASYNC})
})

View File

@ -210,19 +210,15 @@ func (gui *Gui) handleMouseDownSecondary() error {
return nil
}
func (gui *Gui) fetch(canPromptForCredentials bool, action string) (err error) {
func (gui *Gui) fetch() (err error) {
gui.Mutexes.FetchMutex.Lock()
defer gui.Mutexes.FetchMutex.Unlock()
fetchOpts := commands.FetchOptions{}
if canPromptForCredentials {
gui.logAction(action)
fetchOpts.PromptUserForCredential = gui.promptUserForCredential
}
gui.logAction("Fetch")
err = gui.GitCommand.Fetch(fetchOpts)
err = gui.GitCommand.Fetch(commands.FetchOptions{PromptUserForCredential: gui.promptUserForCredential})
if canPromptForCredentials && err != nil && strings.Contains(err.Error(), "exit status 128") {
if err != nil && strings.Contains(err.Error(), "exit status 128") {
_ = gui.createErrorPanel(gui.Tr.PassUnameWrong)
}
@ -231,6 +227,17 @@ func (gui *Gui) fetch(canPromptForCredentials bool, action string) (err error) {
return err
}
func (gui *Gui) backgroundFetch() (err error) {
gui.Mutexes.FetchMutex.Lock()
defer gui.Mutexes.FetchMutex.Unlock()
err = gui.GitCommand.Fetch(commands.FetchOptions{})
_ = gui.refreshSidePanels(refreshOptions{scope: []RefreshableView{BRANCHES, COMMITS, REMOTES, TAGS}, mode: ASYNC})
return err
}
func (gui *Gui) handleCopySelectedSideContextItemToClipboard() error {
// important to note that this assumes we've selected an item in a side context
itemId := gui.getSideContextSelectedItemId()

View File

@ -718,7 +718,7 @@ func (gui *Gui) startBackgroundFetch() {
if !isNew {
time.After(time.Duration(userConfig.Refresher.FetchInterval) * time.Second)
}
err := gui.fetch(false, "")
err := gui.backgroundFetch()
if err != nil && strings.Contains(err.Error(), "exit status 128") && isNew {
_ = gui.ask(askOpts{
title: gui.Tr.NoAutomaticGitFetchTitle,
@ -726,7 +726,7 @@ func (gui *Gui) startBackgroundFetch() {
})
} else {
gui.goEvery(time.Second*time.Duration(userConfig.Refresher.FetchInterval), gui.stopChan, func() error {
err := gui.fetch(false, "")
err := gui.backgroundFetch()
gui.render()
return err
})