Skip to content

Commit 2645952

Browse files
committed
Add a root item ("/") if files at top level have changed
1 parent 0b42cfb commit 2645952

File tree

61 files changed

+663
-448
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

61 files changed

+663
-448
lines changed

pkg/gui/controllers/commits_files_controller.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -509,7 +509,7 @@ func (self *CommitFilesController) enterCommitFile(node *filetree.CommitFileNode
509509
}
510510

511511
func (self *CommitFilesController) handleToggleCommitFileDirCollapsed(node *filetree.CommitFileNode) error {
512-
self.context().CommitFileTreeViewModel.ToggleCollapsed(node.GetPath())
512+
self.context().CommitFileTreeViewModel.ToggleCollapsed(node.GetInternalPath())
513513

514514
self.c.PostRefreshUpdate(self.context())
515515

pkg/gui/controllers/files_controller.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1078,7 +1078,7 @@ func (self *FilesController) handleToggleDirCollapsed() error {
10781078
return nil
10791079
}
10801080

1081-
self.context().FileTreeViewModel.ToggleCollapsed(node.GetPath())
1081+
self.context().FileTreeViewModel.ToggleCollapsed(node.GetInternalPath())
10821082

10831083
self.c.PostRefreshUpdate(self.c.Contexts().Files)
10841084

pkg/gui/filetree/build_tree.go

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ func BuildTreeFromFiles(files []*models.File) *Node[models.File] {
1414

1515
var curr *Node[models.File]
1616
for _, file := range files {
17-
splitPath := split(file.Path)
17+
splitPath := split("./" + file.Path)
1818
curr = root
1919
outer:
2020
for i := range splitPath {
@@ -40,6 +40,11 @@ func BuildTreeFromFiles(files []*models.File) *Node[models.File] {
4040
continue outer
4141
}
4242

43+
if i == 0 && len(files) == 1 && len(splitPath) == 2 {
44+
// skip the root item when there's only one file at top level; we don't need it in that case
45+
continue outer
46+
}
47+
4348
newChild := &Node[models.File]{
4449
path: path,
4550
File: setFile,
@@ -70,7 +75,7 @@ func BuildTreeFromCommitFiles(files []*models.CommitFile) *Node[models.CommitFil
7075

7176
var curr *Node[models.CommitFile]
7277
for _, file := range files {
73-
splitPath := split(file.Path)
78+
splitPath := split("./" + file.Path)
7479
curr = root
7580
outer:
7681
for i := range splitPath {
@@ -89,6 +94,11 @@ func BuildTreeFromCommitFiles(files []*models.CommitFile) *Node[models.CommitFil
8994
}
9095
}
9196

97+
if i == 0 && len(files) == 1 && len(splitPath) == 2 {
98+
// skip the root item when there's only one file at top level; we don't need it in that case
99+
continue outer
100+
}
101+
92102
newChild := &Node[models.CommitFile]{
93103
path: path,
94104
File: setFile,

pkg/gui/filetree/build_tree_test.go

Lines changed: 99 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -35,15 +35,16 @@ func TestBuildTreeFromFiles(t *testing.T) {
3535
path: "",
3636
Children: []*Node[models.File]{
3737
{
38-
path: "dir1",
38+
path: "./dir1",
39+
CompressionLevel: 1,
3940
Children: []*Node[models.File]{
4041
{
4142
File: &models.File{Path: "dir1/a"},
42-
path: "dir1/a",
43+
path: "./dir1/a",
4344
},
4445
{
4546
File: &models.File{Path: "dir1/b"},
46-
path: "dir1/b",
47+
path: "./dir1/b",
4748
},
4849
},
4950
},
@@ -64,24 +65,29 @@ func TestBuildTreeFromFiles(t *testing.T) {
6465
path: "",
6566
Children: []*Node[models.File]{
6667
{
67-
path: "dir1/dir3",
68+
path: ".",
6869
Children: []*Node[models.File]{
6970
{
70-
File: &models.File{Path: "dir1/dir3/a"},
71-
path: "dir1/dir3/a",
71+
path: "./dir1/dir3",
72+
Children: []*Node[models.File]{
73+
{
74+
File: &models.File{Path: "dir1/dir3/a"},
75+
path: "./dir1/dir3/a",
76+
},
77+
},
78+
CompressionLevel: 1,
7279
},
73-
},
74-
CompressionLevel: 1,
75-
},
76-
{
77-
path: "dir2/dir4",
78-
Children: []*Node[models.File]{
7980
{
80-
File: &models.File{Path: "dir2/dir4/b"},
81-
path: "dir2/dir4/b",
81+
path: "./dir2/dir4",
82+
Children: []*Node[models.File]{
83+
{
84+
File: &models.File{Path: "dir2/dir4/b"},
85+
path: "./dir2/dir4/b",
86+
},
87+
},
88+
CompressionLevel: 1,
8289
},
8390
},
84-
CompressionLevel: 1,
8591
},
8692
},
8793
},
@@ -100,12 +106,17 @@ func TestBuildTreeFromFiles(t *testing.T) {
100106
path: "",
101107
Children: []*Node[models.File]{
102108
{
103-
File: &models.File{Path: "a"},
104-
path: "a",
105-
},
106-
{
107-
File: &models.File{Path: "b"},
108-
path: "b",
109+
path: ".",
110+
Children: []*Node[models.File]{
111+
{
112+
File: &models.File{Path: "a"},
113+
path: "./a",
114+
},
115+
{
116+
File: &models.File{Path: "b"},
117+
path: "./b",
118+
},
119+
},
109120
},
110121
},
111122
},
@@ -126,20 +137,25 @@ func TestBuildTreeFromFiles(t *testing.T) {
126137
},
127138
expected: &Node[models.File]{
128139
path: "",
129-
// it is a little strange that we're not bubbling up our merge conflict
130-
// here but we are technically still in tree mode and that's the rule
131140
Children: []*Node[models.File]{
132141
{
133-
File: &models.File{Path: "a"},
134-
path: "a",
135-
},
136-
{
137-
File: &models.File{Path: "b"},
138-
path: "b",
139-
},
140-
{
141-
File: &models.File{Path: "z", HasMergeConflicts: true},
142-
path: "z",
142+
path: ".",
143+
// it is a little strange that we're not bubbling up our merge conflict
144+
// here but we are technically still in tree mode and that's the rule
145+
Children: []*Node[models.File]{
146+
{
147+
File: &models.File{Path: "a"},
148+
path: "./a",
149+
},
150+
{
151+
File: &models.File{Path: "b"},
152+
path: "./b",
153+
},
154+
{
155+
File: &models.File{Path: "z", HasMergeConflicts: true},
156+
path: "./z",
157+
},
158+
},
143159
},
144160
},
145161
},
@@ -183,12 +199,12 @@ func TestBuildFlatTreeFromFiles(t *testing.T) {
183199
Children: []*Node[models.File]{
184200
{
185201
File: &models.File{Path: "dir1/a"},
186-
path: "dir1/a",
202+
path: "./dir1/a",
187203
CompressionLevel: 0,
188204
},
189205
{
190206
File: &models.File{Path: "dir1/b"},
191-
path: "dir1/b",
207+
path: "./dir1/b",
192208
CompressionLevel: 0,
193209
},
194210
},
@@ -209,12 +225,12 @@ func TestBuildFlatTreeFromFiles(t *testing.T) {
209225
Children: []*Node[models.File]{
210226
{
211227
File: &models.File{Path: "dir1/a"},
212-
path: "dir1/a",
228+
path: "./dir1/a",
213229
CompressionLevel: 0,
214230
},
215231
{
216232
File: &models.File{Path: "dir2/b"},
217-
path: "dir2/b",
233+
path: "./dir2/b",
218234
CompressionLevel: 0,
219235
},
220236
},
@@ -235,11 +251,11 @@ func TestBuildFlatTreeFromFiles(t *testing.T) {
235251
Children: []*Node[models.File]{
236252
{
237253
File: &models.File{Path: "a"},
238-
path: "a",
254+
path: "./a",
239255
},
240256
{
241257
File: &models.File{Path: "b"},
242-
path: "b",
258+
path: "./b",
243259
},
244260
},
245261
},
@@ -277,27 +293,27 @@ func TestBuildFlatTreeFromFiles(t *testing.T) {
277293
Children: []*Node[models.File]{
278294
{
279295
File: &models.File{Path: "c1", HasMergeConflicts: true},
280-
path: "c1",
296+
path: "./c1",
281297
},
282298
{
283299
File: &models.File{Path: "c2", HasMergeConflicts: true},
284-
path: "c2",
300+
path: "./c2",
285301
},
286302
{
287303
File: &models.File{Path: "b1", Tracked: true},
288-
path: "b1",
304+
path: "./b1",
289305
},
290306
{
291307
File: &models.File{Path: "b2", Tracked: true},
292-
path: "b2",
308+
path: "./b2",
293309
},
294310
{
295311
File: &models.File{Path: "a1", Tracked: false},
296-
path: "a1",
312+
path: "./a1",
297313
},
298314
{
299315
File: &models.File{Path: "a2", Tracked: false},
300-
path: "a2",
316+
path: "./a2",
301317
},
302318
},
303319
},
@@ -340,15 +356,16 @@ func TestBuildTreeFromCommitFiles(t *testing.T) {
340356
path: "",
341357
Children: []*Node[models.CommitFile]{
342358
{
343-
path: "dir1",
359+
path: "./dir1",
360+
CompressionLevel: 1,
344361
Children: []*Node[models.CommitFile]{
345362
{
346363
File: &models.CommitFile{Path: "dir1/a"},
347-
path: "dir1/a",
364+
path: "./dir1/a",
348365
},
349366
{
350367
File: &models.CommitFile{Path: "dir1/b"},
351-
path: "dir1/b",
368+
path: "./dir1/b",
352369
},
353370
},
354371
},
@@ -369,24 +386,29 @@ func TestBuildTreeFromCommitFiles(t *testing.T) {
369386
path: "",
370387
Children: []*Node[models.CommitFile]{
371388
{
372-
path: "dir1/dir3",
389+
path: ".",
373390
Children: []*Node[models.CommitFile]{
374391
{
375-
File: &models.CommitFile{Path: "dir1/dir3/a"},
376-
path: "dir1/dir3/a",
392+
path: "./dir1/dir3",
393+
Children: []*Node[models.CommitFile]{
394+
{
395+
File: &models.CommitFile{Path: "dir1/dir3/a"},
396+
path: "./dir1/dir3/a",
397+
},
398+
},
399+
CompressionLevel: 1,
377400
},
378-
},
379-
CompressionLevel: 1,
380-
},
381-
{
382-
path: "dir2/dir4",
383-
Children: []*Node[models.CommitFile]{
384401
{
385-
File: &models.CommitFile{Path: "dir2/dir4/b"},
386-
path: "dir2/dir4/b",
402+
path: "./dir2/dir4",
403+
Children: []*Node[models.CommitFile]{
404+
{
405+
File: &models.CommitFile{Path: "dir2/dir4/b"},
406+
path: "./dir2/dir4/b",
407+
},
408+
},
409+
CompressionLevel: 1,
387410
},
388411
},
389-
CompressionLevel: 1,
390412
},
391413
},
392414
},
@@ -405,12 +427,17 @@ func TestBuildTreeFromCommitFiles(t *testing.T) {
405427
path: "",
406428
Children: []*Node[models.CommitFile]{
407429
{
408-
File: &models.CommitFile{Path: "a"},
409-
path: "a",
410-
},
411-
{
412-
File: &models.CommitFile{Path: "b"},
413-
path: "b",
430+
path: ".",
431+
Children: []*Node[models.CommitFile]{
432+
{
433+
File: &models.CommitFile{Path: "a"},
434+
path: "./a",
435+
},
436+
{
437+
File: &models.CommitFile{Path: "b"},
438+
path: "./b",
439+
},
440+
},
414441
},
415442
},
416443
},
@@ -454,12 +481,12 @@ func TestBuildFlatTreeFromCommitFiles(t *testing.T) {
454481
Children: []*Node[models.CommitFile]{
455482
{
456483
File: &models.CommitFile{Path: "dir1/a"},
457-
path: "dir1/a",
484+
path: "./dir1/a",
458485
CompressionLevel: 0,
459486
},
460487
{
461488
File: &models.CommitFile{Path: "dir1/b"},
462-
path: "dir1/b",
489+
path: "./dir1/b",
463490
CompressionLevel: 0,
464491
},
465492
},
@@ -480,12 +507,12 @@ func TestBuildFlatTreeFromCommitFiles(t *testing.T) {
480507
Children: []*Node[models.CommitFile]{
481508
{
482509
File: &models.CommitFile{Path: "dir1/a"},
483-
path: "dir1/a",
510+
path: "./dir1/a",
484511
CompressionLevel: 0,
485512
},
486513
{
487514
File: &models.CommitFile{Path: "dir2/b"},
488-
path: "dir2/b",
515+
path: "./dir2/b",
489516
CompressionLevel: 0,
490517
},
491518
},
@@ -506,11 +533,11 @@ func TestBuildFlatTreeFromCommitFiles(t *testing.T) {
506533
Children: []*Node[models.CommitFile]{
507534
{
508535
File: &models.CommitFile{Path: "a"},
509-
path: "a",
536+
path: "./a",
510537
},
511538
{
512539
File: &models.CommitFile{Path: "b"},
513-
path: "b",
540+
path: "./b",
514541
},
515542
},
516543
},

0 commit comments

Comments
 (0)