Skip to content

Commit 81b497d

Browse files
committed
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.
1 parent e9d050c commit 81b497d

File tree

8 files changed

+1887
-1908
lines changed

8 files changed

+1887
-1908
lines changed

pkg/gui/controllers/sync_controller.go

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -196,23 +196,8 @@ func (self *SyncController) pushAux(currentBranch *models.Branch, opts pushOpts)
196196
SetUpstream: opts.setUpstream,
197197
})
198198
if err != nil {
199-
if !opts.force && strings.Contains(err.Error(), "Updates were rejected") {
200-
forcePushDisabled := self.c.UserConfig.Git.DisableForcePushing
201-
if forcePushDisabled {
202-
_ = self.c.ErrorMsg(self.c.Tr.UpdatesRejectedAndForcePushDisabled)
203-
return nil
204-
}
205-
_ = self.c.Confirm(types.ConfirmOpts{
206-
Title: self.c.Tr.ForcePush,
207-
Prompt: self.forcePushPrompt(),
208-
HandleConfirm: func() error {
209-
newOpts := opts
210-
newOpts.force = true
211-
212-
return self.pushAux(currentBranch, newOpts)
213-
},
214-
})
215-
return nil
199+
if strings.Contains(err.Error(), "Updates were rejected") {
200+
return self.c.ErrorMsg(self.c.Tr.UpdatesRejected)
216201
}
217202
return err
218203
}

pkg/i18n/chinese.go

Lines changed: 318 additions & 319 deletions
Large diffs are not rendered by default.

pkg/i18n/dutch.go

Lines changed: 330 additions & 331 deletions
Large diffs are not rendered by default.

pkg/i18n/english.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ type TranslationSet struct {
192192
ForcePush string
193193
ForcePushPrompt string
194194
ForcePushDisabled string
195-
UpdatesRejectedAndForcePushDisabled string
195+
UpdatesRejected string
196196
CheckForUpdate string
197197
CheckingForUpdates string
198198
UpdateAvailableTitle string
@@ -1145,7 +1145,7 @@ func EnglishTranslationSet() TranslationSet {
11451145
ForcePush: "Force push",
11461146
ForcePushPrompt: "Your branch has diverged from the remote branch. Press {{.cancelKey}} to cancel, or {{.confirmKey}} to force push.",
11471147
ForcePushDisabled: "Your branch has diverged from the remote branch and you've disabled force pushing",
1148-
UpdatesRejectedAndForcePushDisabled: "Updates were rejected and you have disabled force pushing",
1148+
UpdatesRejected: "Updates were rejected. Please fetch and examine the remote changes before pushing again.",
11491149
CheckForUpdate: "Check for update",
11501150
CheckingForUpdates: "Checking for updates...",
11511151
UpdateAvailableTitle: "Update available!",

pkg/i18n/korean.go

Lines changed: 265 additions & 266 deletions
Large diffs are not rendered by default.

pkg/i18n/polish.go

Lines changed: 206 additions & 207 deletions
Large diffs are not rendered by default.

pkg/i18n/russian.go

Lines changed: 384 additions & 385 deletions
Large diffs are not rendered by default.

pkg/i18n/traditional_chinese.go

Lines changed: 380 additions & 381 deletions
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)