feat: prioritize latest commit time for repo UpdatedAt

Amolith and Crush created

Change the order of operations in UpdatedAt() to first try getting
the timestamp from the latest commit before falling back to the
last-modified file. This ensures more accurate update timestamps.

Co-Authored-By: Crush <crush@charm.land>

Change summary

pkg/backend/repo.go | 13 ++++++-------
1 file changed, 6 insertions(+), 7 deletions(-)

Detailed changes

pkg/backend/repo.go 🔗

@@ -718,13 +718,6 @@ func (r *repo) CreatedAt() time.Time {
 
 // UpdatedAt returns the repository's last update time.
 func (r *repo) UpdatedAt() time.Time {
-	// Try to read the last modified time from the info directory.
-	if t, err := readOneline(filepath.Join(r.path, "info", "last-modified")); err == nil {
-		if t, err := time.Parse(time.RFC3339, t); err == nil {
-			return t
-		}
-	}
-
 	rr, err := git.Open(r.path)
 	if err == nil {
 		t, err := rr.LatestCommitTime()
@@ -733,6 +726,12 @@ func (r *repo) UpdatedAt() time.Time {
 		}
 	}
 
+	if t, err := readOneline(filepath.Join(r.path, "info", "last-modified")); err == nil {
+		if t, err := time.Parse(time.RFC3339, t); err == nil {
+			return t
+		}
+	}
+
 	return r.repo.UpdatedAt
 }