jeftadlvw / git-nest

Nest external repositories into your project without git being bothered.
https://github.com/jeftadlvw/git-nest
Apache License 2.0
1 stars 1 forks source link

♻️ improve/outsource path model #34

Open jeftadlvw opened 1 month ago

jeftadlvw commented 1 month ago

The Path model, originally intended as a simple and more accessible wrapper for golang's filepath, is widely used in the whole project for more specific (type) control. It's currently placed as a model and has no other any internal dependenies.

Recent issues and commits showed that this wrapper is not consistent enough and unpredictable in regarding to filesystem case-sensitivity. Because git-nest works on the filesystem level, it's highly important that filehandling is consistent and predictable, while also abstracting away filesystem-level case-sensivitiy.

Thus Path should be either rewritten and tested, or an external dependency. Some libraries exist (https://github.com/spf13/afero, https://github.com/chigopher/pathlib), but these seem bigger than just simple lightweight wrappers (which is what's needed).

I don't mind if a Path becomes a little struct, but the footprint should be kept small. Maybe something like this is fitting:

type Path struct {
   path string
}

func NewPath(p string) Path {
   return Path{path: p}
}

func (p *Path) String() string {
   return p.path
}

// ... other functions

This keeps the footprint small, while also generating a source of truth (which is something the current "a path is really a string type" cannot give).

The new Path should also support windows and network paths, provide conversions, better error handling and byte/text marshaling/unmarshaling.