| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
package commands |
| 5 |
|
| 6 |
import ( |
| 7 |
"path/filepath" |
| 8 |
"regexp" |
| 9 |
"strings" |
| 10 |
"sync" |
| 11 |
|
| 12 |
"github.com/git-lfs/git-lfs/v3/subprocess" |
| 13 |
) |
| 14 |
|
| 15 |
var ( |
| 16 |
winBashPrefix string |
| 17 |
winBashMu sync.Mutex |
| 18 |
winBashRe *regexp.Regexp |
| 19 |
) |
| 20 |
|
| 21 |
func osLineEnding() string { |
| 22 |
return "\r\n" |
| 23 |
} |
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
func cleanRootPath(pattern string) string { |
| 41 |
winBashMu.Lock() |
| 42 |
defer winBashMu.Unlock() |
| 43 |
|
| 44 |
|
| 45 |
if !winPathHasDrive(pattern) { |
| 46 |
return pattern |
| 47 |
} |
| 48 |
|
| 49 |
if len(winBashPrefix) < 1 { |
| 50 |
|
| 51 |
cmd, err := subprocess.ExecCommand("pwd") |
| 52 |
if err != nil { |
| 53 |
return pattern |
| 54 |
} |
| 55 |
winBashPrefix = strings.Replace(filepath.Dir(filepath.Dir(filepath.Dir(cmd.Path))), `\`, "/", -1) + "/" |
| 56 |
} |
| 57 |
|
| 58 |
return strings.Replace(pattern, winBashPrefix, "/", 1) |
| 59 |
} |
| 60 |
|
| 61 |
func winPathHasDrive(pattern string) bool { |
| 62 |
if winBashRe == nil { |
| 63 |
winBashRe = regexp.MustCompile(`\A\w{1}:[/\/]`) |
| 64 |
} |
| 65 |
|
| 66 |
return winBashRe.MatchString(pattern) |
| 67 |
} |