1
0
mirror of https://github.com/jesseduffield/lazygit.git synced 2025-01-18 05:17:55 +02:00

bubble up tracked files in flat file view

This commit is contained in:
Jesse Duffield 2021-04-12 21:57:43 +10:00
parent dab5ba363c
commit 9e5f031553
2 changed files with 64 additions and 13 deletions

View File

@ -97,10 +97,35 @@ func BuildFlatTreeFromFiles(files []*models.File) *FileNode {
rootAux := BuildTreeFromFiles(files)
sortedFiles := rootAux.GetLeaves()
// Move merge conflicts to top. This is the one way in which sorting
// differs between flat mode and tree mode
// from top down we have merge conflict files, then tracked file, then untracked
// files. This is the one way in which sorting differs between flat mode and
// tree mode
sort.SliceStable(sortedFiles, func(i, j int) bool {
return sortedFiles[i].File != nil && sortedFiles[i].File.HasMergeConflicts && !(sortedFiles[j].File != nil && sortedFiles[j].File.HasMergeConflicts)
iFile := sortedFiles[i].File
jFile := sortedFiles[j].File
// never going to happen but just to be safe
if iFile == nil || jFile == nil {
return false
}
if iFile.HasMergeConflicts && !jFile.HasMergeConflicts {
return true
}
if jFile.HasMergeConflicts && !iFile.HasMergeConflicts {
return false
}
if iFile.Tracked && !jFile.Tracked {
return true
}
if jFile.Tracked && !iFile.Tracked {
return false
}
return false
})
return &FileNode{Children: sortedFiles}

View File

@ -236,33 +236,59 @@ func TestBuildFlatTreeFromFiles(t *testing.T) {
},
},
{
name: "paths that can be sorted including a merge conflict file",
name: "tracked, untracked, and conflicted files",
files: []*models.File{
{
Name: "z",
Name: "a2",
Tracked: false,
},
{
Name: "a1",
Tracked: false,
},
{
Name: "c2",
HasMergeConflicts: true,
},
{
Name: "b",
Name: "c1",
HasMergeConflicts: true,
},
{
Name: "a",
Name: "b2",
Tracked: true,
},
{
Name: "b1",
Tracked: true,
},
},
expected: &FileNode{
Path: "",
Children: []*FileNode{
{
File: &models.File{Name: "z", HasMergeConflicts: true},
Path: "z",
File: &models.File{Name: "c1", HasMergeConflicts: true},
Path: "c1",
},
{
File: &models.File{Name: "a"},
Path: "a",
File: &models.File{Name: "c2", HasMergeConflicts: true},
Path: "c2",
},
{
File: &models.File{Name: "b"},
Path: "b",
File: &models.File{Name: "b1", Tracked: true},
Path: "b1",
},
{
File: &models.File{Name: "b2", Tracked: true},
Path: "b2",
},
{
File: &models.File{Name: "a1", Tracked: false},
Path: "a1",
},
{
File: &models.File{Name: "a2", Tracked: false},
Path: "a2",
},
},
},