Don't ask to force-push if the remote rejected updates

Lazygit has two ways to decide whether it needs to ask the user to force-push:
1. if it knows ahead of time that the push will fail because the branch has
diverged, by looking at the incoming/outgoing information that it shows as ↑3↓7.
2. by examining the error that comes back when the push has failed.

The second situation should happen only rarely, because lazygit fetches every
minute by default, so the ↑3↓7 information is usually up to date. It might not
be if the user turned off auto-fetch (or increased the auto-fetch interval).
However, in this case it's almost always harmful to prompt the user to
force-push, because we know that the reason for diverging is that something was
pushed to the remote, and we would wipe it out by force-pushing. In such a
situation, the more likely user action is to pull the remote changes and then
push normally again.

So just remove the second prompt, and replace it by a better error message when
we detect that updates were rejected remotely.

A little bit of history archeology reveals that the second prompt was added at a
time where we didn't have the first one yet, so at that time it made sense to
have it; but when the first prompt was added, we should have removed the second.
This commit is contained in:
Stefan Haller 2024-03-15 18:19:35 +01:00
parent e9d050c5d5
commit 81b497d186
8 changed files with 1887 additions and 1908 deletions

View file

@ -196,23 +196,8 @@ func (self *SyncController) pushAux(currentBranch *models.Branch, opts pushOpts)
SetUpstream: opts.setUpstream,
})
if err != nil {
if !opts.force && strings.Contains(err.Error(), "Updates were rejected") {
forcePushDisabled := self.c.UserConfig.Git.DisableForcePushing
if forcePushDisabled {
_ = self.c.ErrorMsg(self.c.Tr.UpdatesRejectedAndForcePushDisabled)
return nil
}
_ = self.c.Confirm(types.ConfirmOpts{
Title: self.c.Tr.ForcePush,
Prompt: self.forcePushPrompt(),
HandleConfirm: func() error {
newOpts := opts
newOpts.force = true
return self.pushAux(currentBranch, newOpts)
},
})
return nil
if strings.Contains(err.Error(), "Updates were rejected") {
return self.c.ErrorMsg(self.c.Tr.UpdatesRejected)
}
return err
}

View file

@ -132,7 +132,6 @@ func chineseTranslationSet() TranslationSet {
ForcePush: "强制推送",
ForcePushPrompt: "您的分支已与远程分支不同。按esc取消enter强制推送.",
ForcePushDisabled: "您的分支已与远程分支不同, 并且您已经禁用了强行推送",
UpdatesRejectedAndForcePushDisabled: "更新被拒绝,您已禁用强制推送",
CheckForUpdate: "检查更新",
CheckingForUpdates: "正在检查更新…",
OnLatestVersionErr: "已是最新版本",

View file

@ -99,7 +99,6 @@ func dutchTranslationSet() TranslationSet {
ForcePush: "Forceer push",
ForcePushPrompt: "Jouw branch is afgeweken van de remote branch. Druk 'esc' om te annuleren, of 'enter' om geforceert te pushen.",
ForcePushDisabled: "Your branch has diverged from the remote branch and you've disabled force pushing",
UpdatesRejectedAndForcePushDisabled: "Updates were rejected and you have disabled force pushing",
CheckForUpdate: "Check voor updates",
CheckingForUpdates: "Zoeken naar updates...",
OnLatestVersionErr: "Je hebt al de laatste versie",

View file

@ -192,7 +192,7 @@ type TranslationSet struct {
ForcePush string
ForcePushPrompt string
ForcePushDisabled string
UpdatesRejectedAndForcePushDisabled string
UpdatesRejected string
CheckForUpdate string
CheckingForUpdates string
UpdateAvailableTitle string
@ -1145,7 +1145,7 @@ func EnglishTranslationSet() TranslationSet {
ForcePush: "Force push",
ForcePushPrompt: "Your branch has diverged from the remote branch. Press {{.cancelKey}} to cancel, or {{.confirmKey}} to force push.",
ForcePushDisabled: "Your branch has diverged from the remote branch and you've disabled force pushing",
UpdatesRejectedAndForcePushDisabled: "Updates were rejected and you have disabled force pushing",
UpdatesRejected: "Updates were rejected. Please fetch and examine the remote changes before pushing again.",
CheckForUpdate: "Check for update",
CheckingForUpdates: "Checking for updates...",
UpdateAvailableTitle: "Update available!",

View file

@ -124,7 +124,6 @@ func koreanTranslationSet() TranslationSet {
ForcePush: "강제 푸시",
ForcePushPrompt: "브랜치가 원격 브랜치에서 분기하고 있습니다. 'esc'를 눌러 취소하거나, 'enter'를 눌러 강제로 푸시하세요.",
ForcePushDisabled: "브랜치가 원격 브랜치에서 분기하고 있습니다. force push가 비활성화 되었습니다.",
UpdatesRejectedAndForcePushDisabled: "업데이트가 거부되었으며 강제 푸시를 비활성화했습니다.",
CheckForUpdate: "업데이트 확인",
CheckingForUpdates: "업데이트 확인 중...",
UpdateAvailableTitle: "새로운 업데이트 사용가능!",

View file

@ -77,7 +77,6 @@ func polishTranslationSet() TranslationSet {
ForcePush: "Wymuś wysłanie",
ForcePushPrompt: "Twoja gałąź rozeszła się z gałęzią zdalną. Wciśnij 'esc' aby anulować lub 'enter' aby wymusić wysłanie.",
ForcePushDisabled: "Twoja gałąź rozeszła się z gałęzią zdalną i wyłączyłeś wymuszenie wysłania",
UpdatesRejectedAndForcePushDisabled: "Aktualizacje zostały odrzucone i wyłączyłeś wymuszenie wysłania",
CheckForUpdate: "Sprawdź aktualizacje",
CheckingForUpdates: "Sprawdzanie aktualizacji...",
OnLatestVersionErr: "Już posiadasz najnowszą wersję",

View file

@ -152,7 +152,6 @@ func RussianTranslationSet() TranslationSet {
ForcePush: "Принудительная отправка изменении",
ForcePushPrompt: "Ветка отклонилась от удалённой ветки. Нажмите «esc», чтобы отменить, или «enter», чтобы начать принудительную отправку изменении.",
ForcePushDisabled: "Ветка отклонилась от удалённой ветки. Принудительная отправка изменении была отключена",
UpdatesRejectedAndForcePushDisabled: "Обновления были отклонены. Принудительная отправка изменении была отключена",
CheckForUpdate: "Проверить обновления",
CheckingForUpdates: "Проверка обновлений...",
UpdateAvailableTitle: "Доступно обновление!",

View file

@ -185,7 +185,6 @@ func traditionalChineseTranslationSet() TranslationSet {
ForcePush: "強制推送",
ForcePushPrompt: "你的分支與遠端分支分岔。按 'ESC' 取消,或按 'Enter' 強制推送。",
ForcePushDisabled: "你的分支與遠端分支分岔,你已禁用強制推送",
UpdatesRejectedAndForcePushDisabled: "更新被拒絕,你已禁用強制推送",
CheckForUpdate: "檢查更新",
CheckingForUpdates: "正在檢查更新...",
UpdateAvailableTitle: "有可用的更新!",