mirror of
https://github.com/go-gitea/gitea.git
synced 2026-08-12 22:38:01 +09:00
Bundle downloads run `git bundle create` into a temp file under `data/tmp/git-repo-content` and copy it to the response, so every download puts a second, repo-sized copy on disk before the first byte is sent. If the process dies mid-request that copy is stranded: the startup sweep only drops files older than 3 days, and cannot remove a directory that still holds a newer file. Streaming `git bundle create -` to the response removes that copy. `CreateArchive` above already uses the same gitcmd pattern, and the bundle bytes are unchanged (existing integration assertions on the exact length still pass). One consequence: git can now fail after output starts, so a mid-stream failure truncates the body instead of returning an error. I did not act on the TODO. A temp ref only works under `refs/heads/*`; with `refs/bundle/temp-*` the bundle carries no branch and clones empty, so I noted that on the TODO. Fixes https://github.com/go-gitea/gitea/issues/38447 --------- Co-authored-by: silverwind <me@silverwind.io>
30 lines
885 B
Go
30 lines
885 B
Go
// Copyright 2026 The Gitea Authors. All rights reserved.
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
package git
|
|
|
|
import (
|
|
"bytes"
|
|
"strings"
|
|
"testing"
|
|
|
|
"gitea.dev/modules/setting"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
"github.com/stretchr/testify/require"
|
|
)
|
|
|
|
func TestCreateBundle(t *testing.T) {
|
|
setting.AppDataPath = t.TempDir()
|
|
|
|
buf := &bytes.Buffer{}
|
|
require.NoError(t, CreateBundle(t.Context(), mockRepository("repo1_bare"), "ce064814f4a0d337b333e646ece456cd39fab612", buf))
|
|
|
|
header, _, ok := strings.Cut(buf.String(), "\n\n")
|
|
require.True(t, ok)
|
|
assert.Equal(t, "# v2 git bundle", strings.Split(header, "\n")[0])
|
|
// without a refs/heads/* ref and a HEAD, a clone of the bundle has no branch and no checkout
|
|
assert.Contains(t, header, "ce064814f4a0d337b333e646ece456cd39fab612 refs/heads/bundle")
|
|
assert.Contains(t, header, "ce064814f4a0d337b333e646ece456cd39fab612 HEAD")
|
|
}
|