···
w.WriteHeader(http.StatusNoContent)
634
+
func (h *Handle) RepoForkSyncable(w http.ResponseWriter, r *http.Request) {
635
+
l := h.l.With("handler", "RepoForkSync")
638
+
Did string `json:"did"`
639
+
Source string `json:"source"`
640
+
Name string `json:"name,omitempty"`
641
+
HiddenRef string `json:"hiddenref"`
644
+
if err := json.NewDecoder(r.Body).Decode(&data); err != nil {
645
+
writeError(w, "invalid request body", http.StatusBadRequest)
650
+
source := data.Source
652
+
if did == "" || source == "" {
653
+
l.Error("invalid request body, empty did or name")
654
+
w.WriteHeader(http.StatusBadRequest)
659
+
if data.Name != "" {
662
+
name = filepath.Base(source)
665
+
branch := chi.URLParam(r, "branch")
666
+
branch, _ = url.PathUnescape(branch)
668
+
relativeRepoPath := filepath.Join(did, name)
669
+
repoPath, _ := securejoin.SecureJoin(h.c.Repo.ScanPath, relativeRepoPath)
671
+
gr, err := git.PlainOpen(repoPath)
678
+
forkCommit, err := gr.ResolveRevision(branch)
680
+
l.Error("error resolving ref revision", "msg", err.Error())
681
+
writeError(w, fmt.Sprintf("error resolving revision %s", branch), http.StatusBadRequest)
685
+
sourceCommit, err := gr.ResolveRevision(data.HiddenRef)
687
+
l.Error("error resolving hidden ref revision", "msg", err.Error())
688
+
writeError(w, fmt.Sprintf("error resolving revision %s", data.HiddenRef), http.StatusBadRequest)
692
+
isAncestor, err := forkCommit.IsAncestor(sourceCommit)
694
+
log.Printf("error resolving whether %s is ancestor of %s: %s", branch, data.HiddenRef, err)
698
+
w.Header().Set("Content-Type", "application/json")
699
+
json.NewEncoder(w).Encode(types.AncestorCheckResponse{IsAncestor: isAncestor})
func (h *Handle) RepoForkSync(w http.ResponseWriter, r *http.Request) {
l := h.l.With("handler", "RepoForkSync")
···
679
-
l.Error("syncing repo fork", "error", err.Error())
747
+
l.Error("error syncing repo fork", "error", err.Error())
writeError(w, err.Error(), http.StatusInternalServerError)