MCPcopy Index your code
hub / github.com/git-lfs/git-lfs / lockPath

Function lockPath

commands/command_lock.go:113–140  ·  view source on GitHub ↗

lockPath relativizes the given filepath such that it is relative to the root path of the repository it is contained within, taking into account the working directory of the caller. lockPaths also respects different filesystem directory separators, so that a Windows path of "\foo\bar" will be normal

(data *lockData, file string)

Source from the content-addressed store, hash-verified

111// - File to lock: ./baz
112// - Resolved path bar/baz
113func lockPath(data *lockData, file string) (string, error) {
114 var abs string
115 var err error
116
117 if filepath.IsAbs(file) {
118 abs, err = tools.CanonicalizeSystemPath(file)
119 if err != nil {
120 return "", errors.New(tr.Tr.Get("unable to canonicalize path %q: %v", file, err))
121 }
122 } else {
123 abs = filepath.Join(data.workingDir, file)
124 }
125 path, err := filepath.Rel(data.rootDir, abs)
126 if err != nil {
127 return "", err
128 }
129
130 path = filepath.ToSlash(path)
131 if strings.HasPrefix(path, "../") {
132 return "", errors.New(tr.Tr.Get("unable to canonicalize path %q", path))
133 }
134
135 if stat, err := os.Stat(abs); err == nil && stat.IsDir() {
136 return path, errors.New(tr.Tr.Get("cannot lock directory: %s", file))
137 }
138
139 return filepath.ToSlash(path), nil
140}
141
142func init() {
143 RegisterCommand("lock", lockCommand, func(cmd *cobra.Command) {

Callers 3

FiltersMethod · 0.85
lockCommandFunction · 0.85
unlockCommandFunction · 0.85

Calls 4

CanonicalizeSystemPathFunction · 0.92
NewFunction · 0.92
RelMethod · 0.80
GetMethod · 0.65

Tested by

no test coverage detected