Skip to content

Commit 33e5f8f

Browse files
authored
Merge pull request #2694 from stefanhaller/conflict-handling-menu
Show menu instead of prompt when there are conflicts in a rebase or merge
2 parents 523be47 + 16dceb8 commit 33e5f8f

File tree

11 files changed

+131
-21
lines changed

11 files changed

+131
-21
lines changed

pkg/gui/controllers/helpers/merge_and_rebase_helper.go

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -138,15 +138,26 @@ func (self *MergeAndRebaseHelper) CheckMergeOrRebase(result error) error {
138138
// assume in this case that we're already done
139139
return nil
140140
} else if isMergeConflictErr(result.Error()) {
141-
return self.c.Confirm(types.ConfirmOpts{
142-
Title: self.c.Tr.FoundConflictsTitle,
143-
Prompt: self.c.Tr.FoundConflicts,
144-
HandleConfirm: func() error {
145-
return self.c.PushContext(self.c.Contexts().Files)
146-
},
147-
HandleClose: func() error {
148-
return self.genericMergeCommand(REBASE_OPTION_ABORT)
141+
mode := self.workingTreeStateNoun()
142+
return self.c.Menu(types.CreateMenuOptions{
143+
Title: self.c.Tr.FoundConflictsTitle,
144+
Items: []*types.MenuItem{
145+
{
146+
Label: self.c.Tr.ViewConflictsMenuItem,
147+
OnPress: func() error {
148+
return self.c.PushContext(self.c.Contexts().Files)
149+
},
150+
Key: 'v',
151+
},
152+
{
153+
Label: fmt.Sprintf(self.c.Tr.AbortMenuItem, mode),
154+
OnPress: func() error {
155+
return self.genericMergeCommand(REBASE_OPTION_ABORT)
156+
},
157+
Key: 'a',
158+
},
149159
},
160+
HideCancel: true,
150161
})
151162
} else {
152163
return self.c.ErrorMsg(result.Error())

pkg/i18n/chinese.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,6 @@ func chineseTranslationSet() TranslationSet {
175175
ReturnToFilesPanel: `返回文件面板`,
176176
FastForward: `从上游快进此分支`,
177177
Fetching: "抓取并快进 {{.from}} -> {{.to}} ...",
178-
FoundConflicts: "冲突!需要中止操作请按‘esc’, 否则按‘enter’",
179178
FoundConflictsTitle: "自动合并失败",
180179
ViewMergeRebaseOptions: "查看 合并/变基 选项",
181180
NotMergingOrRebasing: "您目前既不进行变基也不进行合并",

pkg/i18n/dutch.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -140,8 +140,7 @@ func dutchTranslationSet() TranslationSet {
140140
ReturnToFilesPanel: `Ga terug naar het bestanden paneel`,
141141
FastForward: `Fast-forward deze branch vanaf zijn upstream`,
142142
Fetching: "Fetching en fast-forwarding {{.from}} -> {{.to}} ...",
143-
FoundConflicts: "Conflicten!, Om af te breken druk 'esc', anders druk op 'enter'",
144-
FoundConflictsTitle: "Auto-merge mislukt",
143+
FoundConflictsTitle: "Conflicten!",
145144
ViewMergeRebaseOptions: "Bekijk merge/rebase opties",
146145
NotMergingOrRebasing: "Je bent momenteel niet aan het rebasen of mergen",
147146
RecentRepos: "Recente repositories",

pkg/i18n/english.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -181,8 +181,9 @@ type TranslationSet struct {
181181
ReturnToFilesPanel string
182182
FastForward string
183183
Fetching string
184-
FoundConflicts string
185184
FoundConflictsTitle string
185+
ViewConflictsMenuItem string
186+
AbortMenuItem string
186187
PickHunk string
187188
PickAllHunks string
188189
ViewMergeRebaseOptions string
@@ -867,8 +868,9 @@ func EnglishTranslationSet() TranslationSet {
867868
ReturnToFilesPanel: `Return to files panel`,
868869
FastForward: `Fast-forward this branch from its upstream`,
869870
Fetching: "Fetching and fast-forwarding {{.from}} -> {{.to}} ...",
870-
FoundConflicts: "Conflicts! To abort press 'esc', otherwise press 'enter'",
871-
FoundConflictsTitle: "Auto-merge failed",
871+
FoundConflictsTitle: "Conflicts!",
872+
ViewConflictsMenuItem: "View conflicts",
873+
AbortMenuItem: "Abort the %s",
872874
ViewMergeRebaseOptions: "View merge/rebase options",
873875
NotMergingOrRebasing: "You are currently neither rebasing nor merging",
874876
AlreadyRebasing: "Can't perform this action during a rebase",

pkg/i18n/korean.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,6 @@ func koreanTranslationSet() TranslationSet {
176176
ReturnToFilesPanel: `파일 목록으로 돌아가기`,
177177
FastForward: `Fast-forward this branch from its upstream`,
178178
Fetching: "Fetching and fast-forwarding {{.from}} -> {{.to}} ...",
179-
FoundConflicts: "Conflicts! To abort press 'esc', otherwise press 'enter'",
180179
FoundConflictsTitle: "Auto-merge failed",
181180
ViewMergeRebaseOptions: "View merge/rebase options",
182181
NotMergingOrRebasing: "You are currently neither rebasing nor merging",

pkg/i18n/polish.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,8 +125,7 @@ func polishTranslationSet() TranslationSet {
125125
MoveUpCommit: "Przenieś commit 1 w górę",
126126
EditCommit: "Edytuj commit",
127127
AmendToCommit: "Popraw commit zmianami z poczekalni",
128-
FoundConflicts: "Konflikty! Wciśnij 'esc' żeby przerwać, w przeciwnym razie wciśnij 'enter'",
129-
FoundConflictsTitle: "Automatyczne scalenie nie powiodło się",
128+
FoundConflictsTitle: "Konflikty!",
130129
ViewMergeRebaseOptions: "Widok scalenia/opcje zmiany bazy",
131130
NotMergingOrRebasing: "W tej chwili nie scalasz ani nie zmieniasz bazy",
132131
RecentRepos: "Ostatnie repozytoria",

pkg/i18n/traditional_chinese.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,6 @@ func traditionalChineseTranslationSet() TranslationSet {
240240
ReturnToFilesPanel: `返回檔案面板`,
241241
FastForward: `從上游快進此分支`,
242242
Fetching: "{{.from}} -> {{.to}} 的擷取和快進中...",
243-
FoundConflicts: "衝突!按 'esc' 退出,否則按 'enter'",
244243
FoundConflictsTitle: "自動合併失敗",
245244
ViewMergeRebaseOptions: "查看合併/變基選項",
246245
NotMergingOrRebasing: "你當前既不在變基也不在合併中",

pkg/integration/components/common.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@ func (self *Common) ContinueRebase() {
1919
}
2020

2121
func (self *Common) AcknowledgeConflicts() {
22-
self.t.ExpectPopup().Confirmation().
23-
Title(Equals("Auto-merge failed")).
24-
Content(Contains("Conflicts!")).
22+
self.t.ExpectPopup().Menu().
23+
Title(Equals("Conflicts!")).
24+
Select(Contains("View conflicts")).
2525
Confirm()
2626
}
2727

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
package branch
2+
3+
import (
4+
"github.com/jesseduffield/lazygit/pkg/config"
5+
. "github.com/jesseduffield/lazygit/pkg/integration/components"
6+
"github.com/jesseduffield/lazygit/pkg/integration/tests/shared"
7+
)
8+
9+
var RebaseAbortOnConflict = NewIntegrationTest(NewIntegrationTestArgs{
10+
Description: "Rebase onto another branch, abort when there are conflicts.",
11+
ExtraCmdArgs: []string{},
12+
Skip: false,
13+
SetupConfig: func(config *config.AppConfig) {},
14+
SetupRepo: func(shell *Shell) {
15+
shared.MergeConflictsSetup(shell)
16+
},
17+
Run: func(t *TestDriver, keys config.KeybindingConfig) {
18+
t.Views().Commits().TopLines(
19+
Contains("first change"),
20+
Contains("original"),
21+
)
22+
23+
t.Views().Branches().
24+
Focus().
25+
Lines(
26+
Contains("first-change-branch"),
27+
Contains("second-change-branch"),
28+
Contains("original-branch"),
29+
).
30+
SelectNextItem().
31+
Press(keys.Branches.RebaseBranch)
32+
33+
t.ExpectPopup().Menu().
34+
Title(Equals("Rebase 'first-change-branch' onto 'second-change-branch'")).
35+
Select(Contains("Simple rebase")).
36+
Confirm()
37+
38+
t.ExpectPopup().Menu().
39+
Title(Equals("Conflicts!")).
40+
Select(Contains("Abort the rebase")).
41+
Confirm()
42+
43+
t.Views().Branches().
44+
IsFocused()
45+
46+
t.Views().Files().
47+
IsEmpty()
48+
},
49+
})
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
package branch
2+
3+
import (
4+
"github.com/jesseduffield/lazygit/pkg/config"
5+
. "github.com/jesseduffield/lazygit/pkg/integration/components"
6+
"github.com/jesseduffield/lazygit/pkg/integration/tests/shared"
7+
)
8+
9+
var RebaseCancelOnConflict = NewIntegrationTest(NewIntegrationTestArgs{
10+
Description: "Rebase onto another branch, cancel when there are conflicts.",
11+
ExtraCmdArgs: []string{},
12+
Skip: false,
13+
SetupConfig: func(config *config.AppConfig) {},
14+
SetupRepo: func(shell *Shell) {
15+
shared.MergeConflictsSetup(shell)
16+
},
17+
Run: func(t *TestDriver, keys config.KeybindingConfig) {
18+
t.Views().Commits().TopLines(
19+
Contains("first change"),
20+
Contains("original"),
21+
)
22+
23+
t.Views().Branches().
24+
Focus().
25+
Lines(
26+
Contains("first-change-branch"),
27+
Contains("second-change-branch"),
28+
Contains("original-branch"),
29+
).
30+
SelectNextItem().
31+
Press(keys.Branches.RebaseBranch)
32+
33+
t.ExpectPopup().Menu().
34+
Title(Equals("Rebase 'first-change-branch' onto 'second-change-branch'")).
35+
Select(Contains("Simple rebase")).
36+
Confirm()
37+
38+
t.ExpectPopup().Menu().
39+
Title(Equals("Conflicts!")).
40+
Select(Contains("Abort the rebase")).
41+
Cancel()
42+
43+
t.Views().Branches().
44+
IsFocused()
45+
46+
t.Views().Files().
47+
Lines(
48+
Contains("UU file"),
49+
)
50+
},
51+
})

0 commit comments

Comments
 (0)