Skip to content

Commit bdca69b

Browse files
committed
Update to latest Gitea 1.16
2 parents 59899cf + efd34d0 commit bdca69b

File tree

9 files changed

+101
-18
lines changed

9 files changed

+101
-18
lines changed

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ require (
8585
github.com/urfave/cli v1.22.5
8686
github.com/xanzy/go-gitlab v0.58.0
8787
github.com/yohcop/openid-go v1.0.0
88-
github.com/yuin/goldmark v1.4.8
88+
github.com/yuin/goldmark v1.4.11
8989
github.com/yuin/goldmark-highlighting v0.0.0-20220208100518-594be1970594
9090
github.com/yuin/goldmark-meta v1.1.0
9191
go.jolheiser.com/hcaptcha v0.0.4

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1539,8 +1539,8 @@ github.com/yuin/goldmark v1.3.5/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1
15391539
github.com/yuin/goldmark v1.4.1/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k=
15401540
github.com/yuin/goldmark v1.4.5/go.mod h1:rmuwmfZ0+bvzB24eSC//bk1R1Zp3hM0OXYv/G2LIilg=
15411541
github.com/yuin/goldmark v1.4.6/go.mod h1:rmuwmfZ0+bvzB24eSC//bk1R1Zp3hM0OXYv/G2LIilg=
1542-
github.com/yuin/goldmark v1.4.8 h1:zHPiabbIRssZOI0MAzJDHsyvG4MXCGqVaMOwR+HeoQQ=
1543-
github.com/yuin/goldmark v1.4.8/go.mod h1:rmuwmfZ0+bvzB24eSC//bk1R1Zp3hM0OXYv/G2LIilg=
1542+
github.com/yuin/goldmark v1.4.11 h1:i45YIzqLnUc2tGaTlJCyUxSG8TvgyGqhqOZOUKIjJ6w=
1543+
github.com/yuin/goldmark v1.4.11/go.mod h1:rmuwmfZ0+bvzB24eSC//bk1R1Zp3hM0OXYv/G2LIilg=
15441544
github.com/yuin/goldmark-highlighting v0.0.0-20220208100518-594be1970594 h1:yHfZyN55+5dp1wG7wDKv8HQ044moxkyGq12KFFMFDxg=
15451545
github.com/yuin/goldmark-highlighting v0.0.0-20220208100518-594be1970594/go.mod h1:U9ihbh+1ZN7fR5Se3daSPoz1CGF9IYtSvWwVQtnzGHU=
15461546
github.com/yuin/goldmark-meta v1.1.0 h1:pWw+JLHGZe8Rk0EGsMVssiNb/AaPMHfSRszZeUeiOUc=

models/repo/mirror.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
package repo
77

88
import (
9+
"context"
910
"errors"
1011
"fmt"
1112
"time"
@@ -115,6 +116,13 @@ func UpdateMirror(m *Mirror) error {
115116
return updateMirror(db.GetEngine(db.DefaultContext), m)
116117
}
117118

119+
// TouchMirror updates the mirror updatedUnix
120+
func TouchMirror(ctx context.Context, m *Mirror) error {
121+
m.UpdatedUnix = timeutil.TimeStampNow()
122+
_, err := db.GetEngine(ctx).ID(m.ID).Cols("updated_unix").Update(m)
123+
return err
124+
}
125+
118126
// DeleteMirrorByRepoID deletes a mirror by repoID
119127
func DeleteMirrorByRepoID(repoID int64) error {
120128
_, err := db.GetEngine(db.DefaultContext).Delete(&Mirror{RepoID: repoID})

modules/git/command.go

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import (
1717

1818
"code.gitea.io/gitea/modules/log"
1919
"code.gitea.io/gitea/modules/process"
20+
"code.gitea.io/gitea/modules/util"
2021
)
2122

2223
var (
@@ -32,10 +33,11 @@ const DefaultLocale = "C"
3233

3334
// Command represents a command with its subcommands or arguments.
3435
type Command struct {
35-
name string
36-
args []string
37-
parentContext context.Context
38-
desc string
36+
name string
37+
args []string
38+
parentContext context.Context
39+
desc string
40+
globalArgsLength int
3941
}
4042

4143
func (c *Command) String() string {
@@ -56,9 +58,10 @@ func NewCommandContext(ctx context.Context, args ...string) *Command {
5658
cargs := make([]string, len(GlobalCommandArgs))
5759
copy(cargs, GlobalCommandArgs)
5860
return &Command{
59-
name: GitExecutable,
60-
args: append(cargs, args...),
61-
parentContext: ctx,
61+
name: GitExecutable,
62+
args: append(cargs, args...),
63+
parentContext: ctx,
64+
globalArgsLength: len(GlobalCommandArgs),
6265
}
6366
}
6467

@@ -145,7 +148,21 @@ func (c *Command) RunWithContext(rc *RunContext) error {
145148

146149
desc := c.desc
147150
if desc == "" {
148-
desc = fmt.Sprintf("%s %s [repo_path: %s]", c.name, strings.Join(c.args, " "), rc.Dir)
151+
args := c.args[c.globalArgsLength:]
152+
var argSensitiveURLIndexes []int
153+
for i, arg := range c.args {
154+
if strings.Contains(arg, "://") && strings.Contains(arg, "@") {
155+
argSensitiveURLIndexes = append(argSensitiveURLIndexes, i)
156+
}
157+
}
158+
if len(argSensitiveURLIndexes) > 0 {
159+
args = make([]string, len(c.args))
160+
copy(args, c.args)
161+
for _, urlArgIndex := range argSensitiveURLIndexes {
162+
args[urlArgIndex] = util.NewStringURLSanitizer(args[urlArgIndex], true).Replace(args[urlArgIndex])
163+
}
164+
}
165+
desc = fmt.Sprintf("%s %s [repo_path: %s]", c.name, strings.Join(args, " "), rc.Dir)
149166
}
150167

151168
ctx, cancel, finished := process.GetManager().AddContextTimeout(c.parentContext, rc.Timeout, desc)

modules/git/repo.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import (
1919
"time"
2020

2121
"code.gitea.io/gitea/modules/proxy"
22+
"code.gitea.io/gitea/modules/util"
2223
)
2324

2425
// GPGSettings represents the default GPG settings for this repository
@@ -158,6 +159,12 @@ func CloneWithArgs(ctx context.Context, from, to string, args []string, opts Clo
158159
}
159160
cmd.AddArguments("--", from, to)
160161

162+
if strings.Contains(from, "://") && strings.Contains(from, "@") {
163+
cmd.SetDescription(fmt.Sprintf("clone branch %s from %s to %s (shared: %t, mirror: %t, depth: %d)", opts.Branch, util.NewStringURLSanitizer(from, true).Replace(from), to, opts.Shared, opts.Mirror, opts.Depth))
164+
} else {
165+
cmd.SetDescription(fmt.Sprintf("clone branch %s from %s to %s (shared: %t, mirror: %t, depth: %d)", opts.Branch, from, to, opts.Shared, opts.Mirror, opts.Depth))
166+
}
167+
161168
if opts.Timeout <= 0 {
162169
opts.Timeout = -1
163170
}
@@ -234,6 +241,11 @@ func Push(ctx context.Context, repoPath string, opts PushOptions) error {
234241
if len(opts.Branch) > 0 {
235242
cmd.AddArguments(opts.Branch)
236243
}
244+
if strings.Contains(opts.Remote, "://") && strings.Contains(opts.Remote, "@") {
245+
cmd.SetDescription(fmt.Sprintf("push branch %s to %s (force: %t, mirror: %t)", opts.Branch, util.NewStringURLSanitizer(opts.Remote, true).Replace(opts.Remote), opts.Force, opts.Mirror))
246+
} else {
247+
cmd.SetDescription(fmt.Sprintf("push branch %s to %s (force: %t, mirror: %t)", opts.Branch, opts.Remote, opts.Force, opts.Mirror))
248+
}
237249
var outbuf, errbuf strings.Builder
238250

239251
if opts.Timeout == 0 {

modules/indexer/stats/indexer_test.go

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,15 @@
55
package stats
66

77
import (
8+
"context"
89
"path/filepath"
910
"testing"
1011
"time"
1112

1213
repo_model "code.gitea.io/gitea/models/repo"
1314
"code.gitea.io/gitea/models/unittest"
15+
"code.gitea.io/gitea/modules/git"
16+
"code.gitea.io/gitea/modules/queue"
1417
"code.gitea.io/gitea/modules/setting"
1518

1619
_ "code.gitea.io/gitea/models"
@@ -24,6 +27,10 @@ func TestMain(m *testing.M) {
2427
}
2528

2629
func TestRepoStatsIndex(t *testing.T) {
30+
if err := git.Init(context.Background()); !assert.NoError(t, err) {
31+
return
32+
}
33+
2734
assert.NoError(t, unittest.PrepareTestDatabase())
2835
setting.Cfg = ini.Empty()
2936

@@ -32,10 +39,14 @@ func TestRepoStatsIndex(t *testing.T) {
3239
err := Init()
3340
assert.NoError(t, err)
3441

35-
time.Sleep(5 * time.Second)
36-
3742
repo, err := repo_model.GetRepositoryByID(1)
3843
assert.NoError(t, err)
44+
45+
err = UpdateRepoIndexer(repo)
46+
assert.NoError(t, err)
47+
48+
queue.GetManager().FlushAll(context.Background(), 5*time.Second)
49+
3950
status, err := repo_model.GetIndexerStatus(repo, repo_model.RepoIndexerTypeStats)
4051
assert.NoError(t, err)
4152
assert.Equal(t, "65f1bf27bc3bf70f64657658635e66094edbcb4d", status.CommitSha)

modules/markup/markdown/markdown_test.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,11 @@ func testAnswers(baseURLContent, baseURLImages string) []string {
197197
</li>
198198
</ol>
199199
</div>
200+
`, `<ul>
201+
<li class="task-list-item"><input type="checkbox" disabled="" data-source-position="3"/> If you want to rebase/retry this PR, click this checkbox.</li>
202+
</ul>
203+
<hr/>
204+
<p>This PR has been generated by <a href="https://github.com/renovatebot/renovate" rel="nofollow">Renovate Bot</a>.</p>
200205
`,
201206
}
202207
}
@@ -269,6 +274,14 @@ Here is a simple footnote,[^1] and here is a longer one.[^bignote]
269274
270275
Add as many paragraphs as you like.
271276
`,
277+
`
278+
- [ ] <!-- rebase-check --> If you want to rebase/retry this PR, click this checkbox.
279+
280+
---
281+
282+
This PR has been generated by [Renovate Bot](https://github.com/renovatebot/renovate).
283+
284+
<!-- test-comment -->`,
272285
}
273286

274287
func TestTotal_RenderWiki(t *testing.T) {

services/mirror/mirror_pull.go

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,13 @@ func UpdateAddress(m *repo_model.Mirror, addr string) error {
3939
return err
4040
}
4141

42-
_, err = git.NewCommand("remote", "add", remoteName, "--mirror=fetch", addr).RunInDir(repoPath)
42+
cmd := git.NewCommand("remote", "add", remoteName, "--mirror=fetch", addr)
43+
if strings.Contains(addr, "://") && strings.Contains(addr, "@") {
44+
cmd.SetDescription(fmt.Sprintf("remote add %s --mirror=fetch %s [repo_path: %s]", remoteName, util.NewStringURLSanitizer(addr, true).Replace(addr), repoPath))
45+
} else {
46+
cmd.SetDescription(fmt.Sprintf("remote add %s --mirror=fetch %s [repo_path: %s]", remoteName, addr, repoPath))
47+
}
48+
_, err = cmd.RunInDir(repoPath)
4349
if err != nil && !strings.HasPrefix(err.Error(), "exit status 128 - fatal: No such remote ") {
4450
return err
4551
}
@@ -53,7 +59,13 @@ func UpdateAddress(m *repo_model.Mirror, addr string) error {
5359
return err
5460
}
5561

56-
_, err = git.NewCommand("remote", "add", remoteName, "--mirror=fetch", wikiRemotePath).RunInDir(wikiPath)
62+
cmd = git.NewCommand("remote", "add", remoteName, "--mirror=fetch", wikiRemotePath)
63+
if strings.Contains(wikiRemotePath, "://") && strings.Contains(wikiRemotePath, "@") {
64+
cmd.SetDescription(fmt.Sprintf("remote add %s --mirror=fetch %s [repo_path: %s]", remoteName, util.NewStringURLSanitizer(wikiRemotePath, true).Replace(wikiRemotePath), wikiPath))
65+
} else {
66+
cmd.SetDescription(fmt.Sprintf("remote add %s --mirror=fetch %s [repo_path: %s]", remoteName, wikiRemotePath, wikiPath))
67+
}
68+
_, err = cmd.RunInDir(wikiPath)
5769
if err != nil && !strings.HasPrefix(err.Error(), "exit status 128 - fatal: No such remote ") {
5870
return err
5971
}
@@ -150,8 +162,8 @@ func pruneBrokenReferences(ctx context.Context,
150162
timeout time.Duration,
151163
stdoutBuilder, stderrBuilder *strings.Builder,
152164
sanitizer *strings.Replacer,
153-
isWiki bool) error {
154-
165+
isWiki bool,
166+
) error {
155167
wiki := ""
156168
if isWiki {
157169
wiki = "Wiki "
@@ -375,6 +387,9 @@ func SyncPullMirror(ctx context.Context, repoID int64) bool {
375387
log.Trace("SyncMirrors [repo: %-v]: Running Sync", m.Repo)
376388
results, ok := runSync(ctx, m)
377389
if !ok {
390+
if err = repo_model.TouchMirror(ctx, m); err != nil {
391+
log.Error("SyncMirrors [repo: %-v]: failed to TouchMirror: %v", m.Repo, err)
392+
}
378393
return false
379394
}
380395

services/mirror/mirror_push.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010
"fmt"
1111
"io"
1212
"regexp"
13+
"strings"
1314
"time"
1415

1516
repo_model "code.gitea.io/gitea/models/repo"
@@ -28,7 +29,13 @@ var stripExitStatus = regexp.MustCompile(`exit status \d+ - `)
2829
// AddPushMirrorRemote registers the push mirror remote.
2930
func AddPushMirrorRemote(m *repo_model.PushMirror, addr string) error {
3031
addRemoteAndConfig := func(addr, path string) error {
31-
if _, err := git.NewCommand("remote", "add", "--mirror=push", m.RemoteName, addr).RunInDir(path); err != nil {
32+
cmd := git.NewCommand("remote", "add", "--mirror=push", m.RemoteName, addr)
33+
if strings.Contains(addr, "://") && strings.Contains(addr, "@") {
34+
cmd.SetDescription(fmt.Sprintf("remote add %s --mirror=push %s [repo_path: %s]", m.RemoteName, util.NewStringURLSanitizer(addr, true).Replace(addr), path))
35+
} else {
36+
cmd.SetDescription(fmt.Sprintf("remote add %s --mirror=push %s [repo_path: %s]", m.RemoteName, addr, path))
37+
}
38+
if _, err := cmd.RunInDir(path); err != nil {
3239
return err
3340
}
3441
if _, err := git.NewCommand("config", "--add", "remote."+m.RemoteName+".push", "+refs/heads/*:refs/heads/*").RunInDir(path); err != nil {

0 commit comments

Comments
 (0)