From 27cdd77a59e1851a693dfcda774d3fc944ba6c28 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=98=99=E2=97=A6=20The=20Tablet=20=E2=9D=80=20GamerGirla?= =?UTF-8?q?ndCo=20=E2=97=A6=E2=9D=A7?= Date: Fri, 21 Nov 2025 23:57:26 -0500 Subject: [PATCH] update `serv` command to recognize group ids in urls --- cmd/serv.go | 17 +++++++++++++---- modules/private/serv.go | 9 +++++++-- 2 files changed, 20 insertions(+), 6 deletions(-) diff --git a/cmd/serv.go b/cmd/serv.go index a35d476c86..9a078cc0c7 100644 --- a/cmd/serv.go +++ b/cmd/serv.go @@ -201,8 +201,17 @@ func runServ(ctx context.Context, c *cli.Command) error { repoPath := strings.TrimPrefix(sshCmdArgs[1], "/") repoPathFields := strings.SplitN(repoPath, "/", 2) + rawGroup, _, _ := strings.Cut(repoPathFields[1], "/") + var groupID int64 if len(repoPathFields) != 2 { - return fail(ctx, "Invalid repository path", "Invalid repository path: %v", repoPath) + if len(repoPathFields) == 3 { + groupID, err = strconv.ParseInt(rawGroup, 10, 64) + if err != nil { + return fail(ctx, "Invalid repository path", "Invalid repository path: %v", repoPath) + } + } else { + return fail(ctx, "Invalid repository path", "Invalid repository path: %v", repoPath) + } } username := repoPathFields[0] @@ -249,16 +258,16 @@ func runServ(ctx context.Context, c *cli.Command) error { requestedMode := getAccessMode(verb, lfsVerb) - results, extra := private.ServCommand(ctx, keyID, username, reponame, requestedMode, verb, lfsVerb) + results, extra := private.ServCommand(ctx, keyID, username, reponame, groupID, requestedMode, verb, lfsVerb) if extra.HasError() { return fail(ctx, extra.UserMsg, "ServCommand failed: %s", extra.Error) } // because the original repoPath maybe redirected, we need to use the returned actual repository information if results.IsWiki { - repoPath = repo_model.RelativeWikiPath(results.OwnerName, results.RepoName) + repoPath = repo_model.RelativeWikiPath(results.OwnerName, results.RepoName, groupID) } else { - repoPath = repo_model.RelativePath(results.OwnerName, results.RepoName) + repoPath = repo_model.RelativePath(results.OwnerName, results.RepoName, groupID) } // LFS SSH protocol diff --git a/modules/private/serv.go b/modules/private/serv.go index b1dafbd81b..2d6bfb94db 100644 --- a/modules/private/serv.go +++ b/modules/private/serv.go @@ -46,10 +46,15 @@ type ServCommandResults struct { } // ServCommand preps for a serv call -func ServCommand(ctx context.Context, keyID int64, ownerName, repoName string, mode perm.AccessMode, verb, lfsVerb string) (*ServCommandResults, ResponseExtra) { - reqURL := setting.LocalURL + fmt.Sprintf("api/internal/serv/command/%d/%s/%s?mode=%d", +func ServCommand(ctx context.Context, keyID int64, ownerName, repoName string, groupID int64, mode perm.AccessMode, verb, lfsVerb string) (*ServCommandResults, ResponseExtra) { + var groupSegment string + if groupID > 0 { + groupSegment = fmt.Sprintf("%d/", groupID) + } + reqURL := setting.LocalURL + fmt.Sprintf("api/internal/serv/command/%d/%s/%s%s?mode=%d", keyID, url.PathEscape(ownerName), + groupSegment, url.PathEscape(repoName), mode, )