Skip to content

Commit

Permalink
Merge branch 'master' into git_simple_pr
Browse files Browse the repository at this point in the history
* master:
  Fixed irritating error message related to go version (go-gitea#14611)
  Use OldRef instead of CommitSHA for DeleteBranch comments (go-gitea#14604)
  Add information on how to build statically (go-gitea#14594)
  [skip ci] Updated translations via Crowdin
  Exclude the current dump file from the dump (go-gitea#14606)
  Remove spurious DataAsync Error logging (go-gitea#14599)
  [API] Add  delete release by tag & fix unreleased inconsistency (go-gitea#14563)
  Fix rate limit bug when downloading assets on migrating from github (go-gitea#14564)
  [API] Add affected files of commits to commit struct (go-gitea#14579)
  • Loading branch information
a1012112796 committed Feb 8, 2021
2 parents f96e9e7 + 758627c commit 501f850
Show file tree
Hide file tree
Showing 21 changed files with 307 additions and 112 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ help:
go-check:
$(eval GO_VERSION := $(shell printf "%03d%03d%03d" $(shell $(GO) version | grep -Eo '[0-9]+\.[0-9.]+' | tr '.' ' ');))
@if [ "$(GO_VERSION)" -lt "$(MIN_GO_VERSION)" ]; then \
echo "Gitea requires Go 1.13 or greater to build. You can get it at https://golang.org/dl/"; \
echo "Gitea requires Go 1.14 or greater to build. You can get it at https://golang.org/dl/"; \
exit 1; \
fi

Expand Down
66 changes: 24 additions & 42 deletions cmd/dump.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,38 +49,6 @@ func addFile(w archiver.Writer, filePath string, absPath string, verbose bool) e
})
}

func addRecursive(w archiver.Writer, dirPath string, absPath string, verbose bool) error {
if verbose {
log.Info("Adding dir %s\n", dirPath)
}
dir, err := os.Open(absPath)
if err != nil {
return fmt.Errorf("Could not open directory %s: %s", absPath, err)
}
defer dir.Close()

files, err := dir.Readdir(0)
if err != nil {
return fmt.Errorf("Unable to list files in %s: %s", absPath, err)
}

if err := addFile(w, dirPath, absPath, false); err != nil {
return err
}

for _, fileInfo := range files {
if fileInfo.IsDir() {
err = addRecursive(w, filepath.Join(dirPath, fileInfo.Name()), filepath.Join(absPath, fileInfo.Name()), verbose)
} else {
err = addFile(w, filepath.Join(dirPath, fileInfo.Name()), filepath.Join(absPath, fileInfo.Name()), verbose)
}
if err != nil {
return err
}
}
return nil
}

func isSubdir(upper string, lower string) (bool, error) {
if relPath, err := filepath.Rel(upper, lower); err != nil {
return false, err
Expand Down Expand Up @@ -157,6 +125,10 @@ It can be used for backup and capture Gitea server image to send to maintainer`,
Name: "skip-log, L",
Usage: "Skip the log dumping",
},
cli.BoolFlag{
Name: "skip-custom-dir",
Usage: "Skip custom directory",
},
cli.GenericFlag{
Name: "type",
Value: outputTypeEnum,
Expand Down Expand Up @@ -211,6 +183,11 @@ func runDump(ctx *cli.Context) error {
}
defer file.Close()

absFileName, err := filepath.Abs(fileName)
if err != nil {
return err
}

verbose := ctx.Bool("verbose")
outType := ctx.String("type")
var iface interface{}
Expand All @@ -233,7 +210,7 @@ func runDump(ctx *cli.Context) error {
log.Info("Skip dumping local repositories")
} else {
log.Info("Dumping local repositories... %s", setting.RepoRootPath)
if err := addRecursive(w, "repos", setting.RepoRootPath, verbose); err != nil {
if err := addRecursiveExclude(w, "repos", setting.RepoRootPath, []string{absFileName}, verbose); err != nil {
fatal("Failed to include repositories: %v", err)
}

Expand Down Expand Up @@ -292,17 +269,21 @@ func runDump(ctx *cli.Context) error {
}
}

customDir, err := os.Stat(setting.CustomPath)
if err == nil && customDir.IsDir() {
if is, _ := isSubdir(setting.AppDataPath, setting.CustomPath); !is {
if err := addRecursive(w, "custom", setting.CustomPath, verbose); err != nil {
fatal("Failed to include custom: %v", err)
if ctx.IsSet("skip-custom-dir") && ctx.Bool("skip-custom-dir") {
log.Info("Skiping custom directory")
} else {
customDir, err := os.Stat(setting.CustomPath)
if err == nil && customDir.IsDir() {
if is, _ := isSubdir(setting.AppDataPath, setting.CustomPath); !is {
if err := addRecursiveExclude(w, "custom", setting.CustomPath, []string{absFileName}, verbose); err != nil {
fatal("Failed to include custom: %v", err)
}
} else {
log.Info("Custom dir %s is inside data dir %s, skipped", setting.CustomPath, setting.AppDataPath)
}
} else {
log.Info("Custom dir %s is inside data dir %s, skipped", setting.CustomPath, setting.AppDataPath)
log.Info("Custom dir %s doesn't exist, skipped", setting.CustomPath)
}
} else {
log.Info("Custom dir %s doesn't exist, skipped", setting.CustomPath)
}

isExist, err := util.IsExist(setting.AppDataPath)
Expand All @@ -325,6 +306,7 @@ func runDump(ctx *cli.Context) error {
excludes = append(excludes, setting.LFS.Path)
excludes = append(excludes, setting.Attachment.Path)
excludes = append(excludes, setting.LogRootPath)
excludes = append(excludes, absFileName)
if err := addRecursiveExclude(w, "data", setting.AppDataPath, excludes, verbose); err != nil {
fatal("Failed to include data directory: %v", err)
}
Expand Down Expand Up @@ -358,7 +340,7 @@ func runDump(ctx *cli.Context) error {
log.Error("Unable to check if %s exists. Error: %v", setting.LogRootPath, err)
}
if isExist {
if err := addRecursive(w, "log", setting.LogRootPath, verbose); err != nil {
if err := addRecursiveExclude(w, "log", setting.LogRootPath, []string{absFileName}, verbose); err != nil {
fatal("Failed to include log: %v", err)
}
}
Expand Down
8 changes: 8 additions & 0 deletions docs/content/doc/installation/from-source.en-us.md
Original file line number Diff line number Diff line change
Expand Up @@ -186,3 +186,11 @@ CC=aarch64-unknown-linux-gnu-gcc GOOS=linux GOARCH=arm64 TAGS="bindata sqlite sq
```

Replace `CC`, `GOOS`, and `GOARCH` as appropriate for your architecture target.

You will sometimes need to build a static compiled image. To do this you will need to add:

```
LDFLAGS="-linkmode external -extldflags '-static' $LDFLAGS" TAGS="netgo osusergo $TAGS" make build
```

This can be combined with `CC`, `GOOS`, and `GOARCH` as above.
1 change: 1 addition & 0 deletions docs/content/doc/usage/command-line.en-us.md
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,7 @@ in the current directory.
- `--file name`, `-f name`: Name of the dump file with will be created. Optional. (default: gitea-dump-[timestamp].zip).
- `--tempdir path`, `-t path`: Path to the temporary directory used. Optional. (default: /tmp).
- `--skip-repository`, `-R`: Skip the repository dumping. Optional.
- `--skip-custom-dir`: Skip dumping of the custom dir. Optional.
- `--database`, `-d`: Specify the database SQL syntax. Optional.
- `--verbose`, `-V`: If provided, shows additional details. Optional.
- Examples:
Expand Down
20 changes: 10 additions & 10 deletions integrations/api_releases_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,25 +154,25 @@ func TestAPIGetReleaseByTag(t *testing.T) {
assert.EqualValues(t, "Not Found", err.Message)
}

func TestAPIDeleteTagByName(t *testing.T) {
func TestAPIDeleteReleaseByTagName(t *testing.T) {
defer prepareTestEnv(t)()

repo := models.AssertExistsAndLoadBean(t, &models.Repository{ID: 1}).(*models.Repository)
owner := models.AssertExistsAndLoadBean(t, &models.User{ID: repo.OwnerID}).(*models.User)
session := loginUser(t, owner.LowerName)
token := getTokenForLoggedInUser(t, session)

urlStr := fmt.Sprintf("/api/v1/repos/%s/%s/releases/tags/delete-tag?token=%s",
owner.Name, repo.Name, token)
createNewReleaseUsingAPI(t, session, token, owner, repo, "release-tag", "", "Release Tag", "test")

req := NewRequestf(t, http.MethodDelete, urlStr)
// delete release
req := NewRequestf(t, http.MethodDelete, fmt.Sprintf("/api/v1/repos/%s/%s/releases/tags/release-tag?token=%s", owner.Name, repo.Name, token))
_ = session.MakeRequest(t, req, http.StatusNoContent)

// Make sure that actual releases can't be deleted outright
createNewReleaseUsingAPI(t, session, token, owner, repo, "release-tag", "", "Release Tag", "test")
urlStr = fmt.Sprintf("/api/v1/repos/%s/%s/releases/tags/release-tag?token=%s",
owner.Name, repo.Name, token)
// make sure release is deleted
req = NewRequestf(t, http.MethodDelete, fmt.Sprintf("/api/v1/repos/%s/%s/releases/tags/release-tag?token=%s", owner.Name, repo.Name, token))
_ = session.MakeRequest(t, req, http.StatusNotFound)

req = NewRequestf(t, http.MethodDelete, urlStr)
_ = session.MakeRequest(t, req, http.StatusConflict)
// delete release tag too
req = NewRequestf(t, http.MethodDelete, fmt.Sprintf("/api/v1/repos/%s/%s/tags/release-tag?token=%s", owner.Name, repo.Name, token))
_ = session.MakeRequest(t, req, http.StatusNoContent)
}
24 changes: 18 additions & 6 deletions integrations/api_repo_git_commits_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,14 @@ import (
"github.com/stretchr/testify/assert"
)

func compareCommitFiles(t *testing.T, expect []string, files []*api.CommitAffectedFiles) {
var actual []string
for i := range files {
actual = append(actual, files[i].Filename)
}
assert.ElementsMatch(t, expect, actual)
}

func TestAPIReposGitCommits(t *testing.T) {
defer prepareTestEnv(t)()
user := models.AssertExistsAndLoadBean(t, &models.User{ID: 2}).(*models.User)
Expand Down Expand Up @@ -56,10 +64,13 @@ func TestAPIReposGitCommitList(t *testing.T) {
var apiData []api.Commit
DecodeJSON(t, resp, &apiData)

assert.Equal(t, 3, len(apiData))
assert.Equal(t, "69554a64c1e6030f051e5c3f94bfbd773cd6a324", apiData[0].CommitMeta.SHA)
assert.Equal(t, "27566bd5738fc8b4e3fef3c5e72cce608537bd95", apiData[1].CommitMeta.SHA)
assert.Equal(t, "5099b81332712fe655e34e8dd63574f503f61811", apiData[2].CommitMeta.SHA)
assert.Len(t, apiData, 3)
assert.EqualValues(t, "69554a64c1e6030f051e5c3f94bfbd773cd6a324", apiData[0].CommitMeta.SHA)
compareCommitFiles(t, []string{"readme.md"}, apiData[0].Files)
assert.EqualValues(t, "27566bd5738fc8b4e3fef3c5e72cce608537bd95", apiData[1].CommitMeta.SHA)
compareCommitFiles(t, []string{"readme.md"}, apiData[1].Files)
assert.EqualValues(t, "5099b81332712fe655e34e8dd63574f503f61811", apiData[2].CommitMeta.SHA)
compareCommitFiles(t, []string{"readme.md"}, apiData[2].Files)
}

func TestAPIReposGitCommitListPage2Empty(t *testing.T) {
Expand All @@ -76,7 +87,7 @@ func TestAPIReposGitCommitListPage2Empty(t *testing.T) {
var apiData []api.Commit
DecodeJSON(t, resp, &apiData)

assert.Equal(t, 0, len(apiData))
assert.Len(t, apiData, 0)
}

func TestAPIReposGitCommitListDifferentBranch(t *testing.T) {
Expand All @@ -93,6 +104,7 @@ func TestAPIReposGitCommitListDifferentBranch(t *testing.T) {
var apiData []api.Commit
DecodeJSON(t, resp, &apiData)

assert.Equal(t, 1, len(apiData))
assert.Len(t, apiData, 1)
assert.Equal(t, "f27c2b2b03dcab38beaf89b0ab4ff61f6de63441", apiData[0].CommitMeta.SHA)
compareCommitFiles(t, []string{"readme.md"}, apiData[0].Files)
}
24 changes: 24 additions & 0 deletions integrations/api_repo_git_tags_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
package integrations

import (
"fmt"
"net/http"
"testing"

Expand Down Expand Up @@ -59,3 +60,26 @@ func TestAPIGitTags(t *testing.T) {
badReq := NewRequestf(t, "GET", "/api/v1/repos/%s/%s/git/tags/%s?token=%s", user.Name, repo.Name, commit.ID.String(), token)
session.MakeRequest(t, badReq, http.StatusBadRequest)
}

func TestAPIDeleteTagByName(t *testing.T) {
defer prepareTestEnv(t)()

repo := models.AssertExistsAndLoadBean(t, &models.Repository{ID: 1}).(*models.Repository)
owner := models.AssertExistsAndLoadBean(t, &models.User{ID: repo.OwnerID}).(*models.User)
session := loginUser(t, owner.LowerName)
token := getTokenForLoggedInUser(t, session)

urlStr := fmt.Sprintf("/api/v1/repos/%s/%s/tags/delete-tag?token=%s",
owner.Name, repo.Name, token)

req := NewRequestf(t, http.MethodDelete, urlStr)
_ = session.MakeRequest(t, req, http.StatusNoContent)

// Make sure that actual releases can't be deleted outright
createNewReleaseUsingAPI(t, session, token, owner, repo, "release-tag", "", "Release Tag", "test")
urlStr = fmt.Sprintf("/api/v1/repos/%s/%s/tags/release-tag?token=%s",
owner.Name, repo.Name, token)

req = NewRequestf(t, http.MethodDelete, urlStr)
_ = session.MakeRequest(t, req, http.StatusConflict)
}
10 changes: 5 additions & 5 deletions models/issue.go
Original file line number Diff line number Diff line change
Expand Up @@ -745,11 +745,11 @@ func AddDeletePRBranchComment(doer *User, repo *Repository, issueID int64, branc
return err
}
var opts = &CreateCommentOptions{
Type: CommentTypeDeleteBranch,
Doer: doer,
Repo: repo,
Issue: issue,
CommitSHA: branchName,
Type: CommentTypeDeleteBranch,
Doer: doer,
Repo: repo,
Issue: issue,
OldRef: branchName,
}
if _, err = createComment(sess, opts); err != nil {
return err
Expand Down
2 changes: 2 additions & 0 deletions models/migrations/migrations.go
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,8 @@ var migrations = []Migration{
// v168 -> v169
NewMigration("Recreate user table to fix default values", recreateUserTableToFixDefaultValues),
// v169 -> v170
NewMigration("Update DeleteBranch comments to set the old_ref to the commit_sha", commentTypeDeleteBranchUseOldRef),
// v170 -> v171
NewMigration("Add agit style pull request support", addAgitStylePullRequest),
}

Expand Down
16 changes: 3 additions & 13 deletions models/migrations/v169.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,10 @@
package migrations

import (
"fmt"

"xorm.io/xorm"
)

func addAgitStylePullRequest(x *xorm.Engine) error {
type PullRequestStyle int

type PullRequest struct {
Style PullRequestStyle
}

if err := x.Sync2(new(PullRequest)); err != nil {
return fmt.Errorf("Sync2: %v", err)
}
return nil
func commentTypeDeleteBranchUseOldRef(x *xorm.Engine) error {
_, err := x.Exec("UPDATE comment SET old_ref = commit_sha, commit_sha = '' WHERE type = 11")
return err
}
24 changes: 24 additions & 0 deletions models/migrations/v170.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// Copyright 2021 The Gitea Authors. All rights reserved.
// Use of this source code is governed by a MIT-style
// license that can be found in the LICENSE file.

package migrations

import (
"fmt"

"xorm.io/xorm"
)

func addAgitStylePullRequest(x *xorm.Engine) error {
type PullRequestStyle int

type PullRequest struct {
Style PullRequestStyle
}

if err := x.Sync2(new(PullRequest)); err != nil {
return fmt.Errorf("Sync2: %v", err)
}
return nil
}
15 changes: 15 additions & 0 deletions modules/convert/git_commit.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,20 @@ func ToCommit(repo *models.Repository, commit *git.Commit, userCache map[string]
}
}

// Retrieve files affected by the commit
fileStatus, err := git.GetCommitFileStatus(repo.RepoPath(), commit.ID.String())
if err != nil {
return nil, err
}
affectedFileList := make([]*api.CommitAffectedFiles, 0, len(fileStatus.Added)+len(fileStatus.Removed)+len(fileStatus.Modified))
for _, files := range [][]string{fileStatus.Added, fileStatus.Removed, fileStatus.Modified} {
for _, filename := range files {
affectedFileList = append(affectedFileList, &api.CommitAffectedFiles{
Filename: filename,
})
}
}

return &api.Commit{
CommitMeta: &api.CommitMeta{
URL: repo.APIURL() + "/git/commits/" + commit.ID.String(),
Expand Down Expand Up @@ -162,5 +176,6 @@ func ToCommit(repo *models.Repository, commit *git.Commit, userCache map[string]
Author: apiAuthor,
Committer: apiCommitter,
Parents: apiParents,
Files: affectedFileList,
}, nil
}
3 changes: 0 additions & 3 deletions modules/git/blob_nogogit.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@ import (
"io"
"strconv"
"strings"

gitea_log "code.gitea.io/gitea/modules/log"
)

// Blob represents a Git object.
Expand All @@ -35,7 +33,6 @@ func (b *Blob) DataAsync() (io.ReadCloser, error) {
err := NewCommand("cat-file", "--batch").RunInDirFullPipeline(b.repoPath, stdoutWriter, stderr, strings.NewReader(b.ID.String()+"\n"))
if err != nil {
err = ConcatenateError(err, stderr.String())
gitea_log.Error("Blob.DataAsync Error: %v", err)
_ = stdoutWriter.CloseWithError(err)
} else {
_ = stdoutWriter.Close()
Expand Down
Loading

0 comments on commit 501f850

Please sign in to comment.