diff options
author | AJ ONeal <coolaj86@gmail.com> | 2021-07-28 21:39:46 -0600 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-07-29 05:39:46 +0200 |
commit | b9a0e33238da353ff39258af3f0befbb83da981e (patch) | |
tree | f2cd690133d498b966bdaf33678c786071c231a7 /routers | |
parent | 4e68d6f41d21e7c5465be6bdb6713c36eb586dfd (diff) | |
download | gitea-b9a0e33238da353ff39258af3f0befbb83da981e.tar.gz gitea-b9a0e33238da353ff39258af3f0befbb83da981e.zip |
Pre-fill suggested New File 'name' and 'content' with Query Params (#16556)
* feature: add (GitHub-style) querystrings for pre-filling new file content
* docs: add query parameters for new files
Diffstat (limited to 'routers')
-rw-r--r-- | routers/web/repo/editor.go | 9 |
1 files changed, 7 insertions, 2 deletions
diff --git a/routers/web/repo/editor.go b/routers/web/repo/editor.go index 792258da84..a99c1c7c61 100644 --- a/routers/web/repo/editor.go +++ b/routers/web/repo/editor.go @@ -81,7 +81,11 @@ func editFile(ctx *context.Context, isNewFile bool) { return } - treeNames, treePaths := getParentTreeFields(ctx.Repo.TreePath) + // Check if the filename (and additional path) is specified in the querystring + // (filename is a misnomer, but kept for compatibility with Github) + filePath, fileName := path.Split(ctx.Req.URL.Query().Get("filename")) + filePath = strings.Trim(filePath, "/") + treeNames, treePaths := getParentTreeFields(path.Join(ctx.Repo.TreePath, filePath)) if !isNewFile { entry, err := ctx.Repo.Commit.GetTreeEntryByPath(ctx.Repo.TreePath) @@ -136,7 +140,8 @@ func editFile(ctx *context.Context, isNewFile bool) { ctx.Data["FileContent"] = content } } else { - treeNames = append(treeNames, "") // Append empty string to allow user name the new file. + // Append filename from query, or empty string to allow user name the new file. + treeNames = append(treeNames, fileName) } ctx.Data["TreeNames"] = treeNames |