diff options
Diffstat (limited to 'modules/git/repo.go')
-rw-r--r-- | modules/git/repo.go | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/modules/git/repo.go b/modules/git/repo.go index f2bbbf4716..e7d42dacb1 100644 --- a/modules/git/repo.go +++ b/modules/git/repo.go @@ -13,6 +13,7 @@ import ( "net/url" "os" "path" + "path/filepath" "strconv" "strings" "time" @@ -415,3 +416,33 @@ func GetDivergingCommits(repoPath string, baseBranch string, targetBranch string return DivergeObject{ahead, behind}, nil } + +// CreateBundle create bundle content to the target path +func (repo *Repository) CreateBundle(ctx context.Context, commit string, out io.Writer) error { + tmp, err := os.MkdirTemp(os.TempDir(), "gitea-bundle") + if err != nil { + return err + } + defer os.RemoveAll(tmp) + + tmpFile := filepath.Join(tmp, "bundle") + args := []string{ + "bundle", + "create", + tmpFile, + commit, + } + _, err = NewCommandContext(ctx, args...).RunInDir(repo.Path) + if err != nil { + return err + } + + fi, err := os.Open(tmpFile) + if err != nil { + return err + } + defer fi.Close() + + _, err = io.Copy(out, fi) + return err +} |