Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add bundle download for repository #14538

Merged
merged 6 commits into from
Aug 24, 2021
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion build.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
// Use of this source code is governed by a MIT-style
// license that can be found in the LICENSE file.

//+build vendor
//go:build vendor
// +build vendor

package main

Expand Down
1 change: 1 addition & 0 deletions build/generate-bindata.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// Use of this source code is governed by a MIT-style
// license that can be found in the LICENSE file.

//go:build ignore
// +build ignore

package main
Expand Down
1 change: 1 addition & 0 deletions build/generate-emoji.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
// Use of this source code is governed by a MIT-style
// license that can be found in the LICENSE file.

//go:build ignore
// +build ignore

package main
Expand Down
1 change: 1 addition & 0 deletions build/generate-gitignores.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
//go:build ignore
// +build ignore

package main
Expand Down
1 change: 1 addition & 0 deletions build/generate-licenses.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
//go:build ignore
// +build ignore

package main
Expand Down
1 change: 1 addition & 0 deletions build/gocovmerge.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
// gocovmerge takes the results from multiple `go test -coverprofile` runs and
// merges them into one profile

//go:build ignore
// +build ignore

package main
Expand Down
1 change: 1 addition & 0 deletions cmd/embedded.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// Use of this source code is governed by a MIT-style
// license that can be found in the LICENSE file.

//go:build bindata
// +build bindata

package cmd
Expand Down
1 change: 1 addition & 0 deletions cmd/embedded_stub.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// Use of this source code is governed by a MIT-style
// license that can be found in the LICENSE file.

//go:build !bindata
// +build !bindata

package cmd
Expand Down
5 changes: 3 additions & 2 deletions modules/auth/pam/pam.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
// +build pam

// Copyright 2014 The Gogs Authors. All rights reserved.
// Use of this source code is governed by a MIT-style
// license that can be found in the LICENSE file.

//go:build pam
// +build pam

package pam

import (
Expand Down
5 changes: 3 additions & 2 deletions modules/auth/pam/pam_stub.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
// +build !pam

// Copyright 2014 The Gogs Authors. All rights reserved.
// Use of this source code is governed by a MIT-style
// license that can be found in the LICENSE file.

//go:build !pam
// +build !pam

package pam

import (
Expand Down
1 change: 1 addition & 0 deletions modules/auth/pam/pam_test.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
//go:build pam
// +build pam

// Copyright 2021 The Gitea Authors. All rights reserved.
Expand Down
1 change: 1 addition & 0 deletions modules/git/blob_gogit.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
// Use of this source code is governed by a MIT-style
// license that can be found in the LICENSE file.

//go:build gogit
// +build gogit

package git
Expand Down
1 change: 1 addition & 0 deletions modules/git/blob_nogogit.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// Use of this source code is governed by a MIT-style
// license that can be found in the LICENSE file.

//go:build !gogit
// +build !gogit

package git
Expand Down
1 change: 1 addition & 0 deletions modules/git/command_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// Use of this source code is governed by a MIT-style
// license that can be found in the LICENSE file.

//go:build race
// +build race

package git
Expand Down
1 change: 1 addition & 0 deletions modules/git/commit_convert_gogit.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
// Use of this source code is governed by a MIT-style
// license that can be found in the LICENSE file.

//go:build gogit
// +build gogit

package git
Expand Down
1 change: 1 addition & 0 deletions modules/git/commit_info_gogit.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// Use of this source code is governed by a MIT-style
// license that can be found in the LICENSE file.

//go:build gogit
// +build gogit

package git
Expand Down
1 change: 1 addition & 0 deletions modules/git/commit_info_nogogit.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// Use of this source code is governed by a MIT-style
// license that can be found in the LICENSE file.

//go:build !gogit
// +build !gogit

package git
Expand Down
1 change: 1 addition & 0 deletions modules/git/last_commit_cache_gogit.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// Use of this source code is governed by a MIT-style
// license that can be found in the LICENSE file.

//go:build gogit
// +build gogit

package git
Expand Down
1 change: 1 addition & 0 deletions modules/git/last_commit_cache_nogogit.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// Use of this source code is governed by a MIT-style
// license that can be found in the LICENSE file.

//go:build !gogit
// +build !gogit

package git
Expand Down
1 change: 1 addition & 0 deletions modules/git/notes_gogit.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// Use of this source code is governed by a MIT-style
// license that can be found in the LICENSE file.

//go:build gogit
// +build gogit

package git
Expand Down
1 change: 1 addition & 0 deletions modules/git/notes_nogogit.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// Use of this source code is governed by a MIT-style
// license that can be found in the LICENSE file.

//go:build !gogit
// +build !gogit

package git
Expand Down
1 change: 1 addition & 0 deletions modules/git/parse_gogit.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// Use of this source code is governed by a MIT-style
// license that can be found in the LICENSE file.

//go:build gogit
// +build gogit

package git
Expand Down
1 change: 1 addition & 0 deletions modules/git/parse_gogit_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// Use of this source code is governed by a MIT-style
// license that can be found in the LICENSE file.

//go:build gogit
// +build gogit

package git
Expand Down
1 change: 1 addition & 0 deletions modules/git/parse_nogogit.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// Use of this source code is governed by a MIT-style
// license that can be found in the LICENSE file.

//go:build !gogit
// +build !gogit

package git
Expand Down
1 change: 1 addition & 0 deletions modules/git/parse_nogogit_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// Use of this source code is governed by a MIT-style
// license that can be found in the LICENSE file.

//go:build !gogit
// +build !gogit

package git
Expand Down
1 change: 1 addition & 0 deletions modules/git/pipeline/lfs.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// Use of this source code is governed by a MIT-style
// license that can be found in the LICENSE file.

//go:build gogit
// +build gogit

package pipeline
Expand Down
1 change: 1 addition & 0 deletions modules/git/pipeline/lfs_nogogit.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// Use of this source code is governed by a MIT-style
// license that can be found in the LICENSE file.

//go:build !gogit
// +build !gogit

package pipeline
Expand Down
31 changes: 31 additions & 0 deletions modules/git/repo.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"net/url"
"os"
"path"
"path/filepath"
"strconv"
"strings"
"time"
Expand Down Expand Up @@ -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
}
4 changes: 4 additions & 0 deletions modules/git/repo_archive.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ const (
ZIP ArchiveType = iota + 1
// TARGZ tar gz archive type
TARGZ
// BUNDLE bundle archive type
BUNDLE
)

// String converts an ArchiveType to string
Expand All @@ -30,6 +32,8 @@ func (a ArchiveType) String() string {
return "zip"
case TARGZ:
return "tar.gz"
case BUNDLE:
return "bundle"
}
return "unknown"
}
Expand Down
1 change: 1 addition & 0 deletions modules/git/repo_base_gogit.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
// Use of this source code is governed by a MIT-style
// license that can be found in the LICENSE file.

//go:build gogit
// +build gogit

package git
Expand Down
1 change: 1 addition & 0 deletions modules/git/repo_base_nogogit.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
// Use of this source code is governed by a MIT-style
// license that can be found in the LICENSE file.

//go:build !gogit
// +build !gogit

package git
Expand Down
1 change: 1 addition & 0 deletions modules/git/repo_blob_gogit.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// Use of this source code is governed by a MIT-style
// license that can be found in the LICENSE file.

//go:build gogit
// +build gogit

package git
Expand Down
1 change: 1 addition & 0 deletions modules/git/repo_blob_nogogit.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// Use of this source code is governed by a MIT-style
// license that can be found in the LICENSE file.

//go:build !gogit
// +build !gogit

package git
Expand Down
1 change: 1 addition & 0 deletions modules/git/repo_branch_gogit.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
// Use of this source code is governed by a MIT-style
// license that can be found in the LICENSE file.

//go:build gogit
// +build gogit

package git
Expand Down
1 change: 1 addition & 0 deletions modules/git/repo_branch_nogogit.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
// Use of this source code is governed by a MIT-style
// license that can be found in the LICENSE file.

//go:build !gogit
// +build !gogit

package git
Expand Down
1 change: 1 addition & 0 deletions modules/git/repo_commit_gogit.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
// Use of this source code is governed by a MIT-style
// license that can be found in the LICENSE file.

//go:build gogit
// +build gogit

package git
Expand Down
1 change: 1 addition & 0 deletions modules/git/repo_commit_nogogit.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// Use of this source code is governed by a MIT-style
// license that can be found in the LICENSE file.

//go:build !gogit
// +build !gogit

package git
Expand Down
1 change: 1 addition & 0 deletions modules/git/repo_commitgraph_gogit.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
// Use of this source code is governed by a MIT-style
// license that can be found in the LICENSE file.

//go:build gogit
// +build gogit

package git
Expand Down
1 change: 1 addition & 0 deletions modules/git/repo_language_stats_gogit.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// Use of this source code is governed by a MIT-style
// license that can be found in the LICENSE file.

//go:build gogit
// +build gogit

package git
Expand Down
1 change: 1 addition & 0 deletions modules/git/repo_language_stats_nogogit.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// Use of this source code is governed by a MIT-style
// license that can be found in the LICENSE file.

//go:build !gogit
// +build !gogit

package git
Expand Down
1 change: 1 addition & 0 deletions modules/git/repo_ref_gogit.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// Use of this source code is governed by a MIT-style
// license that can be found in the LICENSE file.

//go:build gogit
// +build gogit

package git
Expand Down
1 change: 1 addition & 0 deletions modules/git/repo_ref_nogogit.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// Use of this source code is governed by a MIT-style
// license that can be found in the LICENSE file.

//go:build !gogit
// +build !gogit

package git
Expand Down
1 change: 1 addition & 0 deletions modules/git/repo_tag_gogit.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
// Use of this source code is governed by a MIT-style
// license that can be found in the LICENSE file.

//go:build gogit
// +build gogit

package git
Expand Down
1 change: 1 addition & 0 deletions modules/git/repo_tag_nogogit.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
// Use of this source code is governed by a MIT-style
// license that can be found in the LICENSE file.

//go:build !gogit
// +build !gogit

package git
Expand Down
Loading