Files
gitea-MIRROR/modules/git/commit2_test.go
Christmas a46dea6651 fix(mirror): keep repository update times out of the future (#40481)
A pull mirror copied its newest branch tip's committer date into the
repository's "Last updated" field. Commit dates are set by whoever made
the commit, so a single tip dated 2098 kept an idle mirror at the top of
Explore for decades.

Like GitHub, GitLab and Gitea's own push handling, a sync now sets the
update time to the sync time when any ref changed and leaves it
untouched otherwise.

Fixes: https://github.com/go-gitea/gitea/issues/40480

Assisted-by: Codex:GPT-6
Assisted-by: Claude Code:claude-opus-5-5

---------

Co-authored-by: silverwind <me@silverwind.io>
2026-11-25 10:39:43 +00:00

36 lines
1.2 KiB
Go

// Copyright 2025 The Gitea Authors. All rights reserved.
// SPDX-License-Identifier: MIT
package git
import (
"testing"
"github.com/stretchr/testify/assert"
)
func TestCommitsCount(t *testing.T) {
bareRepo1 := mockRepository("repo1_bare")
revision := []string{"8006ff9adbf0cb94da7dad9e537e53817f9fa5c0"}
// The three commits on this revision are dated 2018-04-18, 2017-12-19 and 2017-12-19.
for _, tc := range []struct {
name string
options CommitsCountOptions
expected int64
}{
{"revision", CommitsCountOptions{Revision: revision}, 3},
{"no filter", CommitsCountOptions{Revision: revision}, 3},
{"since keeps newer commits", CommitsCountOptions{Revision: revision, Since: "2018-01-01"}, 1},
{"until keeps older commits", CommitsCountOptions{Revision: revision, Until: "2018-01-01"}, 2},
{"since and until bound the range", CommitsCountOptions{Revision: revision, Since: "2017-12-19T22:16:00-08:00", Until: "2018-01-01"}, 1},
{"without base", CommitsCountOptions{Not: "master", Revision: []string{"branch1"}}, 2},
} {
t.Run(tc.name, func(t *testing.T) {
commitsCount, err := CommitsCount(t.Context(), bareRepo1, tc.options)
assert.NoError(t, err)
assert.Equal(t, tc.expected, commitsCount)
})
}
}