oh-my-posh/src/segments/git_unix.go
Piotr Kalinowski a2533c8f5b fix(git): better cross-platform path resolution and tests
The simple filepath.IsAbs() is not enough on Windows, where the relative
path may start with a separator and should then be taken relative to the
volume name.

So, introduce resolveGitPath() helper function that will do the right
thing on both Windows and other systems. As a bonus, it returns paths
converted to slashes for ease of use with the rest of the git segment:
- Git for Windows uses only slashes.
- Slashes do work as a path separator on Windows anyway.
- Some tests in git segment still use (and rightfully so) slashes.

Add tests for resolveGitPath() on both types of systems and fix
TestEnableInWorktree using a system-dependent testing constant as a root
path.
2022-08-03 18:20:00 +02:00

14 lines
241 B
Go

//go:build !windows
package segments
import "path/filepath"
// resolveGitPath resolves path relative to base.
func resolveGitPath(base, path string) string {
if filepath.IsAbs(path) {
return path
}
return filepath.Join(base, path)
}