mirror of
https://github.com/jesseduffield/lazygit.git
synced 2025-05-13 22:17:05 +02:00
Ask to force push if server rejected the update, if remote not stored locally
This broke with 81b497d186 (#3387). In that PR I claimed that we never want to ask for force-pushing if the server rejected the update, on the assumption that this can only happen because the remote tracking branch is not up to date, and users should just fetch in this case. However, I didn't realize it's even possible to have a branch whose upstream branch is not stored locally; in this case we can't tell ahead of time whether a force push is going to be necessary, so we _have_ to rely on the server response to find out. But we only want to do that in this specific case, so this is not quite an exact revert of 81b497d186.
This commit is contained in:
parent
993d66a8ff
commit
aac2535104
@ -89,7 +89,7 @@ func (self *SyncController) branchCheckedOut(f func(*models.Branch) error) func(
|
||||
func (self *SyncController) push(currentBranch *models.Branch) error {
|
||||
// if we are behind our upstream branch we'll ask if the user wants to force push
|
||||
if currentBranch.IsTrackingRemote() {
|
||||
opts := pushOpts{}
|
||||
opts := pushOpts{remoteBranchStoredLocally: currentBranch.RemoteBranchStoredLocally()}
|
||||
if currentBranch.IsBehindForPush() {
|
||||
return self.requestToForcePush(currentBranch, opts)
|
||||
} else {
|
||||
@ -183,6 +183,12 @@ type pushOpts struct {
|
||||
upstreamRemote string
|
||||
upstreamBranch string
|
||||
setUpstream bool
|
||||
|
||||
// If this is false, we can't tell ahead of time whether a force-push will
|
||||
// be necessary, so we start with a normal push and offer to force-push if
|
||||
// the server rejected. If this is true, we don't offer to force-push if the
|
||||
// server rejected, but rather ask the user to fetch.
|
||||
remoteBranchStoredLocally bool
|
||||
}
|
||||
|
||||
func (self *SyncController) pushAux(currentBranch *models.Branch, opts pushOpts) error {
|
||||
@ -197,9 +203,27 @@ func (self *SyncController) pushAux(currentBranch *models.Branch, opts pushOpts)
|
||||
SetUpstream: opts.setUpstream,
|
||||
})
|
||||
if err != nil {
|
||||
if strings.Contains(err.Error(), "Updates were rejected") {
|
||||
if !opts.force && strings.Contains(err.Error(), "Updates were rejected") {
|
||||
if opts.remoteBranchStoredLocally {
|
||||
return errors.New(self.c.Tr.UpdatesRejected)
|
||||
}
|
||||
|
||||
forcePushDisabled := self.c.UserConfig.Git.DisableForcePushing
|
||||
if forcePushDisabled {
|
||||
return errors.New(self.c.Tr.UpdatesRejectedAndForcePushDisabled)
|
||||
}
|
||||
_ = 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
|
||||
}
|
||||
return err
|
||||
}
|
||||
return self.c.Refresh(types.RefreshOptions{Mode: types.ASYNC})
|
||||
|
@ -132,6 +132,7 @@ func chineseTranslationSet() TranslationSet {
|
||||
ForcePush: "强制推送",
|
||||
ForcePushPrompt: "您的分支已与远程分支不同。按‘esc’取消,或‘enter’强制推送.",
|
||||
ForcePushDisabled: "您的分支已与远程分支不同, 并且您已经禁用了强行推送",
|
||||
UpdatesRejectedAndForcePushDisabled: "更新被拒绝,您已禁用强制推送",
|
||||
CheckForUpdate: "检查更新",
|
||||
CheckingForUpdates: "正在检查更新…",
|
||||
OnLatestVersionErr: "已是最新版本",
|
||||
|
@ -198,6 +198,7 @@ type TranslationSet struct {
|
||||
ForcePushPrompt string
|
||||
ForcePushDisabled string
|
||||
UpdatesRejected string
|
||||
UpdatesRejectedAndForcePushDisabled string
|
||||
CheckForUpdate string
|
||||
CheckingForUpdates string
|
||||
UpdateAvailableTitle string
|
||||
@ -1160,6 +1161,7 @@ func EnglishTranslationSet() TranslationSet {
|
||||
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",
|
||||
UpdatesRejected: "Updates were rejected. Please fetch and examine the remote changes before pushing again.",
|
||||
UpdatesRejectedAndForcePushDisabled: "Updates were rejected and you have disabled force pushing",
|
||||
CheckForUpdate: "Check for update",
|
||||
CheckingForUpdates: "Checking for updates...",
|
||||
UpdateAvailableTitle: "Update available!",
|
||||
|
@ -124,6 +124,7 @@ func koreanTranslationSet() TranslationSet {
|
||||
ForcePush: "강제 푸시",
|
||||
ForcePushPrompt: "브랜치가 원격 브랜치에서 분기하고 있습니다. 'esc'를 눌러 취소하거나, 'enter'를 눌러 강제로 푸시하세요.",
|
||||
ForcePushDisabled: "브랜치가 원격 브랜치에서 분기하고 있습니다. force push가 비활성화 되었습니다.",
|
||||
UpdatesRejectedAndForcePushDisabled: "업데이트가 거부되었으며 강제 푸시를 비활성화했습니다.",
|
||||
CheckForUpdate: "업데이트 확인",
|
||||
CheckingForUpdates: "업데이트 확인 중...",
|
||||
UpdateAvailableTitle: "새로운 업데이트 사용가능!",
|
||||
|
@ -183,6 +183,7 @@ func polishTranslationSet() TranslationSet {
|
||||
ForcePush: "Wymuś wysłanie",
|
||||
ForcePushPrompt: "Twoja gałąź rozbiegła się z gałęzią zdalną. Naciśnij {{.cancelKey}}, aby anulować, lub {{.confirmKey}}, aby wymusić wysłanie.",
|
||||
ForcePushDisabled: "Twoja gałąź rozbiegła się z gałęzią zdalną i masz wyłączone wymuszanie wysyłania",
|
||||
UpdatesRejectedAndForcePushDisabled: "Aktualizacje zostały odrzucone i wyłączyłeś wymuszenie wysłania",
|
||||
CheckForUpdate: "Sprawdź aktualizacje",
|
||||
CheckingForUpdates: "Sprawdzanie aktualizacji...",
|
||||
UpdateAvailableTitle: "Dostępna aktualizacja!",
|
||||
|
@ -152,6 +152,7 @@ func RussianTranslationSet() TranslationSet {
|
||||
ForcePush: "Принудительная отправка изменении",
|
||||
ForcePushPrompt: "Ветка отклонилась от удалённой ветки. Нажмите «esc», чтобы отменить, или «enter», чтобы начать принудительную отправку изменении.",
|
||||
ForcePushDisabled: "Ветка отклонилась от удалённой ветки. Принудительная отправка изменении была отключена",
|
||||
UpdatesRejectedAndForcePushDisabled: "Обновления были отклонены. Принудительная отправка изменении была отключена",
|
||||
CheckForUpdate: "Проверить обновления",
|
||||
CheckingForUpdates: "Проверка обновлений...",
|
||||
UpdateAvailableTitle: "Доступно обновление!",
|
||||
|
@ -184,6 +184,7 @@ func traditionalChineseTranslationSet() TranslationSet {
|
||||
ForcePush: "強制推送",
|
||||
ForcePushPrompt: "你的分支與遠端分支分岔。按 'ESC' 取消,或按 'Enter' 強制推送。",
|
||||
ForcePushDisabled: "你的分支與遠端分支分岔,你已禁用強制推送",
|
||||
UpdatesRejectedAndForcePushDisabled: "更新被拒絕,你已禁用強制推送",
|
||||
CheckForUpdate: "檢查更新",
|
||||
CheckingForUpdates: "正在檢查更新...",
|
||||
UpdateAvailableTitle: "有可用的更新!",
|
||||
|
Loading…
x
Reference in New Issue
Block a user