Skip to content
This repository was archived by the owner on Apr 12, 2019. It is now read-only.

Commit af05861

Browse files
cez81lunny
authored andcommitted
Add GetLatestCommitTime (#45)
1 parent 1b9115b commit af05861

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

repo.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
// Copyright 2015 The Gogs Authors. All rights reserved.
2+
// Copyright 2017 The Gitea Authors. All rights reserved.
23
// Use of this source code is governed by a MIT-style
34
// license that can be found in the LICENSE file.
45

@@ -261,3 +262,14 @@ func parseSize(objects string) *CountObject {
261262
}
262263
return repoSize
263264
}
265+
266+
// GetLatestCommitTime returns time for latest commit in repository (across all branches)
267+
func GetLatestCommitTime(repoPath string) (time.Time, error) {
268+
cmd := NewCommand("for-each-ref", "--sort=-committerdate", "refs/heads/", "--count", "1", "--format=%(committerdate)")
269+
stdout, err := cmd.RunInDir(repoPath)
270+
if err != nil {
271+
return time.Time{}, err
272+
}
273+
commitTime := strings.TrimSpace(stdout)
274+
return time.Parse("Mon Jan 02 15:04:05 2006 -0700", commitTime)
275+
}

0 commit comments

Comments
 (0)