Skip to content

Commit

Permalink
Merge branch 'release/v1.22' into lunny/fix_index_bug2
Browse files Browse the repository at this point in the history
  • Loading branch information
GiteaBot authored Sep 3, 2024
2 parents 27743a0 + 6f5748c commit e742b7a
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 0 deletions.
14 changes: 14 additions & 0 deletions cmd/hook.go
Original file line number Diff line number Diff line change
Expand Up @@ -290,8 +290,22 @@ Gitea or set your environment appropriately.`, "")
return nil
}

// runHookUpdate avoid to do heavy operations on update hook because it will be
// invoked for every ref update which does not like pre-receive and post-receive
func runHookUpdate(c *cli.Context) error {
if isInternal, _ := strconv.ParseBool(os.Getenv(repo_module.EnvIsInternal)); isInternal {
return nil
}

// Update is empty and is kept only for backwards compatibility
if len(os.Args) < 3 {
return nil
}
refName := git.RefName(os.Args[len(os.Args)-3])
if refName.IsPull() {
// ignore update to refs/pull/xxx/head, so we don't need to output any information
os.Exit(1)
}
return nil
}

Expand Down
4 changes: 4 additions & 0 deletions routers/web/org/home.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,10 @@ func Home(ctx *context.Context) {
orderBy = db.SearchOrderByForksReverse
case "fewestforks":
orderBy = db.SearchOrderByForks
case "size":
orderBy = db.SearchOrderByGitSize
case "reversesize":
orderBy = db.SearchOrderByGitSizeReverse
default:
ctx.Data["SortType"] = "recentupdate"
orderBy = db.SearchOrderByRecentUpdated
Expand Down
4 changes: 4 additions & 0 deletions routers/web/user/profile.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,10 @@ func prepareUserProfileTabData(ctx *context.Context, showPrivate bool, profileDb
orderBy = db.SearchOrderByForksReverse
case "fewestforks":
orderBy = db.SearchOrderByForks
case "size":
orderBy = db.SearchOrderByGitSize
case "reversesize":
orderBy = db.SearchOrderByGitSizeReverse
default:
ctx.Data["SortType"] = "recentupdate"
orderBy = db.SearchOrderByRecentUpdated
Expand Down
22 changes: 22 additions & 0 deletions tests/integration/git_push_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@ package integration
import (
"fmt"
"net/url"
"strings"
"testing"

auth_model "code.gitea.io/gitea/models/auth"
"code.gitea.io/gitea/models/db"
git_model "code.gitea.io/gitea/models/git"
"code.gitea.io/gitea/models/unittest"
Expand Down Expand Up @@ -192,3 +194,23 @@ func runTestGitPush(t *testing.T, u *url.URL, gitOperation func(t *testing.T, gi

require.NoError(t, repo_service.DeleteRepositoryDirectly(db.DefaultContext, user, repo.ID))
}

func TestPushPullRefs(t *testing.T) {
onGiteaRun(t, func(t *testing.T, u *url.URL) {
baseAPITestContext := NewAPITestContext(t, "user2", "repo1", auth_model.AccessTokenScopeWriteRepository, auth_model.AccessTokenScopeWriteUser)

u.Path = baseAPITestContext.GitPath()
u.User = url.UserPassword("user2", userPassword)

dstPath := t.TempDir()
doGitClone(dstPath, u)(t)

cmd := git.NewCommand(git.DefaultContext, "push", "--delete", "origin", "refs/pull/2/head")
stdout, stderr, err := cmd.RunStdString(&git.RunOpts{
Dir: dstPath,
})
assert.Error(t, err)
assert.Empty(t, stdout)
assert.False(t, strings.Contains(stderr, "[deleted]"), "stderr: %s", stderr)
})
}
1 change: 1 addition & 0 deletions tests/test_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,7 @@ func PrepareTestEnv(t testing.TB, skip ...int) func() {
_ = os.MkdirAll(filepath.Join(setting.RepoRootPath, ownerDir.Name(), repoDir.Name(), "objects", "info"), 0o755)
_ = os.MkdirAll(filepath.Join(setting.RepoRootPath, ownerDir.Name(), repoDir.Name(), "refs", "heads"), 0o755)
_ = os.MkdirAll(filepath.Join(setting.RepoRootPath, ownerDir.Name(), repoDir.Name(), "refs", "tag"), 0o755)
_ = os.MkdirAll(filepath.Join(setting.RepoRootPath, ownerDir.Name(), repoDir.Name(), "refs", "pull"), 0o755)
}
}

Expand Down

0 comments on commit e742b7a

Please sign in to comment.