mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2024-11-25 08:59:31 -05:00
743d1e34ac
As the docs of codeberg refer to the strings printed by the Forgejo ssh servers, this is user-facing and is nice to update to the new product name. (cherry picked from commit103991d73f
) (cherry picked from commit2a0d3f85f1
) (cherry picked from commiteb2b4ce388
) (cherry picked from commit0998b51716
) [BRANDING] forgejo log message (cherry picked from commitd51a046ebe
) (cherry picked from commitd66e1c7b6e
) (cherry picked from commitb5bffe4ce8
) (cherry picked from commit3fa776d856
) (cherry picked from commit18d064f472
) (cherry picked from commitc95094e355
) (cherry picked from commit5784290bc4
) (cherry picked from commitaee336886b
) (cherry picked from commitec2f60b516
) (cherry picked from commit7af742a284
) (cherry picked from commitf279e2a264
) (cherry picked from commitfd38cfb14e
) (cherry picked from commit64c8226618
) (cherry picked from commitb546fb2304
) (cherry picked from commitad10202177
) (cherry picked from commitc89cab9c2b
) (cherry picked from commit9579322ec2
) (cherry picked from commit16b44ad18d
) (cherry picked from commit2571ff703b
) (cherry picked from commitad61d9ce9b
) (cherry picked from commit9b2c45d4d3
) (cherry picked from commited01b79a59
) (cherry picked from commitd040b66427
) (cherry picked from commitffe0bbea48
) (cherry picked from commit4c1b2c409b
) (cherry picked from commit3d8338ed10
) (cherry picked from commita92f044ea9
) [BRANDING] link to forgejo.org/docs instead of docs.gitea.io (cherry picked from commit3efafd0e08
) (cherry picked from commit148185e34b
) (cherry picked from commit834e264698
) (cherry picked from commite72fa6eb1e
) [BRANDING] link to forgejo.org/docs instead of docs.gitea.io Fix the link that was 404. (cherry picked from commitae515d7258
) (cherry picked from commitfacc2367f0
) (cherry picked from commit25784b9f21
) (cherry picked from commit2efc6138d9
) (cherry picked from commitb9d0871631
) (cherry picked from commitf0446e51b9
) (cherry picked from commit1638aa67fb
) (cherry picked from commit290db6a018
) (cherry picked from commit89b87cf542
) (cherry picked from commit656ed94962
) (cherry picked from commit036f879f96
) (cherry picked from commit69eea35f81
) (cherry picked from commitb72e3f4a92
) (cherry picked from commitaf606b8574
) (cherry picked from commit7e47f8135c
) (cherry picked from commit0e5218cc53
) (cherry picked from commit7c2a20a528
) (cherry picked from commit4e94006363
) (cherry picked from commite47cdfc43f
) (cherry picked from commit1dcb3e1da4
) (cherry picked from commit67367c4e0f
) (cherry picked from commit252087d1ff
) (cherry picked from commitf5977a43e5
) Conflicts: templates/base/head_navbar.tmpl https://codeberg.org/forgejo/forgejo/pulls/1351 (cherry picked from commit594938eb15
) (cherry picked from commit0257d038a7
) (cherry picked from commit72821dd140
) [BRANDING] s/gitea/forgejo/ in HTML placeholders Replaced Gitea branding with Forgejo for input placeholders Closes: #686 Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/752 (cherry picked from commit6160d37ca9
) (cherry picked from commitdf61138c7e
) (cherry picked from commit1f30566c3f
) (cherry picked from commit539bb825f5
) (cherry picked from commitbee0f66c86
) (cherry picked from commit60ad005c95
) (cherry picked from commit282e26222e
) (cherry picked from commitf9ca551f3d
) (cherry picked from commitb2e04b04c3
) (cherry picked from commitc8f395a03c
) (cherry picked from commit0d58ce49ae
) (cherry picked from commitc602ddf91e
) (cherry picked from commit029e37271e
) (cherry picked from commitfdaa96b3cc
) (cherry picked from commit515d99e27d
) (cherry picked from commitda73274ba1
) (cherry picked from commitce90b696a0
) (cherry picked from commitb6bf98763b
) (cherry picked from commit5b380d22d7
) [BRANDING] How to start a runner: URL to Actions admin documentation (cherry picked from commitda91799e6f
) (cherry picked from commit28231663b6
) (cherry picked from commit533a90345b
) (cherry picked from commit6a0e4e55dd
) (cherry picked from commitf47cd611c6
) (cherry picked from commit001264b784
) (cherry picked from commite4099e9bb9
) (cherry picked from commit3a1885649f
) (cherry picked from commitc42802c710
) (cherry picked from commita611ce8d6d
) (cherry picked from commita3d7d10a80
) (cherry picked from commit52adde671f
) (cherry picked from commitc9a3820fef
) (cherry picked from commitdce40997c9
) (cherry picked from commit312a6b92f3
) [BRANDING] package templates & links - Change Gitea to Forgejo where necessary. - Point all documentation to Forgejo's documentation. - Resolves #992 (cherry picked from commitd0b78a6ede
) (cherry picked from commite2382f30ba
) (cherry picked from commitc41cf05a33
) (cherry picked from commit797e598ae7
) (cherry picked from commit970031a1c2
) (cherry picked from commit0c1180e2e1
) Conflicts: templates/package/content/alpine.tmpl templates/package/content/cargo.tmpl templates/package/content/chef.tmpl templates/package/content/composer.tmpl templates/package/content/conan.tmpl templates/package/content/conda.tmpl templates/package/content/container.tmpl templates/package/content/cran.tmpl templates/package/content/debian.tmpl templates/package/content/generic.tmpl templates/package/content/go.tmpl templates/package/content/helm.tmpl templates/package/content/maven.tmpl templates/package/content/npm.tmpl templates/package/content/nuget.tmpl templates/package/content/pub.tmpl templates/package/content/pypi.tmpl templates/package/content/rpm.tmpl templates/package/content/rubygems.tmpl templates/package/content/swift.tmpl templates/package/content/vagrant.tmpl https://codeberg.org/forgejo/forgejo/pulls/1351 (cherry picked from commit42ac9ff2ab
) (cherry picked from commite390000bce
) (cherry picked from commit56a437b29b
) Conflicts: templates/package/content/cargo.tmpl https://codeberg.org/forgejo/forgejo/pulls/1466 [BRANDING] s/Gitea/Forgejo/ in user visible help & comments - Modify the README of the docker directory to point to the relevant docker files and documentation for Forgejo. (cherry picked from commitaca6371215
) (cherry picked from commit0ba96b1bc4
) (cherry picked from commit5c8e6b53f1
) Conflicts: docker/README.md https://codeberg.org/forgejo/forgejo/pulls/1351 (cherry picked from commitb3121c8004
) (cherry picked from commit607f870416
) (cherry picked from commit191d96afe4
) [BRANDING] healthcheck/check.go (cherry picked from commitd703a236ce
) (cherry picked from commitd84ce3ff20
) (cherry picked from commit2dbb844606
) (cherry picked from commit14d3ae7e3a
) [BRANDING] s/Gitea/Forgejo/g in CLI output (cherry picked from commit7543c126bb
) (cherry picked from commitb66f422fc3
) (cherry picked from commita81e4e46f3
) [BRANDING] Gitea->Forgejo in mailer code (cherry picked from commitb91afea4ff
) (cherry picked from commit5d7428167c
) (cherry picked from commited8101ba6c
) [BRANDING] use 'Forgejo' for Discord, Packagist, and Slack webhooks Refs: https://codeberg.org/forgejo/forgejo/issues/1387 (cherry picked from commit7dc3a05f5b
) (cherry picked from commit133f2fc6cc
) [BRANDING] cmd/manager.go (cherry picked from commitd1dba2c79d
) [BRANDING] pyproject.toml (cherry picked from commit7e8c868db2
) (cherry picked from commit2395995c8b
) (cherry picked from commitdd6fbbf332
) Conflicts: templates/package/content/cargo.tmpl https://codeberg.org/forgejo/forgejo/pulls/1548 (cherry picked from commit6f9a5d5cab
) (cherry picked from commitd0635c4a07
) (cherry picked from commit5f9a8c5744
) (cherry picked from commit10b96c4567
) (cherry picked from commit717d52e928
) (cherry picked from commit5debdb103e
) (cherry picked from commitded1c1700e
) (cherry picked from commit52aa23cf7a
) (cherry picked from commit882c942b06
) (cherry picked from commit73fc2d2ea8
) Conflicts: cmd/actions.go cmd/doctor.go cmd/keys.go https://codeberg.org/forgejo/forgejo/pulls/1976 (cherry picked from commit6180ef24dc
) (cherry picked from commit8970fa2bf8
) Conflicts: templates/package/content/debian.tmpl https://codeberg.org/forgejo/forgejo/pulls/2074 Fix a typo in docker/README.md Signed-off-by: Gergely Nagy <forgejo@gergo.csillger.hu> (cherry picked from commit2e5df79dfb
) (cherry picked from commit2bf6ce5b81
) (cherry picked from commit8ec779277d
) (cherry picked from commit6048fc66e8
) (cherry picked from commit162538c722
) (cherry picked from commit646bb99650
)
360 lines
12 KiB
Go
360 lines
12 KiB
Go
// Copyright 2014 The Gogs Authors. All rights reserved.
|
|
// Copyright 2016 The Gitea Authors. All rights reserved.
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
package cmd
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
"net/url"
|
|
"os"
|
|
"os/exec"
|
|
"path/filepath"
|
|
"regexp"
|
|
"strconv"
|
|
"strings"
|
|
"time"
|
|
"unicode"
|
|
|
|
asymkey_model "code.gitea.io/gitea/models/asymkey"
|
|
git_model "code.gitea.io/gitea/models/git"
|
|
"code.gitea.io/gitea/models/perm"
|
|
"code.gitea.io/gitea/modules/git"
|
|
"code.gitea.io/gitea/modules/json"
|
|
"code.gitea.io/gitea/modules/log"
|
|
"code.gitea.io/gitea/modules/pprof"
|
|
"code.gitea.io/gitea/modules/private"
|
|
"code.gitea.io/gitea/modules/process"
|
|
repo_module "code.gitea.io/gitea/modules/repository"
|
|
"code.gitea.io/gitea/modules/setting"
|
|
"code.gitea.io/gitea/services/lfs"
|
|
|
|
"github.com/golang-jwt/jwt/v5"
|
|
"github.com/kballard/go-shellquote"
|
|
"github.com/urfave/cli/v2"
|
|
)
|
|
|
|
const (
|
|
lfsAuthenticateVerb = "git-lfs-authenticate"
|
|
)
|
|
|
|
// CmdServ represents the available serv sub-command.
|
|
var CmdServ = &cli.Command{
|
|
Name: "serv",
|
|
Usage: "(internal) Should only be called by SSH shell",
|
|
Description: "Serv provides access auth for repositories",
|
|
Before: PrepareConsoleLoggerLevel(log.FATAL),
|
|
Action: runServ,
|
|
Flags: []cli.Flag{
|
|
&cli.BoolFlag{
|
|
Name: "enable-pprof",
|
|
},
|
|
&cli.BoolFlag{
|
|
Name: "debug",
|
|
},
|
|
},
|
|
}
|
|
|
|
func setup(ctx context.Context, debug bool) {
|
|
if debug {
|
|
setupConsoleLogger(log.TRACE, false, os.Stderr)
|
|
} else {
|
|
setupConsoleLogger(log.FATAL, false, os.Stderr)
|
|
}
|
|
setting.MustInstalled()
|
|
if debug {
|
|
setting.RunMode = "dev"
|
|
}
|
|
|
|
// Check if setting.RepoRootPath exists. It could be the case that it doesn't exist, this can happen when
|
|
// `[repository]` `ROOT` is a relative path and $GITEA_WORK_DIR isn't passed to the SSH connection.
|
|
if _, err := os.Stat(setting.RepoRootPath); err != nil {
|
|
if os.IsNotExist(err) {
|
|
_ = fail(ctx, "Incorrect configuration, no repository directory.", "Directory `[repository].ROOT` %q was not found, please check if $GITEA_WORK_DIR is passed to the SSH connection or make `[repository].ROOT` an absolute value.", setting.RepoRootPath)
|
|
} else {
|
|
_ = fail(ctx, "Incorrect configuration, repository directory is inaccessible", "Directory `[repository].ROOT` %q is inaccessible. err: %v", setting.RepoRootPath, err)
|
|
}
|
|
return
|
|
}
|
|
|
|
if err := git.InitSimple(context.Background()); err != nil {
|
|
_ = fail(ctx, "Failed to init git", "Failed to init git, err: %v", err)
|
|
}
|
|
}
|
|
|
|
var (
|
|
allowedCommands = map[string]perm.AccessMode{
|
|
"git-upload-pack": perm.AccessModeRead,
|
|
"git-upload-archive": perm.AccessModeRead,
|
|
"git-receive-pack": perm.AccessModeWrite,
|
|
lfsAuthenticateVerb: perm.AccessModeNone,
|
|
}
|
|
alphaDashDotPattern = regexp.MustCompile(`[^\w-\.]`)
|
|
)
|
|
|
|
// fail prints message to stdout, it's mainly used for git serv and git hook commands.
|
|
// The output will be passed to git client and shown to user.
|
|
func fail(ctx context.Context, userMessage, logMsgFmt string, args ...any) error {
|
|
if userMessage == "" {
|
|
userMessage = "Internal Server Error (no specific error)"
|
|
}
|
|
|
|
// There appears to be a chance to cause a zombie process and failure to read the Exit status
|
|
// if nothing is outputted on stdout.
|
|
_, _ = fmt.Fprintln(os.Stdout, "")
|
|
_, _ = fmt.Fprintln(os.Stderr, "Forgejo:", userMessage)
|
|
|
|
if logMsgFmt != "" {
|
|
logMsg := fmt.Sprintf(logMsgFmt, args...)
|
|
if !setting.IsProd {
|
|
_, _ = fmt.Fprintln(os.Stderr, "Forgejo:", logMsg)
|
|
}
|
|
if userMessage != "" {
|
|
if unicode.IsPunct(rune(userMessage[len(userMessage)-1])) {
|
|
logMsg = userMessage + " " + logMsg
|
|
} else {
|
|
logMsg = userMessage + ". " + logMsg
|
|
}
|
|
}
|
|
_ = private.SSHLog(ctx, true, logMsg)
|
|
}
|
|
return cli.Exit("", 1)
|
|
}
|
|
|
|
// handleCliResponseExtra handles the extra response from the cli sub-commands
|
|
// If there is a user message it will be printed to stdout
|
|
// If the command failed it will return an error (the error will be printed by cli framework)
|
|
func handleCliResponseExtra(extra private.ResponseExtra) error {
|
|
if extra.UserMsg != "" {
|
|
_, _ = fmt.Fprintln(os.Stdout, extra.UserMsg)
|
|
}
|
|
if extra.HasError() {
|
|
return cli.Exit(extra.Error, 1)
|
|
}
|
|
return nil
|
|
}
|
|
|
|
func runServ(c *cli.Context) error {
|
|
ctx, cancel := installSignals()
|
|
defer cancel()
|
|
|
|
// FIXME: This needs to internationalised
|
|
setup(ctx, c.Bool("debug"))
|
|
|
|
if setting.SSH.Disabled {
|
|
println("Forgejo: SSH has been disabled")
|
|
return nil
|
|
}
|
|
|
|
if c.NArg() < 1 {
|
|
if err := cli.ShowSubcommandHelp(c); err != nil {
|
|
fmt.Printf("error showing subcommand help: %v\n", err)
|
|
}
|
|
return nil
|
|
}
|
|
|
|
keys := strings.Split(c.Args().First(), "-")
|
|
if len(keys) != 2 || keys[0] != "key" {
|
|
return fail(ctx, "Key ID format error", "Invalid key argument: %s", c.Args().First())
|
|
}
|
|
keyID, err := strconv.ParseInt(keys[1], 10, 64)
|
|
if err != nil {
|
|
return fail(ctx, "Key ID parsing error", "Invalid key argument: %s", c.Args().Get(1))
|
|
}
|
|
|
|
cmd := os.Getenv("SSH_ORIGINAL_COMMAND")
|
|
if len(cmd) == 0 {
|
|
key, user, err := private.ServNoCommand(ctx, keyID)
|
|
if err != nil {
|
|
return fail(ctx, "Key check failed", "Failed to check provided key: %v", err)
|
|
}
|
|
switch key.Type {
|
|
case asymkey_model.KeyTypeDeploy:
|
|
println("Hi there! You've successfully authenticated with the deploy key named " + key.Name + ", but Forgejo does not provide shell access.")
|
|
case asymkey_model.KeyTypePrincipal:
|
|
println("Hi there! You've successfully authenticated with the principal " + key.Content + ", but Forgejo does not provide shell access.")
|
|
default:
|
|
println("Hi there, " + user.Name + "! You've successfully authenticated with the key named " + key.Name + ", but Forgejo does not provide shell access.")
|
|
}
|
|
println("If this is unexpected, please log in with password and setup Forgejo under another user.")
|
|
return nil
|
|
} else if c.Bool("debug") {
|
|
log.Debug("SSH_ORIGINAL_COMMAND: %s", os.Getenv("SSH_ORIGINAL_COMMAND"))
|
|
}
|
|
|
|
words, err := shellquote.Split(cmd)
|
|
if err != nil {
|
|
return fail(ctx, "Error parsing arguments", "Failed to parse arguments: %v", err)
|
|
}
|
|
|
|
if len(words) < 2 {
|
|
if git.CheckGitVersionAtLeast("2.29") == nil {
|
|
// for AGit Flow
|
|
if cmd == "ssh_info" {
|
|
fmt.Print(`{"type":"gitea","version":1}`)
|
|
return nil
|
|
}
|
|
}
|
|
return fail(ctx, "Too few arguments", "Too few arguments in cmd: %s", cmd)
|
|
}
|
|
|
|
verb := words[0]
|
|
repoPath := words[1]
|
|
if repoPath[0] == '/' {
|
|
repoPath = repoPath[1:]
|
|
}
|
|
|
|
var lfsVerb string
|
|
if verb == lfsAuthenticateVerb {
|
|
if !setting.LFS.StartServer {
|
|
return fail(ctx, "Unknown git command", "LFS authentication request over SSH denied, LFS support is disabled")
|
|
}
|
|
|
|
if len(words) > 2 {
|
|
lfsVerb = words[2]
|
|
}
|
|
}
|
|
|
|
// LowerCase and trim the repoPath as that's how they are stored.
|
|
repoPath = strings.ToLower(strings.TrimSpace(repoPath))
|
|
|
|
rr := strings.SplitN(repoPath, "/", 2)
|
|
if len(rr) != 2 {
|
|
return fail(ctx, "Invalid repository path", "Invalid repository path: %v", repoPath)
|
|
}
|
|
|
|
username := strings.ToLower(rr[0])
|
|
reponame := strings.ToLower(strings.TrimSuffix(rr[1], ".git"))
|
|
|
|
if alphaDashDotPattern.MatchString(reponame) {
|
|
return fail(ctx, "Invalid repo name", "Invalid repo name: %s", reponame)
|
|
}
|
|
|
|
if c.Bool("enable-pprof") {
|
|
if err := os.MkdirAll(setting.PprofDataPath, os.ModePerm); err != nil {
|
|
return fail(ctx, "Error while trying to create PPROF_DATA_PATH", "Error while trying to create PPROF_DATA_PATH: %v", err)
|
|
}
|
|
|
|
stopCPUProfiler, err := pprof.DumpCPUProfileForUsername(setting.PprofDataPath, username)
|
|
if err != nil {
|
|
return fail(ctx, "Unable to start CPU profiler", "Unable to start CPU profile: %v", err)
|
|
}
|
|
defer func() {
|
|
stopCPUProfiler()
|
|
err := pprof.DumpMemProfileForUsername(setting.PprofDataPath, username)
|
|
if err != nil {
|
|
_ = fail(ctx, "Unable to dump Mem profile", "Unable to dump Mem Profile: %v", err)
|
|
}
|
|
}()
|
|
}
|
|
|
|
requestedMode, has := allowedCommands[verb]
|
|
if !has {
|
|
return fail(ctx, "Unknown git command", "Unknown git command %s", verb)
|
|
}
|
|
|
|
if verb == lfsAuthenticateVerb {
|
|
if lfsVerb == "upload" {
|
|
requestedMode = perm.AccessModeWrite
|
|
} else if lfsVerb == "download" {
|
|
requestedMode = perm.AccessModeRead
|
|
} else {
|
|
return fail(ctx, "Unknown LFS verb", "Unknown lfs verb %s", lfsVerb)
|
|
}
|
|
}
|
|
|
|
results, extra := private.ServCommand(ctx, keyID, username, reponame, requestedMode, verb, lfsVerb)
|
|
if extra.HasError() {
|
|
return fail(ctx, extra.UserMsg, "ServCommand failed: %s", extra.Error)
|
|
}
|
|
|
|
// LFS token authentication
|
|
if verb == lfsAuthenticateVerb {
|
|
url := fmt.Sprintf("%s%s/%s.git/info/lfs", setting.AppURL, url.PathEscape(results.OwnerName), url.PathEscape(results.RepoName))
|
|
|
|
now := time.Now()
|
|
claims := lfs.Claims{
|
|
RegisteredClaims: jwt.RegisteredClaims{
|
|
ExpiresAt: jwt.NewNumericDate(now.Add(setting.LFS.HTTPAuthExpiry)),
|
|
NotBefore: jwt.NewNumericDate(now),
|
|
},
|
|
RepoID: results.RepoID,
|
|
Op: lfsVerb,
|
|
UserID: results.UserID,
|
|
}
|
|
token := jwt.NewWithClaims(jwt.SigningMethodHS256, claims)
|
|
|
|
// Sign and get the complete encoded token as a string using the secret
|
|
tokenString, err := token.SignedString(setting.LFS.JWTSecretBytes)
|
|
if err != nil {
|
|
return fail(ctx, "Failed to sign JWT Token", "Failed to sign JWT token: %v", err)
|
|
}
|
|
|
|
tokenAuthentication := &git_model.LFSTokenResponse{
|
|
Header: make(map[string]string),
|
|
Href: url,
|
|
}
|
|
tokenAuthentication.Header["Authorization"] = fmt.Sprintf("Bearer %s", tokenString)
|
|
|
|
enc := json.NewEncoder(os.Stdout)
|
|
err = enc.Encode(tokenAuthentication)
|
|
if err != nil {
|
|
return fail(ctx, "Failed to encode LFS json response", "Failed to encode LFS json response: %v", err)
|
|
}
|
|
return nil
|
|
}
|
|
|
|
var gitcmd *exec.Cmd
|
|
gitBinPath := filepath.Dir(git.GitExecutable) // e.g. /usr/bin
|
|
gitBinVerb := filepath.Join(gitBinPath, verb) // e.g. /usr/bin/git-upload-pack
|
|
if _, err := os.Stat(gitBinVerb); err != nil {
|
|
// if the command "git-upload-pack" doesn't exist, try to split "git-upload-pack" to use the sub-command with git
|
|
// ps: Windows only has "git.exe" in the bin path, so Windows always uses this way
|
|
verbFields := strings.SplitN(verb, "-", 2)
|
|
if len(verbFields) == 2 {
|
|
// use git binary with the sub-command part: "C:\...\bin\git.exe", "upload-pack", ...
|
|
gitcmd = exec.CommandContext(ctx, git.GitExecutable, verbFields[1], repoPath)
|
|
}
|
|
}
|
|
if gitcmd == nil {
|
|
// by default, use the verb (it has been checked above by allowedCommands)
|
|
gitcmd = exec.CommandContext(ctx, gitBinVerb, repoPath)
|
|
}
|
|
|
|
process.SetSysProcAttribute(gitcmd)
|
|
gitcmd.Dir = setting.RepoRootPath
|
|
gitcmd.Stdout = os.Stdout
|
|
gitcmd.Stdin = os.Stdin
|
|
gitcmd.Stderr = os.Stderr
|
|
gitcmd.Env = append(gitcmd.Env, os.Environ()...)
|
|
gitcmd.Env = append(gitcmd.Env,
|
|
repo_module.EnvRepoIsWiki+"="+strconv.FormatBool(results.IsWiki),
|
|
repo_module.EnvRepoName+"="+results.RepoName,
|
|
repo_module.EnvRepoUsername+"="+results.OwnerName,
|
|
repo_module.EnvPusherName+"="+results.UserName,
|
|
repo_module.EnvPusherEmail+"="+results.UserEmail,
|
|
repo_module.EnvPusherID+"="+strconv.FormatInt(results.UserID, 10),
|
|
repo_module.EnvRepoID+"="+strconv.FormatInt(results.RepoID, 10),
|
|
repo_module.EnvPRID+"="+fmt.Sprintf("%d", 0),
|
|
repo_module.EnvDeployKeyID+"="+fmt.Sprintf("%d", results.DeployKeyID),
|
|
repo_module.EnvKeyID+"="+fmt.Sprintf("%d", results.KeyID),
|
|
repo_module.EnvAppURL+"="+setting.AppURL,
|
|
)
|
|
// to avoid breaking, here only use the minimal environment variables for the "gitea serv" command.
|
|
// it could be re-considered whether to use the same git.CommonGitCmdEnvs() as "git" command later.
|
|
gitcmd.Env = append(gitcmd.Env, git.CommonCmdServEnvs()...)
|
|
|
|
if err = gitcmd.Run(); err != nil {
|
|
return fail(ctx, "Failed to execute git command", "Failed to execute git command: %v", err)
|
|
}
|
|
|
|
// Update user key activity.
|
|
if results.KeyID > 0 {
|
|
if err = private.UpdatePublicKeyInRepo(ctx, results.KeyID, results.RepoID); err != nil {
|
|
return fail(ctx, "Failed to update public key", "UpdatePublicKeyInRepo: %v", err)
|
|
}
|
|
}
|
|
|
|
return nil
|
|
}
|