Turns out we were accidentally using the destination knot as the sourceUrl, and git was understandably annoyed. This also improves the error checking when fetching the existingRepo from the database to verify the forkName won't clash.
+14
-8
appview/state/repo.go
+14
-8
appview/state/repo.go
···
1698
1698
1699
1699
forkName := fmt.Sprintf("%s", f.RepoName)
1700
1700
1701
-
existingRepo, err := db.GetRepo(s.db, f.OwnerDid(), f.RepoName)
1702
-
if err == nil && existingRepo != nil {
1701
+
// this check is *only* to see if the forked repo name already exists
1702
+
// in the user's account.
1703
+
existingRepo, err := db.GetRepo(s.db, user.Did, f.RepoName)
1704
+
if err != nil {
1705
+
if errors.Is(err, sql.ErrNoRows) {
1706
+
// no existing repo with this name found, we can use the name as is
1707
+
} else {
1708
+
log.Println("error fetching existing repo from db", err)
1709
+
s.pages.Notice(w, "repo", "Failed to fork this repository. Try again later.")
1710
+
return
1711
+
}
1712
+
} else if existingRepo != nil {
1713
+
// repo with this name already exists, append random string
1703
1714
forkName = fmt.Sprintf("%s-%s", forkName, randomString(3))
1704
-
} else if err != nil {
1705
-
log.Println("error fetching existing repo from db", err)
1706
-
s.pages.Notice(w, "repo", "Failed to fork this repository. Try again later.")
1707
-
return
1708
1715
}
1709
-
1710
1716
secret, err := db.GetRegistrationKey(s.db, knot)
1711
1717
if err != nil {
1712
1718
s.pages.Notice(w, "repo", fmt.Sprintf("No registration key found for knot %s.", knot))
···
1725
1731
} else {
1726
1732
uri = "https"
1727
1733
}
1728
-
sourceUrl := fmt.Sprintf("%s://%s/%s/%s", uri, existingRepo.Knot, f.OwnerDid(), f.RepoName)
1734
+
sourceUrl := fmt.Sprintf("%s://%s/%s/%s", uri, f.Knot, f.OwnerDid(), f.RepoName)
1729
1735
sourceAt := f.RepoAt.String()
1730
1736
1731
1737
rkey := s.TID()