mirror of
https://github.com/go-gitea/gitea.git
synced 2025-02-02 15:09:33 -05:00
fix
This commit is contained in:
parent
06c5f30fc4
commit
cab9bbccf2
@ -40,35 +40,41 @@ func syncGitConfig() (err error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Set git some configurations - these must be set to these values for gitea to work correctly
|
// Set git some configurations - these must be set to these values for gitea to work correctly
|
||||||
if err := configSet("core.quotePath", "false"); err != nil {
|
if err = configSet("core.quotePath", "false"); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
if DefaultFeatures().CheckVersionAtLeast("2.10") {
|
if DefaultFeatures().CheckVersionAtLeast("2.10") {
|
||||||
if err := configSet("receive.advertisePushOptions", "true"); err != nil {
|
if err = configSet("receive.advertisePushOptions", "true"); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if DefaultFeatures().CheckVersionAtLeast("2.18") {
|
if DefaultFeatures().CheckVersionAtLeast("2.18") {
|
||||||
if err := configSet("core.commitGraph", "true"); err != nil {
|
if err = configSet("core.commitGraph", "true"); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if err := configSet("gc.writeCommitGraph", "true"); err != nil {
|
if err = configSet("gc.writeCommitGraph", "true"); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if err := configSet("fetch.writeCommitGraph", "true"); err != nil {
|
if err = configSet("fetch.writeCommitGraph", "true"); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if DefaultFeatures().SupportProcReceive {
|
if DefaultFeatures().SupportProcReceive {
|
||||||
// set support for AGit flow
|
// set support for AGit flow
|
||||||
if err := configAddNonExist("receive.procReceiveRefs", "refs/for"); err != nil {
|
if err = configAddNonExist("receive.procReceiveRefs", "refs/for"); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if err = configAddNonExist("receive.procReceiveRefs", "refs/for-review"); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if err := configUnsetAll("receive.procReceiveRefs", "refs/for"); err != nil {
|
if err = configUnsetAll("receive.procReceiveRefs", "refs/for"); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if err = configUnsetAll("receive.procReceiveRefs", "refs/for-review"); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -11,7 +11,6 @@ import (
|
|||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"regexp"
|
|
||||||
"runtime"
|
"runtime"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
@ -219,187 +218,3 @@ func InitFull(ctx context.Context) (err error) {
|
|||||||
|
|
||||||
return syncGitConfig()
|
return syncGitConfig()
|
||||||
}
|
}
|
||||||
|
|
||||||
// syncGitConfig only modifies gitconfig, won't change global variables (otherwise there will be data-race problem)
|
|
||||||
func syncGitConfig() (err error) {
|
|
||||||
if err = os.MkdirAll(HomeDir(), os.ModePerm); err != nil {
|
|
||||||
return fmt.Errorf("unable to prepare git home directory %s, err: %w", HomeDir(), err)
|
|
||||||
}
|
|
||||||
|
|
||||||
// first, write user's git config options to git config file
|
|
||||||
// user config options could be overwritten by builtin values later, because if a value is builtin, it must have some special purposes
|
|
||||||
for k, v := range setting.GitConfig.Options {
|
|
||||||
if err = configSet(strings.ToLower(k), v); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Git requires setting user.name and user.email in order to commit changes - old comment: "if they're not set just add some defaults"
|
|
||||||
// TODO: need to confirm whether users really need to change these values manually. It seems that these values are dummy only and not really used.
|
|
||||||
// If these values are not really used, then they can be set (overwritten) directly without considering about existence.
|
|
||||||
for configKey, defaultValue := range map[string]string{
|
|
||||||
"user.name": "Gitea",
|
|
||||||
"user.email": "gitea@fake.local",
|
|
||||||
} {
|
|
||||||
if err := configSetNonExist(configKey, defaultValue); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Set git some configurations - these must be set to these values for gitea to work correctly
|
|
||||||
if err := configSet("core.quotePath", "false"); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
if DefaultFeatures().CheckVersionAtLeast("2.10") {
|
|
||||||
if err := configSet("receive.advertisePushOptions", "true"); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if DefaultFeatures().CheckVersionAtLeast("2.18") {
|
|
||||||
if err := configSet("core.commitGraph", "true"); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
if err := configSet("gc.writeCommitGraph", "true"); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
if err := configSet("fetch.writeCommitGraph", "true"); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if DefaultFeatures().SupportProcReceive {
|
|
||||||
// set support for AGit flow
|
|
||||||
if err := configAddNonExist("receive.procReceiveRefs", "refs/for"); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
if err := configAddNonExist("receive.procReceiveRefs", "refs/for-review"); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
if err := configUnsetAll("receive.procReceiveRefs", "refs/for"); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
if err := configUnsetAll("receive.procReceiveRefs", "refs/for-review"); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Due to CVE-2022-24765, git now denies access to git directories which are not owned by current user.
|
|
||||||
// However, some docker users and samba users find it difficult to configure their systems correctly,
|
|
||||||
// so that Gitea's git repositories are owned by the Gitea user.
|
|
||||||
// (Possibly Windows Service users - but ownership in this case should really be set correctly on the filesystem.)
|
|
||||||
// See issue: https://github.com/go-gitea/gitea/issues/19455
|
|
||||||
// As Gitea now always use its internal git config file, and access to the git repositories is managed through Gitea,
|
|
||||||
// it is now safe to set "safe.directory=*" for internal usage only.
|
|
||||||
// Although this setting is only supported by some new git versions, it is also tolerated by earlier versions
|
|
||||||
if err := configAddNonExist("safe.directory", "*"); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
if runtime.GOOS == "windows" {
|
|
||||||
if err := configSet("core.longpaths", "true"); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
if setting.Git.DisableCoreProtectNTFS {
|
|
||||||
err = configSet("core.protectNTFS", "false")
|
|
||||||
} else {
|
|
||||||
err = configUnsetAll("core.protectNTFS", "false")
|
|
||||||
}
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// By default partial clones are disabled, enable them from git v2.22
|
|
||||||
if !setting.Git.DisablePartialClone && DefaultFeatures().CheckVersionAtLeast("2.22") {
|
|
||||||
if err = configSet("uploadpack.allowfilter", "true"); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
err = configSet("uploadpack.allowAnySHA1InWant", "true")
|
|
||||||
} else {
|
|
||||||
if err = configUnsetAll("uploadpack.allowfilter", "true"); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
err = configUnsetAll("uploadpack.allowAnySHA1InWant", "true")
|
|
||||||
}
|
|
||||||
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
func configSet(key, value string) error {
|
|
||||||
stdout, _, err := NewCommand(DefaultContext, "config", "--global", "--get").AddDynamicArguments(key).RunStdString(nil)
|
|
||||||
if err != nil && !IsErrorExitCode(err, 1) {
|
|
||||||
return fmt.Errorf("failed to get git config %s, err: %w", key, err)
|
|
||||||
}
|
|
||||||
|
|
||||||
currValue := strings.TrimSpace(stdout)
|
|
||||||
if currValue == value {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
_, _, err = NewCommand(DefaultContext, "config", "--global").AddDynamicArguments(key, value).RunStdString(nil)
|
|
||||||
if err != nil {
|
|
||||||
return fmt.Errorf("failed to set git global config %s, err: %w", key, err)
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func configSetNonExist(key, value string) error {
|
|
||||||
_, _, err := NewCommand(DefaultContext, "config", "--global", "--get").AddDynamicArguments(key).RunStdString(nil)
|
|
||||||
if err == nil {
|
|
||||||
// already exist
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
if IsErrorExitCode(err, 1) {
|
|
||||||
// not exist, set new config
|
|
||||||
_, _, err = NewCommand(DefaultContext, "config", "--global").AddDynamicArguments(key, value).RunStdString(nil)
|
|
||||||
if err != nil {
|
|
||||||
return fmt.Errorf("failed to set git global config %s, err: %w", key, err)
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
return fmt.Errorf("failed to get git config %s, err: %w", key, err)
|
|
||||||
}
|
|
||||||
|
|
||||||
func configAddNonExist(key, value string) error {
|
|
||||||
_, _, err := NewCommand(DefaultContext, "config", "--global", "--get").AddDynamicArguments(key, regexp.QuoteMeta(value)).RunStdString(nil)
|
|
||||||
if err == nil {
|
|
||||||
// already exist
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
if IsErrorExitCode(err, 1) {
|
|
||||||
// not exist, add new config
|
|
||||||
_, _, err = NewCommand(DefaultContext, "config", "--global", "--add").AddDynamicArguments(key, value).RunStdString(nil)
|
|
||||||
if err != nil {
|
|
||||||
return fmt.Errorf("failed to add git global config %s, err: %w", key, err)
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
return fmt.Errorf("failed to get git config %s, err: %w", key, err)
|
|
||||||
}
|
|
||||||
|
|
||||||
func configUnsetAll(key, value string) error {
|
|
||||||
_, _, err := NewCommand(DefaultContext, "config", "--global", "--get").AddDynamicArguments(key).RunStdString(nil)
|
|
||||||
if err == nil {
|
|
||||||
// exist, need to remove
|
|
||||||
_, _, err = NewCommand(DefaultContext, "config", "--global", "--unset-all").AddDynamicArguments(key, regexp.QuoteMeta(value)).RunStdString(nil)
|
|
||||||
if err != nil {
|
|
||||||
return fmt.Errorf("failed to unset git global config %s, err: %w", key, err)
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
if IsErrorExitCode(err, 1) {
|
|
||||||
// not exist
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
return fmt.Errorf("failed to get git config %s, err: %w", key, err)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Fsck verifies the connectivity and validity of the objects in the database
|
|
||||||
func Fsck(ctx context.Context, repoPath string, timeout time.Duration, args TrustedCmdArgs) error {
|
|
||||||
return NewCommand(ctx, "fsck").AddArguments(args...).Run(&RunOpts{Timeout: timeout, Dir: repoPath})
|
|
||||||
}
|
|
||||||
|
@ -153,7 +153,7 @@ func ProcReceive(ctx context.Context, repo *repo_model.Repository, gitRepo *git.
|
|||||||
pr: pull,
|
pr: pull,
|
||||||
gitRepo: gitRepo,
|
gitRepo: gitRepo,
|
||||||
repo: repo,
|
repo: repo,
|
||||||
forcePush: forcePush,
|
forcePush: forcePush.Value(),
|
||||||
pusher: pusher,
|
pusher: pusher,
|
||||||
RefFullName: opts.RefFullNames[i],
|
RefFullName: opts.RefFullNames[i],
|
||||||
OldCommitID: opts.OldCommitIDs[i],
|
OldCommitID: opts.OldCommitIDs[i],
|
||||||
@ -287,46 +287,13 @@ func ProcReceive(ctx context.Context, repo *repo_model.Repository, gitRepo *git.
|
|||||||
pr: pr,
|
pr: pr,
|
||||||
gitRepo: gitRepo,
|
gitRepo: gitRepo,
|
||||||
repo: repo,
|
repo: repo,
|
||||||
forcePush: forcePush,
|
forcePush: forcePush.Value(),
|
||||||
pusher: pusher,
|
pusher: pusher,
|
||||||
RefFullName: opts.RefFullNames[i],
|
RefFullName: opts.RefFullNames[i],
|
||||||
OldCommitID: opts.OldCommitIDs[i],
|
OldCommitID: opts.OldCommitIDs[i],
|
||||||
NewCommitID: opts.NewCommitIDs[i],
|
NewCommitID: opts.NewCommitIDs[i],
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("unable to get ref commit id in base repository for PR[%d] Error: %w", pr.ID, err)
|
|
||||||
}
|
|
||||||
|
|
||||||
if oldCommitID == opts.NewCommitIDs[i] {
|
|
||||||
results = append(results, private.HookProcReceiveRefResult{
|
|
||||||
OriginalRef: opts.RefFullNames[i],
|
|
||||||
OldOID: opts.OldCommitIDs[i],
|
|
||||||
NewOID: opts.NewCommitIDs[i],
|
|
||||||
Err: "new commit is same with old commit",
|
|
||||||
})
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
if !forcePush.Value() {
|
|
||||||
output, _, err := git.NewCommand(ctx, "rev-list", "--max-count=1").
|
|
||||||
AddDynamicArguments(oldCommitID, "^"+opts.NewCommitIDs[i]).
|
|
||||||
RunStdString(&git.RunOpts{Dir: repo.RepoPath(), Env: os.Environ()})
|
|
||||||
if err != nil {
|
|
||||||
return nil, fmt.Errorf("failed to detect force push: %w", err)
|
|
||||||
} else if len(output) > 0 {
|
|
||||||
results = append(results, private.HookProcReceiveRefResult{
|
|
||||||
OriginalRef: opts.RefFullNames[i],
|
|
||||||
OldOID: opts.OldCommitIDs[i],
|
|
||||||
NewOID: opts.NewCommitIDs[i],
|
|
||||||
Err: "request `force-push` push option",
|
|
||||||
})
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pr.HeadCommitID = opts.NewCommitIDs[i]
|
|
||||||
if err = pull_service.UpdateRef(ctx, pr); err != nil {
|
|
||||||
return nil, fmt.Errorf("failed to update pull ref. Error: %w", err)
|
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
results = append(results, *result)
|
results = append(results, *result)
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
{{if and .Issue.IsPull .IsIssuePoster (not .Issue.IsClosed) .Issue.PullRequest.HeadRepo}}
|
{{if and .Issue.IsPull .IsIssuePoster (not .Issue.IsClosed) .Issue.PullRequest.HeadRepo}}
|
||||||
{{if and (not (eq .Issue.PullRequest.HeadRepo.FullName .Issue.PullRequest.BaseRepo.FullName)) .CanWriteToHeadRepo}}
|
{{if or (eq .SignedUserID .Issue.PosterID) (and (not (eq .Issue.PullRequest.HeadRepo.FullName .Issue.PullRequest.BaseRepo.FullName)) .CanWriteToHeadRepo)}}
|
||||||
<div class="divider"></div>
|
<div class="divider"></div>
|
||||||
<div class="ui checkbox loading-icon-2px" id="allow-edits-from-maintainers"
|
<div class="ui checkbox loading-icon-2px" id="allow-edits-from-maintainers"
|
||||||
data-url="{{.Issue.Link}}"
|
data-url="{{.Issue.Link}}"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user