MCPcopy
hub / github.com/git-lfs/git-lfs / locksHandler

Function locksHandler

t/cmd/lfstest-gitserver.go:1280–1488  ·  view source on GitHub ↗
(w http.ResponseWriter, r *http.Request, repo string)

Source from the content-addressed store, hash-verified

1278)
1279
1280func locksHandler(w http.ResponseWriter, r *http.Request, repo string) {
1281 dec := json.NewDecoder(r.Body)
1282 enc := json.NewEncoder(w)
1283
1284 if repo == "netrctest" {
1285 _, user, pass, err := extractAuth(r.Header.Get("Authorization"))
1286 if err != nil || (user == "netrcuser" && pass == "badpassretry") {
1287 writeLFSError(w, 401, "Error: Bad Auth")
1288 return
1289 }
1290 }
1291
1292 switch r.Method {
1293 case "GET":
1294 if !lockRe.MatchString(r.URL.Path) {
1295 w.Header().Set("Content-Type", "application/json")
1296 w.WriteHeader(http.StatusNotFound)
1297 w.Write([]byte(`{"message":"unknown path: ` + r.URL.Path + `"}`))
1298 return
1299 }
1300
1301 if err := r.ParseForm(); err != nil {
1302 http.Error(w, "could not parse form values", http.StatusInternalServerError)
1303 return
1304 }
1305
1306 if strings.HasSuffix(repo, "branch-required") {
1307 parts := strings.Split(repo, "-")
1308 lenParts := len(parts)
1309 if lenParts > 3 && "refs/heads/"+parts[lenParts-3] != r.FormValue("refspec") {
1310 w.WriteHeader(403)
1311 enc.Encode(struct {
1312 Message string `json:"message"`
1313 }{fmt.Sprintf("Expected ref %q, got %q", "refs/heads/"+parts[lenParts-3], r.FormValue("refspec"))})
1314 return
1315 }
1316 }
1317
1318 ll := &LockList{}
1319 w.Header().Set("Content-Type", "application/json")
1320 locks, nextCursor, err := getFilteredLocks(repo,
1321 r.FormValue("path"),
1322 r.FormValue("cursor"),
1323 r.FormValue("limit"))
1324
1325 if err != nil {
1326 ll.Message = err.Error()
1327 } else {
1328 ll.Locks = locks
1329 ll.NextCursor = nextCursor
1330 }
1331
1332 enc.Encode(ll)
1333 return
1334 case "POST":
1335 w.Header().Set("Content-Type", "application/json")
1336 if strings.HasSuffix(r.URL.Path, "unlock") {
1337 var lockId string

Callers 1

lfsHandlerFunction · 0.85

Calls 15

RefNameMethod · 0.95
RefNameMethod · 0.95
RefNameMethod · 0.95
extractAuthFunction · 0.85
writeLFSErrorFunction · 0.85
getFilteredLocksFunction · 0.85
delLockFunction · 0.85
getLocksFunction · 0.85
addLocksFunction · 0.85
EncodeMethod · 0.80
GetMethod · 0.65
SetMethod · 0.65

Tested by

no test coverage detected