From 9e79fe8cf9162a4dd205217c1d16774567232b30 Mon Sep 17 00:00:00 2001 From: Vidya Sagar VOBBILISETTI Date: Mon, 29 Sep 2025 20:00:41 +0200 Subject: [PATCH] appview/repo: add an option to choose the name of the forked repo Given that repo names cannot be changed later, this gives the freedom to choose the name and still stay in the fork network. Signed-off-by: Vidya Sagar VOBBILISETTI --- appview/pages/templates/repo/fork.html | 7 +++++++ appview/repo/repo.go | 18 +++++++++++------- 2 files changed, 18 insertions(+), 7 deletions(-) diff --git a/appview/pages/templates/repo/fork.html b/appview/pages/templates/repo/fork.html index 2fec27e0..3a5c5910 100644 --- a/appview/pages/templates/repo/fork.html +++ b/appview/pages/templates/repo/fork.html @@ -6,6 +6,13 @@
+ +
+ Repository name + +
+
Select a knot to fork into
diff --git a/appview/repo/repo.go b/appview/repo/repo.go index e82dfc80..a47b2e42 100644 --- a/appview/repo/repo.go +++ b/appview/repo/repo.go @@ -2129,25 +2129,29 @@ func (rp *Repo) ForkRepo(w http.ResponseWriter, r *http.Request) { } // choose a name for a fork - forkName := f.Name + forkName := r.FormValue("repo_name") + if forkName == "" { + rp.pages.Notice(w, "repo", "Repository name cannot be empty.") + return + } + // this check is *only* to see if the forked repo name already exists // in the user's account. existingRepo, err := db.GetRepo( rp.db, db.FilterEq("did", user.Did), - db.FilterEq("name", f.Name), + db.FilterEq("name", forkName), ) if err != nil { - if errors.Is(err, sql.ErrNoRows) { - // no existing repo with this name found, we can use the name as is - } else { + if !errors.Is(err, sql.ErrNoRows) { log.Println("error fetching existing repo from db", "err", err) rp.pages.Notice(w, "repo", "Failed to fork this repository. Try again later.") return } } else if existingRepo != nil { - // repo with this name already exists, append random string - forkName = fmt.Sprintf("%s-%s", forkName, randomString(3)) + // repo with this name already exists + rp.pages.Notice(w, "repo", "A repository with this name already exists.") + return } l = l.With("forkName", forkName) -- 2.43.0