mirror of
https://github.com/gogs/gogs.git
synced 2026-05-07 21:17:46 +02:00
modes/mirror: make Updated unchanged if no new commits fetched (#4341)
After sync mirror, get latest commit date and compare to current repository updated time, only update it if the commit date is newer.
This commit is contained in:
2
vendor/github.com/gogits/git-module/git.go
generated
vendored
2
vendor/github.com/gogits/git-module/git.go
generated
vendored
@@ -10,7 +10,7 @@ import (
|
||||
"time"
|
||||
)
|
||||
|
||||
const _VERSION = "0.6.0"
|
||||
const _VERSION = "0.6.1"
|
||||
|
||||
func Version() string {
|
||||
return _VERSION
|
||||
|
||||
15
vendor/github.com/gogits/git-module/repo.go
generated
vendored
15
vendor/github.com/gogits/git-module/repo.go
generated
vendored
@@ -278,3 +278,18 @@ func GetRepoSize(repoPath string) (*CountObject, error) {
|
||||
|
||||
return countObject, nil
|
||||
}
|
||||
|
||||
// GetLatestCommitDate returns the date of latest commit of repository.
|
||||
// If branch is empty, it returns the latest commit across all branches.
|
||||
func GetLatestCommitDate(repoPath, branch string) (time.Time, error) {
|
||||
cmd := NewCommand("for-each-ref", "--count=1", "--sort=-committerdate", "--format=%(committerdate:iso8601)")
|
||||
if len(branch) > 0 {
|
||||
cmd.AddArguments("refs/heads/" + branch)
|
||||
}
|
||||
stdout, err := cmd.RunInDir(repoPath)
|
||||
if err != nil {
|
||||
return time.Time{}, err
|
||||
}
|
||||
|
||||
return time.Parse("2006-01-02 15:04:05 -0700", strings.TrimSpace(stdout))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user