diff --git a/appview/pages/templates/repo/new.html b/appview/pages/templates/repo/new.html index ebf85f8e..e71ee250 100644 --- a/appview/pages/templates/repo/new.html +++ b/appview/pages/templates/repo/new.html @@ -16,6 +16,16 @@ class="w-full max-w-md" />

All repositories are publicly visible.

+ + + +

The default branch is main

diff --git a/appview/state/signer.go b/appview/state/signer.go index 9c32d1b2..e35789fd 100644 --- a/appview/state/signer.go +++ b/appview/state/signer.go @@ -77,17 +77,20 @@ func (s *SignedClient) Init(did string) (*http.Response, error) { return s.client.Do(req) } -func (s *SignedClient) NewRepo(did, repoName string) (*http.Response, error) { +func (s *SignedClient) NewRepo(did, repoName, defaultBranch string) (*http.Response, error) { const ( Method = "PUT" Endpoint = "/repo/new" ) body, _ := json.Marshal(map[string]interface{}{ - "did": did, - "name": repoName, + "did": did, + "name": repoName, + "default_branch": defaultBranch, }) + fmt.Println(body) + req, err := s.newRequest(Method, Endpoint, body) if err != nil { return nil, err diff --git a/appview/state/state.go b/appview/state/state.go index 6372af7e..6ca97190 100644 --- a/appview/state/state.go +++ b/appview/state/state.go @@ -508,6 +508,11 @@ func (s *State) AddRepo(w http.ResponseWriter, r *http.Request) { return } + defaultBranch := r.FormValue("branch") + if defaultBranch == "" { + defaultBranch = "main" + } + ok, err := s.enforcer.E.Enforce(user.Did, domain, domain, "repo:create") if err != nil || !ok { s.pages.Notice(w, "repo", "You do not have permission to create a repo in this knot.") @@ -526,7 +531,7 @@ func (s *State) AddRepo(w http.ResponseWriter, r *http.Request) { return } - resp, err := client.NewRepo(user.Did, repoName) + resp, err := client.NewRepo(user.Did, repoName, defaultBranch) if err != nil { s.pages.Notice(w, "repo", "Failed to create repository on knot server.") return diff --git a/knotserver/routes.go b/knotserver/routes.go index cf2f8ef6..3b7a0539 100644 --- a/knotserver/routes.go +++ b/knotserver/routes.go @@ -505,8 +505,9 @@ func (h *Handle) NewRepo(w http.ResponseWriter, r *http.Request) { return } + log.Println("branch", data.DefaultBranch) if data.DefaultBranch == "" { - data.DefaultBranch = "main" + data.DefaultBranch = h.c.Repo.MainBranch } did := data.Did