Skip to content

Commit

Permalink
windows/darwin: Fixed the status error of files with the same name (c…
Browse files Browse the repository at this point in the history
…ase insensitive)
  • Loading branch information
fcharlie committed Nov 25, 2024
1 parent a1f9ff4 commit b568352
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 6 deletions.
30 changes: 29 additions & 1 deletion pkg/zeta/worktree_drawin.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
package zeta

import (
"bytes"
"strings"
"syscall"
"time"

Expand Down Expand Up @@ -42,8 +44,9 @@ func (w *Worktree) excludeIgnoredChanges(changes merkletrie.Changes) merkletrie.
if err != nil {
return changes
}

var newItems merkletrie.Changes
var res merkletrie.Changes
rmItems := make(map[string]merkletrie.Change)
for _, ch := range changes {
var path []string
for _, n := range ch.To {
Expand All @@ -62,6 +65,31 @@ func (w *Worktree) excludeIgnoredChanges(changes merkletrie.Changes) merkletrie.
}
}
}
// Add
if ch.From == nil {
newItems = append(newItems, ch)
continue
}
// Del
if ch.To == nil {
rmItems[strings.ToLower(ch.From.String())] = ch
continue
}
res = append(res, ch)
}
for _, ch := range newItems {
name := strings.ToLower(ch.To.String())
if c, ok := rmItems[name]; ok {
if !bytes.Equal(c.From.Hash(), ch.To.Hash()) {
ch.From = c.From
res = append(res, ch) // rename and modify
}
delete(rmItems, name)
continue
}
res = append(res, ch)
}
for _, ch := range rmItems {
res = append(res, ch)
}
return res
Expand Down
38 changes: 33 additions & 5 deletions pkg/zeta/worktree_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@
package zeta

import (
"bytes"
"os"
"strings"
"syscall"
"time"

Expand Down Expand Up @@ -51,7 +53,7 @@ type hasher interface {
Mode() filemode.FileMode
}

func (w *Worktree) hijackChange(ch *merkletrie.Change) bool {
func (w *Worktree) hijackChangeFileMode(ch *merkletrie.Change) bool {
if ch.From == nil || ch.To == nil {
return false
}
Expand Down Expand Up @@ -91,12 +93,10 @@ func (w *Worktree) excludeIgnoredChanges(changes merkletrie.Changes) merkletrie.
if err != nil {
return changes
}

var newItems merkletrie.Changes
var res merkletrie.Changes
rmItems := make(map[string]merkletrie.Change)
for _, ch := range changes {
if w.hijackChange(&ch) {
continue
}
var path []string
for _, n := range ch.To {
path = append(path, n.Name())
Expand All @@ -114,6 +114,34 @@ func (w *Worktree) excludeIgnoredChanges(changes merkletrie.Changes) merkletrie.
}
}
}
if w.hijackChangeFileMode(&ch) {
continue
}
// Add
if ch.From == nil {
newItems = append(newItems, ch)
continue
}
// Del
if ch.To == nil {
rmItems[strings.ToLower(ch.From.String())] = ch
continue
}
res = append(res, ch)
}
for _, ch := range newItems {
name := strings.ToLower(ch.To.String())
if c, ok := rmItems[name]; ok {
if !bytes.Equal(c.From.Hash(), ch.To.Hash()) {
ch.From = c.From
res = append(res, ch) // rename and modify
}
delete(rmItems, name)
continue
}
res = append(res, ch)
}
for _, ch := range rmItems {
res = append(res, ch)
}
return res
Expand Down

0 comments on commit b568352

Please sign in to comment.