Skip to content

Commit cab9bbc

Browse files
committed
fix
1 parent 06c5f30 commit cab9bbc

File tree

4 files changed

+16
-228
lines changed

4 files changed

+16
-228
lines changed

modules/git/config.go

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -40,35 +40,41 @@ func syncGitConfig() (err error) {
4040
}
4141

4242
// Set git some configurations - these must be set to these values for gitea to work correctly
43-
if err := configSet("core.quotePath", "false"); err != nil {
43+
if err = configSet("core.quotePath", "false"); err != nil {
4444
return err
4545
}
4646

4747
if DefaultFeatures().CheckVersionAtLeast("2.10") {
48-
if err := configSet("receive.advertisePushOptions", "true"); err != nil {
48+
if err = configSet("receive.advertisePushOptions", "true"); err != nil {
4949
return err
5050
}
5151
}
5252

5353
if DefaultFeatures().CheckVersionAtLeast("2.18") {
54-
if err := configSet("core.commitGraph", "true"); err != nil {
54+
if err = configSet("core.commitGraph", "true"); err != nil {
5555
return err
5656
}
57-
if err := configSet("gc.writeCommitGraph", "true"); err != nil {
57+
if err = configSet("gc.writeCommitGraph", "true"); err != nil {
5858
return err
5959
}
60-
if err := configSet("fetch.writeCommitGraph", "true"); err != nil {
60+
if err = configSet("fetch.writeCommitGraph", "true"); err != nil {
6161
return err
6262
}
6363
}
6464

6565
if DefaultFeatures().SupportProcReceive {
6666
// set support for AGit flow
67-
if err := configAddNonExist("receive.procReceiveRefs", "refs/for"); err != nil {
67+
if err = configAddNonExist("receive.procReceiveRefs", "refs/for"); err != nil {
68+
return err
69+
}
70+
if err = configAddNonExist("receive.procReceiveRefs", "refs/for-review"); err != nil {
6871
return err
6972
}
7073
} else {
71-
if err := configUnsetAll("receive.procReceiveRefs", "refs/for"); err != nil {
74+
if err = configUnsetAll("receive.procReceiveRefs", "refs/for"); err != nil {
75+
return err
76+
}
77+
if err = configUnsetAll("receive.procReceiveRefs", "refs/for-review"); err != nil {
7278
return err
7379
}
7480
}

modules/git/git.go

Lines changed: 0 additions & 185 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import (
1111
"os"
1212
"os/exec"
1313
"path/filepath"
14-
"regexp"
1514
"runtime"
1615
"strings"
1716
"time"
@@ -219,187 +218,3 @@ func InitFull(ctx context.Context) (err error) {
219218

220219
return syncGitConfig()
221220
}
222-
223-
// syncGitConfig only modifies gitconfig, won't change global variables (otherwise there will be data-race problem)
224-
func syncGitConfig() (err error) {
225-
if err = os.MkdirAll(HomeDir(), os.ModePerm); err != nil {
226-
return fmt.Errorf("unable to prepare git home directory %s, err: %w", HomeDir(), err)
227-
}
228-
229-
// first, write user's git config options to git config file
230-
// user config options could be overwritten by builtin values later, because if a value is builtin, it must have some special purposes
231-
for k, v := range setting.GitConfig.Options {
232-
if err = configSet(strings.ToLower(k), v); err != nil {
233-
return err
234-
}
235-
}
236-
237-
// Git requires setting user.name and user.email in order to commit changes - old comment: "if they're not set just add some defaults"
238-
// 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.
239-
// If these values are not really used, then they can be set (overwritten) directly without considering about existence.
240-
for configKey, defaultValue := range map[string]string{
241-
"user.name": "Gitea",
242-
"user.email": "[email protected]",
243-
} {
244-
if err := configSetNonExist(configKey, defaultValue); err != nil {
245-
return err
246-
}
247-
}
248-
249-
// Set git some configurations - these must be set to these values for gitea to work correctly
250-
if err := configSet("core.quotePath", "false"); err != nil {
251-
return err
252-
}
253-
254-
if DefaultFeatures().CheckVersionAtLeast("2.10") {
255-
if err := configSet("receive.advertisePushOptions", "true"); err != nil {
256-
return err
257-
}
258-
}
259-
260-
if DefaultFeatures().CheckVersionAtLeast("2.18") {
261-
if err := configSet("core.commitGraph", "true"); err != nil {
262-
return err
263-
}
264-
if err := configSet("gc.writeCommitGraph", "true"); err != nil {
265-
return err
266-
}
267-
if err := configSet("fetch.writeCommitGraph", "true"); err != nil {
268-
return err
269-
}
270-
}
271-
272-
if DefaultFeatures().SupportProcReceive {
273-
// set support for AGit flow
274-
if err := configAddNonExist("receive.procReceiveRefs", "refs/for"); err != nil {
275-
return err
276-
}
277-
if err := configAddNonExist("receive.procReceiveRefs", "refs/for-review"); err != nil {
278-
return err
279-
}
280-
} else {
281-
if err := configUnsetAll("receive.procReceiveRefs", "refs/for"); err != nil {
282-
return err
283-
}
284-
if err := configUnsetAll("receive.procReceiveRefs", "refs/for-review"); err != nil {
285-
return err
286-
}
287-
}
288-
289-
// Due to CVE-2022-24765, git now denies access to git directories which are not owned by current user.
290-
// However, some docker users and samba users find it difficult to configure their systems correctly,
291-
// so that Gitea's git repositories are owned by the Gitea user.
292-
// (Possibly Windows Service users - but ownership in this case should really be set correctly on the filesystem.)
293-
// See issue: https://github.com/go-gitea/gitea/issues/19455
294-
// As Gitea now always use its internal git config file, and access to the git repositories is managed through Gitea,
295-
// it is now safe to set "safe.directory=*" for internal usage only.
296-
// Although this setting is only supported by some new git versions, it is also tolerated by earlier versions
297-
if err := configAddNonExist("safe.directory", "*"); err != nil {
298-
return err
299-
}
300-
301-
if runtime.GOOS == "windows" {
302-
if err := configSet("core.longpaths", "true"); err != nil {
303-
return err
304-
}
305-
if setting.Git.DisableCoreProtectNTFS {
306-
err = configSet("core.protectNTFS", "false")
307-
} else {
308-
err = configUnsetAll("core.protectNTFS", "false")
309-
}
310-
if err != nil {
311-
return err
312-
}
313-
}
314-
315-
// By default partial clones are disabled, enable them from git v2.22
316-
if !setting.Git.DisablePartialClone && DefaultFeatures().CheckVersionAtLeast("2.22") {
317-
if err = configSet("uploadpack.allowfilter", "true"); err != nil {
318-
return err
319-
}
320-
err = configSet("uploadpack.allowAnySHA1InWant", "true")
321-
} else {
322-
if err = configUnsetAll("uploadpack.allowfilter", "true"); err != nil {
323-
return err
324-
}
325-
err = configUnsetAll("uploadpack.allowAnySHA1InWant", "true")
326-
}
327-
328-
return err
329-
}
330-
331-
func configSet(key, value string) error {
332-
stdout, _, err := NewCommand(DefaultContext, "config", "--global", "--get").AddDynamicArguments(key).RunStdString(nil)
333-
if err != nil && !IsErrorExitCode(err, 1) {
334-
return fmt.Errorf("failed to get git config %s, err: %w", key, err)
335-
}
336-
337-
currValue := strings.TrimSpace(stdout)
338-
if currValue == value {
339-
return nil
340-
}
341-
342-
_, _, err = NewCommand(DefaultContext, "config", "--global").AddDynamicArguments(key, value).RunStdString(nil)
343-
if err != nil {
344-
return fmt.Errorf("failed to set git global config %s, err: %w", key, err)
345-
}
346-
347-
return nil
348-
}
349-
350-
func configSetNonExist(key, value string) error {
351-
_, _, err := NewCommand(DefaultContext, "config", "--global", "--get").AddDynamicArguments(key).RunStdString(nil)
352-
if err == nil {
353-
// already exist
354-
return nil
355-
}
356-
if IsErrorExitCode(err, 1) {
357-
// not exist, set new config
358-
_, _, err = NewCommand(DefaultContext, "config", "--global").AddDynamicArguments(key, value).RunStdString(nil)
359-
if err != nil {
360-
return fmt.Errorf("failed to set git global config %s, err: %w", key, err)
361-
}
362-
return nil
363-
}
364-
365-
return fmt.Errorf("failed to get git config %s, err: %w", key, err)
366-
}
367-
368-
func configAddNonExist(key, value string) error {
369-
_, _, err := NewCommand(DefaultContext, "config", "--global", "--get").AddDynamicArguments(key, regexp.QuoteMeta(value)).RunStdString(nil)
370-
if err == nil {
371-
// already exist
372-
return nil
373-
}
374-
if IsErrorExitCode(err, 1) {
375-
// not exist, add new config
376-
_, _, err = NewCommand(DefaultContext, "config", "--global", "--add").AddDynamicArguments(key, value).RunStdString(nil)
377-
if err != nil {
378-
return fmt.Errorf("failed to add git global config %s, err: %w", key, err)
379-
}
380-
return nil
381-
}
382-
return fmt.Errorf("failed to get git config %s, err: %w", key, err)
383-
}
384-
385-
func configUnsetAll(key, value string) error {
386-
_, _, err := NewCommand(DefaultContext, "config", "--global", "--get").AddDynamicArguments(key).RunStdString(nil)
387-
if err == nil {
388-
// exist, need to remove
389-
_, _, err = NewCommand(DefaultContext, "config", "--global", "--unset-all").AddDynamicArguments(key, regexp.QuoteMeta(value)).RunStdString(nil)
390-
if err != nil {
391-
return fmt.Errorf("failed to unset git global config %s, err: %w", key, err)
392-
}
393-
return nil
394-
}
395-
if IsErrorExitCode(err, 1) {
396-
// not exist
397-
return nil
398-
}
399-
return fmt.Errorf("failed to get git config %s, err: %w", key, err)
400-
}
401-
402-
// Fsck verifies the connectivity and validity of the objects in the database
403-
func Fsck(ctx context.Context, repoPath string, timeout time.Duration, args TrustedCmdArgs) error {
404-
return NewCommand(ctx, "fsck").AddArguments(args...).Run(&RunOpts{Timeout: timeout, Dir: repoPath})
405-
}

services/agit/agit.go

Lines changed: 2 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ func ProcReceive(ctx context.Context, repo *repo_model.Repository, gitRepo *git.
153153
pr: pull,
154154
gitRepo: gitRepo,
155155
repo: repo,
156-
forcePush: forcePush,
156+
forcePush: forcePush.Value(),
157157
pusher: pusher,
158158
RefFullName: opts.RefFullNames[i],
159159
OldCommitID: opts.OldCommitIDs[i],
@@ -287,46 +287,13 @@ func ProcReceive(ctx context.Context, repo *repo_model.Repository, gitRepo *git.
287287
pr: pr,
288288
gitRepo: gitRepo,
289289
repo: repo,
290-
forcePush: forcePush,
290+
forcePush: forcePush.Value(),
291291
pusher: pusher,
292292
RefFullName: opts.RefFullNames[i],
293293
OldCommitID: opts.OldCommitIDs[i],
294294
NewCommitID: opts.NewCommitIDs[i],
295295
})
296296
if err != nil {
297-
return nil, fmt.Errorf("unable to get ref commit id in base repository for PR[%d] Error: %w", pr.ID, err)
298-
}
299-
300-
if oldCommitID == opts.NewCommitIDs[i] {
301-
results = append(results, private.HookProcReceiveRefResult{
302-
OriginalRef: opts.RefFullNames[i],
303-
OldOID: opts.OldCommitIDs[i],
304-
NewOID: opts.NewCommitIDs[i],
305-
Err: "new commit is same with old commit",
306-
})
307-
continue
308-
}
309-
310-
if !forcePush.Value() {
311-
output, _, err := git.NewCommand(ctx, "rev-list", "--max-count=1").
312-
AddDynamicArguments(oldCommitID, "^"+opts.NewCommitIDs[i]).
313-
RunStdString(&git.RunOpts{Dir: repo.RepoPath(), Env: os.Environ()})
314-
if err != nil {
315-
return nil, fmt.Errorf("failed to detect force push: %w", err)
316-
} else if len(output) > 0 {
317-
results = append(results, private.HookProcReceiveRefResult{
318-
OriginalRef: opts.RefFullNames[i],
319-
OldOID: opts.OldCommitIDs[i],
320-
NewOID: opts.NewCommitIDs[i],
321-
Err: "request `force-push` push option",
322-
})
323-
continue
324-
}
325-
}
326-
327-
pr.HeadCommitID = opts.NewCommitIDs[i]
328-
if err = pull_service.UpdateRef(ctx, pr); err != nil {
329-
return nil, fmt.Errorf("failed to update pull ref. Error: %w", err)
330297
return nil, err
331298
}
332299
results = append(results, *result)

templates/repo/issue/sidebar/allow_maintainer_edit.tmpl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{{if and .Issue.IsPull .IsIssuePoster (not .Issue.IsClosed) .Issue.PullRequest.HeadRepo}}
2-
{{if and (not (eq .Issue.PullRequest.HeadRepo.FullName .Issue.PullRequest.BaseRepo.FullName)) .CanWriteToHeadRepo}}
2+
{{if or (eq .SignedUserID .Issue.PosterID) (and (not (eq .Issue.PullRequest.HeadRepo.FullName .Issue.PullRequest.BaseRepo.FullName)) .CanWriteToHeadRepo)}}
33
<div class="divider"></div>
44
<div class="ui checkbox loading-icon-2px" id="allow-edits-from-maintainers"
55
data-url="{{.Issue.Link}}"

0 commit comments

Comments
 (0)