forked from tangled.org/core
Monorepo for Tangled

Compare changes

Choose any two refs to compare.

Changed files
+27 -6
api
tangled
appview
pages
templates
repo
repo
knotserver
lexicons
+2
api/tangled/repocreate.go
··· 18 type RepoCreate_Input struct { 19 // defaultBranch: Default branch to push to 20 DefaultBranch *string `json:"defaultBranch,omitempty" cborgen:"defaultBranch,omitempty"` 21 // rkey: Rkey of the repository record 22 Rkey string `json:"rkey" cborgen:"rkey"` 23 // source: A source URL to clone from, populate this when forking or importing a repository.
··· 18 type RepoCreate_Input struct { 19 // defaultBranch: Default branch to push to 20 DefaultBranch *string `json:"defaultBranch,omitempty" cborgen:"defaultBranch,omitempty"` 21 + // defaultBranchOnly: If true and source is provided, only clone the default branch 22 + DefaultBranchOnly *bool `json:"defaultBranchOnly,omitempty" cborgen:"defaultBranchOnly,omitempty"` 23 // rkey: Rkey of the repository record 24 Rkey string `json:"rkey" cborgen:"rkey"` 25 // source: A source URL to clone from, populate this when forking or importing a repository.
+8 -1
appview/pages/templates/repo/fork.html
··· 5 <p class="text-xl font-bold dark:text-white">Fork {{ .RepoInfo.FullName }}</p> 6 </div> 7 <div class="p-6 bg-white dark:bg-gray-800 drop-shadow-sm rounded"> 8 - <form hx-post="/{{ .RepoInfo.FullName }}/fork" class="space-y-12" hx-swap="none" hx-indicator="#spinner"> 9 10 <fieldset class="space-y-3"> 11 <legend for="repo_name" class="dark:text-white">Repository name</legend> ··· 13 class="w-full p-2 border rounded bg-gray-100 dark:bg-gray-700 dark:text-white dark:border-gray-600" /> 14 </fieldset> 15 16 <fieldset class="space-y-3"> 17 <legend class="dark:text-white">Select a knot to fork into</legend> 18 <div class="space-y-2">
··· 5 <p class="text-xl font-bold dark:text-white">Fork {{ .RepoInfo.FullName }}</p> 6 </div> 7 <div class="p-6 bg-white dark:bg-gray-800 drop-shadow-sm rounded"> 8 + <form hx-post="/{{ .RepoInfo.FullName }}/fork" class="space-y-6" hx-swap="none" hx-indicator="#spinner"> 9 10 <fieldset class="space-y-3"> 11 <legend for="repo_name" class="dark:text-white">Repository name</legend> ··· 13 class="w-full p-2 border rounded bg-gray-100 dark:bg-gray-700 dark:text-white dark:border-gray-600" /> 14 </fieldset> 15 16 + <fieldset class="space-y-3"> 17 + <div class="flex items-center"> 18 + <input type="checkbox" name="default_branch_only" id="default_branch_only" class="mr-2" /> 19 + <label for="default_branch_only" class="dark:text-white normal-case">Copy the default branch only</label> 20 + </div> 21 + </fieldset> 22 + 23 <fieldset class="space-y-3"> 24 <legend class="dark:text-white">Select a knot to fork into</legend> 25 <div class="space-y-2">
+4 -2
appview/repo/repo.go
··· 1144 return 1145 } 1146 1147 err = tangled.RepoCreate( 1148 r.Context(), 1149 client, 1150 &tangled.RepoCreate_Input{ 1151 - Rkey: rkey, 1152 - Source: &forkSourceUrl, 1153 }, 1154 ) 1155 if err := xrpcclient.HandleXrpcErr(err); err != nil {
··· 1144 return 1145 } 1146 1147 + defaultBranchOnly := r.FormValue("default_branch_only") == "on" 1148 err = tangled.RepoCreate( 1149 r.Context(), 1150 client, 1151 &tangled.RepoCreate_Input{ 1152 + Rkey: rkey, 1153 + Source: &forkSourceUrl, 1154 + DefaultBranchOnly: &defaultBranchOnly, 1155 }, 1156 ) 1157 if err := xrpcclient.HandleXrpcErr(err); err != nil {
+7 -2
knotserver/git/fork.go
··· 13 knotconfig "tangled.org/core/knotserver/config" 14 ) 15 16 - func Fork(repoPath, source string, cfg *knotconfig.Config) error { 17 u, err := url.Parse(source) 18 if err != nil { 19 return fmt.Errorf("failed to parse source URL: %w", err) ··· 23 u = o 24 } 25 26 - cloneCmd := exec.Command("git", "clone", "--bare", u.String(), repoPath) 27 if err := cloneCmd.Run(); err != nil { 28 return fmt.Errorf("failed to bare clone repository: %w", err) 29 }
··· 13 knotconfig "tangled.org/core/knotserver/config" 14 ) 15 16 + func Fork(repoPath, source string, singleBranch bool, cfg *knotconfig.Config) error { 17 u, err := url.Parse(source) 18 if err != nil { 19 return fmt.Errorf("failed to parse source URL: %w", err) ··· 23 u = o 24 } 25 26 + args := []string{"clone", "--bare"} 27 + if singleBranch { 28 + args = append(args, "--single-branch") 29 + } 30 + args = append(args, u.String(), repoPath) 31 + cloneCmd := exec.Command("git", args...) 32 if err := cloneCmd.Run(); err != nil { 33 return fmt.Errorf("failed to bare clone repository: %w", err) 34 }
+2 -1
knotserver/xrpc/create_repo.go
··· 84 repoPath, _ := securejoin.SecureJoin(h.Config.Repo.ScanPath, relativeRepoPath) 85 86 if data.Source != nil && *data.Source != "" { 87 - err = git.Fork(repoPath, *data.Source, h.Config) 88 if err != nil { 89 l.Error("forking repo", "error", err.Error()) 90 writeError(w, xrpcerr.GenericError(err), http.StatusInternalServerError)
··· 84 repoPath, _ := securejoin.SecureJoin(h.Config.Repo.ScanPath, relativeRepoPath) 85 86 if data.Source != nil && *data.Source != "" { 87 + singleBranch := data.DefaultBranchOnly != nil && *data.DefaultBranchOnly 88 + err = git.Fork(repoPath, *data.Source, singleBranch, h.Config) 89 if err != nil { 90 l.Error("forking repo", "error", err.Error()) 91 writeError(w, xrpcerr.GenericError(err), http.StatusInternalServerError)
+4
lexicons/repo/create.json
··· 24 "source": { 25 "type": "string", 26 "description": "A source URL to clone from, populate this when forking or importing a repository." 27 } 28 } 29 }
··· 24 "source": { 25 "type": "string", 26 "description": "A source URL to clone from, populate this when forking or importing a repository." 27 + }, 28 + "defaultBranchOnly": { 29 + "type": "boolean", 30 + "description": "If true and source is provided, only clone the default branch" 31 } 32 } 33 }