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