git-lfs/commands/path.go
brian m. carlson 226f5bb092
track: use default line endings for core.autocrlf=input
We currently use core.autocrlf to guess what line endings a user might
want to have for the .gitattributes file if it lacks line endings
already. When the user has specified core.autocrlf=input, they have
specified that they don't want line endings to be changed. This isn't
explicitly an indication that they want to use CRLF line endings,
especially if they are on a non-Windows system.

Therefore, if we need to guess what line endings to use with
core.autocrlf=input, guess the system line endings, not CRLF.
2019-07-16 16:57:21 +00:00

36 lines
829 B
Go

package commands
import "strings"
func gitLineEnding(git env) string {
value, _ := git.Get("core.autocrlf")
switch strings.ToLower(value) {
case "true", "t", "1":
return "\r\n"
default:
return osLineEnding()
}
}
const (
windowsPrefix = `.\`
nixPrefix = `./`
)
// trimCurrentPrefix removes a leading prefix of "./" or ".\" (referring to the
// current directory in a platform independent manner).
//
// It is useful for callers such as "git lfs track" and "git lfs untrack", that
// wish to compare filepaths and/or attributes patterns without cleaning across
// multiple platforms.
func trimCurrentPrefix(p string) string {
if strings.HasPrefix(p, windowsPrefix) {
return strings.TrimPrefix(p, windowsPrefix)
}
return strings.TrimPrefix(p, nixPrefix)
}
type env interface {
Get(string) (string, bool)
}