diff --git a/app/api/controller/githook/pre_receive.go b/app/api/controller/githook/pre_receive.go index c82e21312..95100d64c 100644 --- a/app/api/controller/githook/pre_receive.go +++ b/app/api/controller/githook/pre_receive.go @@ -93,18 +93,13 @@ func (c *Controller) PreReceive( return hook.Output{}, fmt.Errorf("failed to extend pre-receive hook: %w", err) } - // File size check currently checks all the blobs in alternate as well in the original repo dirs. - // We want to check file size only in alternate dirs. - // Temporarily comment out file size check until the solution is found. - // TODO: find the way to check the blob size only in alternate dirs. - - // err = c.checkFileSizeLimit(ctx, rgit, repo, in, &output) - // if output.Error != nil { - // return output, nil - // } - // if err != nil { - // return hook.Output{}, err - // } + err = c.checkFileSizeLimit(ctx, rgit, repo, in, &output) + if output.Error != nil { + return output, nil + } + if err != nil { + return hook.Output{}, err + } return output, nil } diff --git a/app/api/controller/githook/pre_receive_file_size_limit.go b/app/api/controller/githook/pre_receive_file_size_limit.go index 19cbfbf70..aae1dbd65 100644 --- a/app/api/controller/githook/pre_receive_file_size_limit.go +++ b/app/api/controller/githook/pre_receive_file_size_limit.go @@ -26,7 +26,6 @@ import ( "github.com/gotidy/ptr" ) -// nolint:unused func (c *Controller) checkFileSizeLimit( ctx context.Context, rgit RestrictedGIT, diff --git a/app/api/controller/githook/print.go b/app/api/controller/githook/print.go index f68fb737f..af6689fc4 100644 --- a/app/api/controller/githook/print.go +++ b/app/api/controller/githook/print.go @@ -104,7 +104,6 @@ func FMTDuration(d time.Duration) string { return d.String() } -// nolint:unused func printOversizeFiles( output *hook.Output, oversizeFiles []git.FileInfo, diff --git a/git/commit.go b/git/commit.go index 027ed1353..3f0ab4dc0 100644 --- a/git/commit.go +++ b/git/commit.go @@ -18,6 +18,7 @@ import ( "bytes" "context" "fmt" + "os" "time" "github.com/harness/gitness/errors" @@ -306,6 +307,16 @@ func catFileBatchCheckAllObjects( repoPath string, gitObjDir string, ) ([]parser.BatchCheckObject, error) { + // "info/alternates" points to the original repository. + const oldFilename = "/info/alternates" + const newFilename = "/info/alternates.bkp" + + // --batch-all-objects reports objects in the current repository and in all alternate directories. + // We want to report objects in the current repository only. + if err := os.Rename(gitObjDir+oldFilename, gitObjDir+newFilename); err != nil && !os.IsNotExist(err) { + return nil, fmt.Errorf("failed to rename %s to %s: %w", oldFilename, newFilename, err) + } + cmd := command.New("cat-file", command.WithFlag("--batch-check"), command.WithFlag("--batch-all-objects"), @@ -328,5 +339,9 @@ func catFileBatchCheckAllObjects( return nil, fmt.Errorf("failed to parse output of cat-file batch check all objects: %w", err) } + if err := os.Rename(gitObjDir+newFilename, gitObjDir+oldFilename); err != nil && !os.IsNotExist(err) { + return nil, fmt.Errorf("failed to rename %s to %s: %w", newFilename, oldFilename, err) + } + return objects, nil }