Skip to content

Commit 2e1be45

Browse files
committed
Better main view display for conflicing files
For the less common conflict types DD, AU, UA, DU, and UD, we would previously only show "* Unmerged path" in the main view, which isn't helpful. Also, for some of these we would split the main view and show this text both in the unstaged changes and staged changes views, which is a bit embarrassing. Improve this by offering more explanation about what's going on, and what the most likely way to resolve the situation is for each case.
1 parent a09ca59 commit 2e1be45

File tree

3 files changed

+65
-0
lines changed

3 files changed

+65
-0
lines changed

pkg/commands/models/file.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package models
22

33
import (
4+
"github.com/jesseduffield/lazygit/pkg/i18n"
45
"github.com/jesseduffield/lazygit/pkg/utils"
56
"github.com/samber/lo"
67
)
@@ -101,6 +102,22 @@ func (f *File) GetIsFile() bool {
101102
return true
102103
}
103104

105+
func (f *File) GetMergeStateDescription(tr *i18n.TranslationSet) string {
106+
m := map[string]string{
107+
"DD": tr.MergeConflictDescription_DD,
108+
"AU": tr.MergeConflictDescription_AU,
109+
"UA": tr.MergeConflictDescription_UA,
110+
"DU": tr.MergeConflictDescription_DU,
111+
"UD": tr.MergeConflictDescription_UD,
112+
}
113+
114+
if description, ok := m[f.ShortStatus]; ok {
115+
return description
116+
}
117+
118+
panic("should only be called if there's a merge conflict")
119+
}
120+
104121
type StatusFields struct {
105122
HasStagedChanges bool
106123
HasUnstagedChanges bool

pkg/gui/controllers/files_controller.go

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -268,6 +268,38 @@ func (self *FilesController) GetOnRenderToMain() func() {
268268
self.c.Helpers().MergeConflicts.Render()
269269
return
270270
}
271+
} else if node.File != nil && node.File.HasMergeConflicts {
272+
opts := types.RefreshMainOpts{
273+
Pair: self.c.MainViewPairs().Normal,
274+
Main: &types.ViewUpdateOpts{
275+
Title: self.c.Tr.DiffTitle,
276+
SubTitle: self.c.Helpers().Diff.IgnoringWhitespaceSubTitle(),
277+
},
278+
}
279+
message := node.File.GetMergeStateDescription(self.c.Tr)
280+
message += "\n\n" + fmt.Sprintf(self.c.Tr.MergeConflictPressEnterToResolve,
281+
self.c.UserConfig().Keybinding.Universal.GoInto)
282+
if self.c.Views().Main.InnerWidth() > 70 {
283+
// If the main view is very wide, wrap the message to increase readability
284+
lines, _, _ := utils.WrapViewLinesToWidth(true, false, message, 70, 4)
285+
message = strings.Join(lines, "\n")
286+
}
287+
if node.File.ShortStatus == "DU" || node.File.ShortStatus == "UD" {
288+
cmdObj := self.c.Git().Diff.DiffCmdObj([]string{"--base", "--", node.GetPath()})
289+
task := types.NewRunPtyTask(cmdObj.GetCmd())
290+
task.Prefix = message + "\n\n"
291+
if node.File.ShortStatus == "DU" {
292+
task.Prefix += self.c.Tr.MergeConflictIncomingDiff
293+
} else {
294+
task.Prefix += self.c.Tr.MergeConflictCurrentDiff
295+
}
296+
task.Prefix += "\n\n"
297+
opts.Main.Task = task
298+
} else {
299+
opts.Main.Task = types.NewRenderStringTask(message)
300+
}
301+
self.c.RenderToMainViews(opts)
302+
return
271303
}
272304

273305
self.c.Helpers().MergeConflicts.ResetMergeState()

pkg/i18n/english.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,14 @@ type TranslationSet struct {
9999
FilterLabelUntrackedFiles string
100100
FilterLabelConflictingFiles string
101101
MergeConflictsTitle string
102+
MergeConflictDescription_DD string
103+
MergeConflictDescription_AU string
104+
MergeConflictDescription_UA string
105+
MergeConflictDescription_DU string
106+
MergeConflictDescription_UD string
107+
MergeConflictIncomingDiff string
108+
MergeConflictCurrentDiff string
109+
MergeConflictPressEnterToResolve string
102110
Checkout string
103111
CheckoutTooltip string
104112
CantCheckoutBranchWhilePulling string
@@ -1112,6 +1120,14 @@ func EnglishTranslationSet() *TranslationSet {
11121120
PullTooltip: "Pull changes from the remote for the current branch. If no upstream is configured, you will be prompted to configure an upstream branch.",
11131121
Scroll: "Scroll",
11141122
MergeConflictsTitle: "Merge conflicts",
1123+
MergeConflictDescription_DD: "Conflict: this file was moved or renamed both in the current and the incoming changes, but to different destinations. I don't know which ones, but they should both show up as conflicts too (marked 'AU' and 'UA', respectively). The most likely resolution is to delete this file, and pick one of the destinations and delete the other.",
1124+
MergeConflictDescription_AU: "Conflict: this file is the destination of a move or rename in the current changes, but was moved or renamed to a different destination in the incoming changes. That other destination should also show up as a conflict (marked 'UA'), as well as the file that both were renamed from (marked 'DD').",
1125+
MergeConflictDescription_UA: "Conflict: this file is the destination of a move or rename in the incoming changes, but was moved or renamed to a different destination in the current changes. That other destination should also show up as a conflict (marked 'AU'), as well as the file that both were renamed from (marked 'DD').",
1126+
MergeConflictDescription_DU: "Conflict: this file was deleted in the current changes and modified in the incoming changes.\n\nThe most likely resolution is to delete the file after applying the incoming modifications manually to some other place in the code.",
1127+
MergeConflictDescription_UD: "Conflict: this file was modified in the current changes and deleted in incoming changes.\n\nThe most likely resolution is to delete the file after applying the current modifications manually to some other place in the code.",
1128+
MergeConflictIncomingDiff: "Incoming changes:",
1129+
MergeConflictCurrentDiff: "Current changes:",
1130+
MergeConflictPressEnterToResolve: "Press %s to resolve.",
11151131
Checkout: "Checkout",
11161132
CheckoutTooltip: "Checkout selected item.",
11171133
CantCheckoutBranchWhilePulling: "You cannot checkout another branch while pulling the current branch",

0 commit comments

Comments
 (0)