mirror of
https://github.com/JanDeDobbeleer/oh-my-posh.git
synced 2025-03-05 20:49:04 -08:00
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.
14 lines
241 B
Go
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)
|
|
}
|