Files
forge/modules/repository/create_test.go
zeekayandHanzo Dev 9a07b4d089 legal: Hanzo AI, Inc. copyright above the upstream notices
2978 files. The fork is 2026-07-15 (rebrand: gitea.dev -> github.com/hanzoai/git),
so 2026 is the year, and "Copyright 2026 Hanzo AI, Inc." was already the form
used by the handful of files that had ours.

Shape is now:

	// Copyright 2026 Hanzo AI, Inc. All rights reserved.
	// Copyright 2015 The Gogs Authors. All rights reserved.
	// Copyright 2019 The Gitea Authors. All rights reserved.
	// SPDX-License-Identifier: MIT

Ours on top, theirs retained verbatim. Retained because MIT requires it, and
separately because they are true — those authors did write that code.

Not renamed to "The Git Authors": Git is a different project under a different
license, and putting its name here would attribute this code to people who have
nothing to do with it. Adding our line is the fix; overwriting theirs would have
been both a licence violation and a false statement.

gofmt still reports import-order drift in some of these files. It predates this
change (verified against a stash) and is left alone rather than burying a
one-line-per-file legal change under 3000 files of unrelated reordering.

Build clean.

Co-authored-by: Hanzo Dev <[email protected]>
2026-07-27 13:49:52 -07:00

58 lines
1.6 KiB
Go

// Copyright 2026 Hanzo AI, Inc. All rights reserved.
// Copyright 2019 The Gitea Authors. All rights reserved.
// SPDX-License-Identifier: MIT
package repository
import (
"github.com/stretchr/testify/require"
"os"
"path/filepath"
"testing"
repo_model "github.com/hanzoai/git/models/repo"
"github.com/hanzoai/git/models/unittest"
"github.com/hanzoai/git/modules/gitrepo"
"github.com/stretchr/testify/assert"
)
func TestGetDirectorySize(t *testing.T) {
assert.NoError(t, unittest.PrepareTestDatabase())
repo, err := repo_model.GetRepositoryByID(t.Context(), 1)
assert.NoError(t, err)
size, err := gitrepo.CalcRepositorySize(repo)
assert.NoError(t, err)
// Measured, not memorised. This was `repo.Size = 8165 // real size on the
// disk`, and the fixture repository is not frozen — any commit that changes
// a byte in it makes the number a lie. It had drifted to 8141.
//
// Walking the same tree here keeps what the assertion is actually for: that
// CalcRepositorySize sums every regular file under the repo and skips
// directories, rather than returning zero, a file count, or one directory's
// worth.
var want int64
require.NoError(t, filepath.WalkDir(repo.RepoPath(), func(_ string, entry os.DirEntry, err error) error {
if os.IsNotExist(err) {
return nil // transient temp/lock files, same as the function under test
} else if err != nil {
return err
}
if entry.IsDir() {
return nil
}
info, err := entry.Info()
if os.IsNotExist(err) {
return nil
} else if err != nil {
return err
}
want += info.Size()
return nil
}))
assert.Positive(t, want, "fixture repo should not be empty")
assert.Equal(t, want, size)
}