mirror of
https://github.com/go-gitea/gitea
synced 2024-12-24 03:35:55 +01:00
Make git.OpenRepository accept Context (#19260)
* OpenRepositoryCtx -> OpenRepository * OpenRepository -> openRepositoryWithDefaultContext, only for internal usage
This commit is contained in:
parent
889a8c268c
commit
3e88af898a
@ -724,7 +724,7 @@ func runRepoSyncReleases(_ *cli.Context) error {
|
|||||||
log.Trace("Processing next %d repos of %d", len(repos), count)
|
log.Trace("Processing next %d repos of %d", len(repos), count)
|
||||||
for _, repo := range repos {
|
for _, repo := range repos {
|
||||||
log.Trace("Synchronizing repo %s with path %s", repo.FullName(), repo.RepoPath())
|
log.Trace("Synchronizing repo %s with path %s", repo.FullName(), repo.RepoPath())
|
||||||
gitRepo, err := git.OpenRepositoryCtx(ctx, repo.RepoPath())
|
gitRepo, err := git.OpenRepository(ctx, repo.RepoPath())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Warn("OpenRepository: %v", err)
|
log.Warn("OpenRepository: %v", err)
|
||||||
continue
|
continue
|
||||||
|
@ -105,7 +105,7 @@ func TestAPICreateAndUpdateRelease(t *testing.T) {
|
|||||||
session := loginUser(t, owner.LowerName)
|
session := loginUser(t, owner.LowerName)
|
||||||
token := getTokenForLoggedInUser(t, session)
|
token := getTokenForLoggedInUser(t, session)
|
||||||
|
|
||||||
gitRepo, err := git.OpenRepository(repo.RepoPath())
|
gitRepo, err := git.OpenRepository(git.DefaultContext, repo.RepoPath())
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
defer gitRepo.Close()
|
defer gitRepo.Close()
|
||||||
|
|
||||||
@ -167,7 +167,7 @@ func TestAPICreateReleaseToDefaultBranchOnExistingTag(t *testing.T) {
|
|||||||
session := loginUser(t, owner.LowerName)
|
session := loginUser(t, owner.LowerName)
|
||||||
token := getTokenForLoggedInUser(t, session)
|
token := getTokenForLoggedInUser(t, session)
|
||||||
|
|
||||||
gitRepo, err := git.OpenRepository(repo.RepoPath())
|
gitRepo, err := git.OpenRepository(git.DefaultContext, repo.RepoPath())
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
defer gitRepo.Close()
|
defer gitRepo.Close()
|
||||||
|
|
||||||
|
@ -5,6 +5,7 @@
|
|||||||
package integrations
|
package integrations
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
stdCtx "context"
|
||||||
"encoding/base64"
|
"encoding/base64"
|
||||||
"fmt"
|
"fmt"
|
||||||
"net/http"
|
"net/http"
|
||||||
@ -167,7 +168,7 @@ func TestAPICreateFile(t *testing.T) {
|
|||||||
url := fmt.Sprintf("/api/v1/repos/%s/%s/contents/%s?token=%s", user2.Name, repo1.Name, treePath, token2)
|
url := fmt.Sprintf("/api/v1/repos/%s/%s/contents/%s?token=%s", user2.Name, repo1.Name, treePath, token2)
|
||||||
req := NewRequestWithJSON(t, "POST", url, &createFileOptions)
|
req := NewRequestWithJSON(t, "POST", url, &createFileOptions)
|
||||||
resp := session.MakeRequest(t, req, http.StatusCreated)
|
resp := session.MakeRequest(t, req, http.StatusCreated)
|
||||||
gitRepo, _ := git.OpenRepository(repo1.RepoPath())
|
gitRepo, _ := git.OpenRepository(stdCtx.Background(), repo1.RepoPath())
|
||||||
commitID, _ := gitRepo.GetBranchCommitID(createFileOptions.NewBranchName)
|
commitID, _ := gitRepo.GetBranchCommitID(createFileOptions.NewBranchName)
|
||||||
expectedFileResponse := getExpectedFileResponseForCreate("user2/repo1", commitID, treePath)
|
expectedFileResponse := getExpectedFileResponseForCreate("user2/repo1", commitID, treePath)
|
||||||
var fileResponse api.FileResponse
|
var fileResponse api.FileResponse
|
||||||
@ -286,7 +287,7 @@ func TestAPICreateFile(t *testing.T) {
|
|||||||
req = NewRequestWithJSON(t, "POST", url, &createFileOptions)
|
req = NewRequestWithJSON(t, "POST", url, &createFileOptions)
|
||||||
resp = session.MakeRequest(t, req, http.StatusCreated)
|
resp = session.MakeRequest(t, req, http.StatusCreated)
|
||||||
emptyRepo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{OwnerName: "user2", Name: "empty-repo"}).(*repo_model.Repository) // public repo
|
emptyRepo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{OwnerName: "user2", Name: "empty-repo"}).(*repo_model.Repository) // public repo
|
||||||
gitRepo, _ := git.OpenRepository(emptyRepo.RepoPath())
|
gitRepo, _ := git.OpenRepository(stdCtx.Background(), emptyRepo.RepoPath())
|
||||||
commitID, _ := gitRepo.GetBranchCommitID(createFileOptions.NewBranchName)
|
commitID, _ := gitRepo.GetBranchCommitID(createFileOptions.NewBranchName)
|
||||||
expectedFileResponse := getExpectedFileResponseForCreate("user2/empty-repo", commitID, treePath)
|
expectedFileResponse := getExpectedFileResponseForCreate("user2/empty-repo", commitID, treePath)
|
||||||
DecodeJSON(t, resp, &fileResponse)
|
DecodeJSON(t, resp, &fileResponse)
|
||||||
|
@ -5,6 +5,7 @@
|
|||||||
package integrations
|
package integrations
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
stdCtx "context"
|
||||||
"encoding/base64"
|
"encoding/base64"
|
||||||
"fmt"
|
"fmt"
|
||||||
"net/http"
|
"net/http"
|
||||||
@ -134,7 +135,7 @@ func TestAPIUpdateFile(t *testing.T) {
|
|||||||
url := fmt.Sprintf("/api/v1/repos/%s/%s/contents/%s?token=%s", user2.Name, repo1.Name, treePath, token2)
|
url := fmt.Sprintf("/api/v1/repos/%s/%s/contents/%s?token=%s", user2.Name, repo1.Name, treePath, token2)
|
||||||
req := NewRequestWithJSON(t, "PUT", url, &updateFileOptions)
|
req := NewRequestWithJSON(t, "PUT", url, &updateFileOptions)
|
||||||
resp := session.MakeRequest(t, req, http.StatusOK)
|
resp := session.MakeRequest(t, req, http.StatusOK)
|
||||||
gitRepo, _ := git.OpenRepository(repo1.RepoPath())
|
gitRepo, _ := git.OpenRepository(stdCtx.Background(), repo1.RepoPath())
|
||||||
commitID, _ := gitRepo.GetBranchCommitID(updateFileOptions.NewBranchName)
|
commitID, _ := gitRepo.GetBranchCommitID(updateFileOptions.NewBranchName)
|
||||||
expectedFileResponse := getExpectedFileResponseForUpdate(commitID, treePath)
|
expectedFileResponse := getExpectedFileResponseForUpdate(commitID, treePath)
|
||||||
var fileResponse api.FileResponse
|
var fileResponse api.FileResponse
|
||||||
|
@ -75,7 +75,7 @@ func testAPIGetContentsList(t *testing.T, u *url.URL) {
|
|||||||
err := repo_service.CreateNewBranch(git.DefaultContext, user2, repo1, repo1.DefaultBranch, newBranch)
|
err := repo_service.CreateNewBranch(git.DefaultContext, user2, repo1, repo1.DefaultBranch, newBranch)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
// Get the commit ID of the default branch
|
// Get the commit ID of the default branch
|
||||||
gitRepo, err := git.OpenRepository(repo1.RepoPath())
|
gitRepo, err := git.OpenRepository(git.DefaultContext, repo1.RepoPath())
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
defer gitRepo.Close()
|
defer gitRepo.Close()
|
||||||
|
|
||||||
|
@ -76,7 +76,7 @@ func testAPIGetContents(t *testing.T, u *url.URL) {
|
|||||||
err := repo_service.CreateNewBranch(git.DefaultContext, user2, repo1, repo1.DefaultBranch, newBranch)
|
err := repo_service.CreateNewBranch(git.DefaultContext, user2, repo1, repo1.DefaultBranch, newBranch)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
// Get the commit ID of the default branch
|
// Get the commit ID of the default branch
|
||||||
gitRepo, err := git.OpenRepository(repo1.RepoPath())
|
gitRepo, err := git.OpenRepository(git.DefaultContext, repo1.RepoPath())
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
defer gitRepo.Close()
|
defer gitRepo.Close()
|
||||||
|
|
||||||
|
@ -31,7 +31,7 @@ func TestAPIGitTags(t *testing.T) {
|
|||||||
git.NewCommand(git.DefaultContext, "config", "user.name", user.Name).RunInDir(repo.RepoPath())
|
git.NewCommand(git.DefaultContext, "config", "user.name", user.Name).RunInDir(repo.RepoPath())
|
||||||
git.NewCommand(git.DefaultContext, "config", "user.email", user.Email).RunInDir(repo.RepoPath())
|
git.NewCommand(git.DefaultContext, "config", "user.email", user.Email).RunInDir(repo.RepoPath())
|
||||||
|
|
||||||
gitRepo, _ := git.OpenRepository(repo.RepoPath())
|
gitRepo, _ := git.OpenRepository(git.DefaultContext, repo.RepoPath())
|
||||||
defer gitRepo.Close()
|
defer gitRepo.Close()
|
||||||
|
|
||||||
commit, _ := gitRepo.GetBranchCommit("master")
|
commit, _ := gitRepo.GetBranchCommit("master")
|
||||||
|
@ -624,7 +624,7 @@ func doCreateAgitFlowPull(dstPath string, ctx *APITestContext, baseBranch, headB
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
gitRepo, err := git.OpenRepository(dstPath)
|
gitRepo, err := git.OpenRepository(git.DefaultContext, dstPath)
|
||||||
if !assert.NoError(t, err) {
|
if !assert.NoError(t, err) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -52,7 +52,7 @@ func TestMirrorPull(t *testing.T) {
|
|||||||
mirror, err := repository.MigrateRepositoryGitData(ctx, user, mirrorRepo, opts, nil)
|
mirror, err := repository.MigrateRepositoryGitData(ctx, user, mirrorRepo, opts, nil)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
|
|
||||||
gitRepo, err := git.OpenRepository(repoPath)
|
gitRepo, err := git.OpenRepository(git.DefaultContext, repoPath)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
defer gitRepo.Close()
|
defer gitRepo.Close()
|
||||||
|
|
||||||
|
@ -54,14 +54,14 @@ func testMirrorPush(t *testing.T, u *url.URL) {
|
|||||||
ok := mirror_service.SyncPushMirror(context.Background(), mirrors[0].ID)
|
ok := mirror_service.SyncPushMirror(context.Background(), mirrors[0].ID)
|
||||||
assert.True(t, ok)
|
assert.True(t, ok)
|
||||||
|
|
||||||
srcGitRepo, err := git.OpenRepository(srcRepo.RepoPath())
|
srcGitRepo, err := git.OpenRepository(git.DefaultContext, srcRepo.RepoPath())
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
defer srcGitRepo.Close()
|
defer srcGitRepo.Close()
|
||||||
|
|
||||||
srcCommit, err := srcGitRepo.GetBranchCommit("master")
|
srcCommit, err := srcGitRepo.GetBranchCommit("master")
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
|
|
||||||
mirrorGitRepo, err := git.OpenRepository(mirrorRepo.RepoPath())
|
mirrorGitRepo, err := git.OpenRepository(git.DefaultContext, mirrorRepo.RepoPath())
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
defer mirrorGitRepo.Close()
|
defer mirrorGitRepo.Close()
|
||||||
|
|
||||||
|
@ -238,7 +238,7 @@ func TestCantMergeConflict(t *testing.T) {
|
|||||||
BaseBranch: "base",
|
BaseBranch: "base",
|
||||||
}).(*models.PullRequest)
|
}).(*models.PullRequest)
|
||||||
|
|
||||||
gitRepo, err := git.OpenRepository(repo_model.RepoPath(user1.Name, repo1.Name))
|
gitRepo, err := git.OpenRepository(git.DefaultContext, repo_model.RepoPath(user1.Name, repo1.Name))
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
|
|
||||||
err = pull.Merge(git.DefaultContext, pr, user1, gitRepo, repo_model.MergeStyleMerge, "", "CONFLICT")
|
err = pull.Merge(git.DefaultContext, pr, user1, gitRepo, repo_model.MergeStyleMerge, "", "CONFLICT")
|
||||||
@ -333,7 +333,7 @@ func TestCantMergeUnrelated(t *testing.T) {
|
|||||||
session.MakeRequest(t, req, http.StatusCreated)
|
session.MakeRequest(t, req, http.StatusCreated)
|
||||||
|
|
||||||
// Now this PR could be marked conflict - or at least a race may occur - so drop down to pure code at this point...
|
// Now this PR could be marked conflict - or at least a race may occur - so drop down to pure code at this point...
|
||||||
gitRepo, err := git.OpenRepository(path)
|
gitRepo, err := git.OpenRepository(git.DefaultContext, path)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
pr := unittest.AssertExistsAndLoadBean(t, &models.PullRequest{
|
pr := unittest.AssertExistsAndLoadBean(t, &models.PullRequest{
|
||||||
HeadRepoID: repo1.ID,
|
HeadRepoID: repo1.ID,
|
||||||
|
@ -90,7 +90,7 @@ func createOutdatedPR(t *testing.T, actor, forkOrg *user_model.User) *models.Pul
|
|||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
assert.NotEmpty(t, baseRepo)
|
assert.NotEmpty(t, baseRepo)
|
||||||
|
|
||||||
headRepo, err := repo_service.ForkRepository(actor, forkOrg, repo_service.ForkRepoOptions{
|
headRepo, err := repo_service.ForkRepository(git.DefaultContext, actor, forkOrg, repo_service.ForkRepoOptions{
|
||||||
BaseRepo: baseRepo,
|
BaseRepo: baseRepo,
|
||||||
Name: "repo-pr-update",
|
Name: "repo-pr-update",
|
||||||
Description: "desc",
|
Description: "desc",
|
||||||
|
@ -202,7 +202,7 @@ func TestCreateOrUpdateRepoFileForCreate(t *testing.T) {
|
|||||||
|
|
||||||
// asserts
|
// asserts
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
gitRepo, _ := git.OpenRepository(repo.RepoPath())
|
gitRepo, _ := git.OpenRepository(git.DefaultContext, repo.RepoPath())
|
||||||
defer gitRepo.Close()
|
defer gitRepo.Close()
|
||||||
|
|
||||||
commitID, _ := gitRepo.GetBranchCommitID(opts.NewBranch)
|
commitID, _ := gitRepo.GetBranchCommitID(opts.NewBranch)
|
||||||
@ -238,7 +238,7 @@ func TestCreateOrUpdateRepoFileForUpdate(t *testing.T) {
|
|||||||
|
|
||||||
// asserts
|
// asserts
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
gitRepo, _ := git.OpenRepository(repo.RepoPath())
|
gitRepo, _ := git.OpenRepository(git.DefaultContext, repo.RepoPath())
|
||||||
defer gitRepo.Close()
|
defer gitRepo.Close()
|
||||||
|
|
||||||
commitID, _ := gitRepo.GetBranchCommitID(opts.NewBranch)
|
commitID, _ := gitRepo.GetBranchCommitID(opts.NewBranch)
|
||||||
@ -273,7 +273,7 @@ func TestCreateOrUpdateRepoFileForUpdateWithFileMove(t *testing.T) {
|
|||||||
|
|
||||||
// asserts
|
// asserts
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
gitRepo, _ := git.OpenRepository(repo.RepoPath())
|
gitRepo, _ := git.OpenRepository(git.DefaultContext, repo.RepoPath())
|
||||||
defer gitRepo.Close()
|
defer gitRepo.Close()
|
||||||
|
|
||||||
commit, _ := gitRepo.GetBranchCommit(opts.NewBranch)
|
commit, _ := gitRepo.GetBranchCommit(opts.NewBranch)
|
||||||
@ -323,7 +323,7 @@ func TestCreateOrUpdateRepoFileWithoutBranchNames(t *testing.T) {
|
|||||||
|
|
||||||
// asserts
|
// asserts
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
gitRepo, _ := git.OpenRepository(repo.RepoPath())
|
gitRepo, _ := git.OpenRepository(git.DefaultContext, repo.RepoPath())
|
||||||
defer gitRepo.Close()
|
defer gitRepo.Close()
|
||||||
|
|
||||||
commitID, _ := gitRepo.GetBranchCommitID(repo.DefaultBranch)
|
commitID, _ := gitRepo.GetBranchCommitID(repo.DefaultBranch)
|
||||||
|
@ -109,7 +109,7 @@ func fixPublisherIDforTagReleases(x *xorm.Engine) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
gitRepo, err = git.OpenRepositoryCtx(git.DefaultContext, repoPath(repo.OwnerName, repo.Name))
|
gitRepo, err = git.OpenRepository(git.DefaultContext, repoPath(repo.OwnerName, repo.Name))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error("Error whilst opening git repo for [%d]%s/%s. Error: %v", repo.ID, repo.OwnerName, repo.Name, err)
|
log.Error("Error whilst opening git repo for [%d]%s/%s. Error: %v", repo.ID, repo.OwnerName, repo.Name, err)
|
||||||
return err
|
return err
|
||||||
|
@ -99,7 +99,7 @@ func fixReleaseSha1OnReleaseTable(x *xorm.Engine) error {
|
|||||||
userCache[repo.OwnerID] = user
|
userCache[repo.OwnerID] = user
|
||||||
}
|
}
|
||||||
|
|
||||||
gitRepo, err = git.OpenRepositoryCtx(git.DefaultContext, RepoPath(user.Name, repo.Name))
|
gitRepo, err = git.OpenRepository(git.DefaultContext, RepoPath(user.Name, repo.Name))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -10,6 +10,7 @@ import (
|
|||||||
"code.gitea.io/gitea/models/db"
|
"code.gitea.io/gitea/models/db"
|
||||||
"code.gitea.io/gitea/models/perm"
|
"code.gitea.io/gitea/models/perm"
|
||||||
repo_model "code.gitea.io/gitea/models/repo"
|
repo_model "code.gitea.io/gitea/models/repo"
|
||||||
|
|
||||||
"xorm.io/builder"
|
"xorm.io/builder"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -9,6 +9,7 @@ import (
|
|||||||
|
|
||||||
"code.gitea.io/gitea/models/db"
|
"code.gitea.io/gitea/models/db"
|
||||||
user_model "code.gitea.io/gitea/models/user"
|
user_model "code.gitea.io/gitea/models/user"
|
||||||
|
|
||||||
"xorm.io/builder"
|
"xorm.io/builder"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -247,8 +247,8 @@ func CanUserForkRepo(user *user_model.User, repo *repo_model.Repository) (bool,
|
|||||||
}
|
}
|
||||||
|
|
||||||
// FindUserOrgForks returns the forked repositories for one user from a repository
|
// FindUserOrgForks returns the forked repositories for one user from a repository
|
||||||
func FindUserOrgForks(repoID, userID int64) ([]*repo_model.Repository, error) {
|
func FindUserOrgForks(ctx context.Context, repoID, userID int64) ([]*repo_model.Repository, error) {
|
||||||
var cond builder.Cond = builder.And(
|
cond := builder.And(
|
||||||
builder.Eq{"fork_id": repoID},
|
builder.Eq{"fork_id": repoID},
|
||||||
builder.In("owner_id",
|
builder.In("owner_id",
|
||||||
builder.Select("org_id").
|
builder.Select("org_id").
|
||||||
@ -258,23 +258,23 @@ func FindUserOrgForks(repoID, userID int64) ([]*repo_model.Repository, error) {
|
|||||||
)
|
)
|
||||||
|
|
||||||
var repos []*repo_model.Repository
|
var repos []*repo_model.Repository
|
||||||
return repos, db.GetEngine(db.DefaultContext).Table("repository").Where(cond).Find(&repos)
|
return repos, db.GetEngine(ctx).Table("repository").Where(cond).Find(&repos)
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetForksByUserAndOrgs return forked repos of the user and owned orgs
|
// GetForksByUserAndOrgs return forked repos of the user and owned orgs
|
||||||
func GetForksByUserAndOrgs(user *user_model.User, repo *repo_model.Repository) ([]*repo_model.Repository, error) {
|
func GetForksByUserAndOrgs(ctx context.Context, user *user_model.User, repo *repo_model.Repository) ([]*repo_model.Repository, error) {
|
||||||
var repoList []*repo_model.Repository
|
var repoList []*repo_model.Repository
|
||||||
if user == nil {
|
if user == nil {
|
||||||
return repoList, nil
|
return repoList, nil
|
||||||
}
|
}
|
||||||
forkedRepo, err := repo_model.GetUserFork(repo.ID, user.ID)
|
forkedRepo, err := repo_model.GetUserFork(ctx, repo.ID, user.ID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return repoList, err
|
return repoList, err
|
||||||
}
|
}
|
||||||
if forkedRepo != nil {
|
if forkedRepo != nil {
|
||||||
repoList = append(repoList, forkedRepo)
|
repoList = append(repoList, forkedRepo)
|
||||||
}
|
}
|
||||||
orgForks, err := FindUserOrgForks(repo.ID, user.ID)
|
orgForks, err := FindUserOrgForks(ctx, repo.ID, user.ID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -44,9 +44,9 @@ func HasForkedRepo(ownerID, repoID int64) bool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// GetUserFork return user forked repository from this repository, if not forked return nil
|
// GetUserFork return user forked repository from this repository, if not forked return nil
|
||||||
func GetUserFork(repoID, userID int64) (*Repository, error) {
|
func GetUserFork(ctx context.Context, repoID, userID int64) (*Repository, error) {
|
||||||
var forkedRepo Repository
|
var forkedRepo Repository
|
||||||
has, err := db.GetEngine(db.DefaultContext).Where("fork_id = ?", repoID).And("owner_id = ?", userID).Get(&forkedRepo)
|
has, err := db.GetEngine(ctx).Where("fork_id = ?", repoID).And("owner_id = ?", userID).Get(&forkedRepo)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -7,6 +7,7 @@ package repo
|
|||||||
import (
|
import (
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
"code.gitea.io/gitea/models/db"
|
||||||
"code.gitea.io/gitea/models/unittest"
|
"code.gitea.io/gitea/models/unittest"
|
||||||
|
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
@ -19,14 +20,14 @@ func TestGetUserFork(t *testing.T) {
|
|||||||
repo, err := GetRepositoryByID(10)
|
repo, err := GetRepositoryByID(10)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
assert.NotNil(t, repo)
|
assert.NotNil(t, repo)
|
||||||
repo, err = GetUserFork(repo.ID, 13)
|
repo, err = GetUserFork(db.DefaultContext, repo.ID, 13)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
assert.NotNil(t, repo)
|
assert.NotNil(t, repo)
|
||||||
|
|
||||||
repo, err = GetRepositoryByID(9)
|
repo, err = GetRepositoryByID(9)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
assert.NotNil(t, repo)
|
assert.NotNil(t, repo)
|
||||||
repo, err = GetUserFork(repo.ID, 13)
|
repo, err = GetUserFork(db.DefaultContext, repo.ID, 13)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
assert.Nil(t, repo)
|
assert.Nil(t, repo)
|
||||||
}
|
}
|
||||||
|
@ -331,7 +331,7 @@ func ReferencesGitRepo(allowEmpty bool) func(ctx *APIContext) (cancel context.Ca
|
|||||||
// For API calls.
|
// For API calls.
|
||||||
if ctx.Repo.GitRepo == nil {
|
if ctx.Repo.GitRepo == nil {
|
||||||
repoPath := repo_model.RepoPath(ctx.Repo.Owner.Name, ctx.Repo.Repository.Name)
|
repoPath := repo_model.RepoPath(ctx.Repo.Owner.Name, ctx.Repo.Repository.Name)
|
||||||
gitRepo, err := git.OpenRepositoryCtx(ctx, repoPath)
|
gitRepo, err := git.OpenRepository(ctx, repoPath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "RepoRef Invalid repo "+repoPath, err)
|
ctx.Error(http.StatusInternalServerError, "RepoRef Invalid repo "+repoPath, err)
|
||||||
return
|
return
|
||||||
@ -388,7 +388,7 @@ func RepoRefForAPI(next http.Handler) http.Handler {
|
|||||||
|
|
||||||
if ctx.Repo.GitRepo == nil {
|
if ctx.Repo.GitRepo == nil {
|
||||||
repoPath := repo_model.RepoPath(ctx.Repo.Owner.Name, ctx.Repo.Repository.Name)
|
repoPath := repo_model.RepoPath(ctx.Repo.Owner.Name, ctx.Repo.Repository.Name)
|
||||||
ctx.Repo.GitRepo, err = git.OpenRepositoryCtx(ctx, repoPath)
|
ctx.Repo.GitRepo, err = git.OpenRepository(ctx, repoPath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.InternalServerError(err)
|
ctx.InternalServerError(err)
|
||||||
return
|
return
|
||||||
|
@ -529,7 +529,7 @@ func RepoAssignment(ctx *Context) (cancel context.CancelFunc) {
|
|||||||
}
|
}
|
||||||
ctx.Data["CanSignedUserFork"] = canSignedUserFork
|
ctx.Data["CanSignedUserFork"] = canSignedUserFork
|
||||||
|
|
||||||
userAndOrgForks, err := models.GetForksByUserAndOrgs(ctx.Doer, ctx.Repo.Repository)
|
userAndOrgForks, err := models.GetForksByUserAndOrgs(ctx, ctx.Doer, ctx.Repo.Repository)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.ServerError("GetForksByUserAndOrgs", err)
|
ctx.ServerError("GetForksByUserAndOrgs", err)
|
||||||
return
|
return
|
||||||
@ -588,7 +588,7 @@ func RepoAssignment(ctx *Context) (cancel context.CancelFunc) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
gitRepo, err := git.OpenRepositoryCtx(ctx, repo_model.RepoPath(userName, repoName))
|
gitRepo, err := git.OpenRepository(ctx, repo_model.RepoPath(userName, repoName))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if strings.Contains(err.Error(), "repository does not exist") || strings.Contains(err.Error(), "no such file or directory") {
|
if strings.Contains(err.Error(), "repository does not exist") || strings.Contains(err.Error(), "no such file or directory") {
|
||||||
log.Error("Repository %-v has a broken repository on the file system: %s Error: %v", ctx.Repo.Repository, ctx.Repo.Repository.RepoPath(), err)
|
log.Error("Repository %-v has a broken repository on the file system: %s Error: %v", ctx.Repo.Repository, ctx.Repo.Repository.RepoPath(), err)
|
||||||
@ -846,7 +846,7 @@ func RepoRefByType(refType RepoRefType, ignoreNotExistErr ...bool) func(*Context
|
|||||||
|
|
||||||
if ctx.Repo.GitRepo == nil {
|
if ctx.Repo.GitRepo == nil {
|
||||||
repoPath := repo_model.RepoPath(ctx.Repo.Owner.Name, ctx.Repo.Repository.Name)
|
repoPath := repo_model.RepoPath(ctx.Repo.Owner.Name, ctx.Repo.Repository.Name)
|
||||||
ctx.Repo.GitRepo, err = git.OpenRepositoryCtx(ctx, repoPath)
|
ctx.Repo.GitRepo, err = git.OpenRepository(ctx, repoPath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.ServerError("RepoRef Invalid repo "+repoPath, err)
|
ctx.ServerError("RepoRef Invalid repo "+repoPath, err)
|
||||||
return
|
return
|
||||||
|
@ -85,7 +85,7 @@ func ToAPIPullRequest(ctx context.Context, pr *models.PullRequest, doer *user_mo
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
gitRepo, err := git.OpenRepositoryCtx(ctx, pr.BaseRepo.RepoPath())
|
gitRepo, err := git.OpenRepository(ctx, pr.BaseRepo.RepoPath())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error("OpenRepository[%s]: %v", pr.BaseRepo.RepoPath(), err)
|
log.Error("OpenRepository[%s]: %v", pr.BaseRepo.RepoPath(), err)
|
||||||
return nil
|
return nil
|
||||||
@ -111,7 +111,7 @@ func ToAPIPullRequest(ctx context.Context, pr *models.PullRequest, doer *user_mo
|
|||||||
}
|
}
|
||||||
|
|
||||||
if pr.Flow == models.PullRequestFlowAGit {
|
if pr.Flow == models.PullRequestFlowAGit {
|
||||||
gitRepo, err := git.OpenRepositoryCtx(ctx, pr.BaseRepo.RepoPath())
|
gitRepo, err := git.OpenRepository(ctx, pr.BaseRepo.RepoPath())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error("OpenRepository[%s]: %v", pr.GetGitRefName(), err)
|
log.Error("OpenRepository[%s]: %v", pr.GetGitRefName(), err)
|
||||||
return nil
|
return nil
|
||||||
@ -138,7 +138,7 @@ func ToAPIPullRequest(ctx context.Context, pr *models.PullRequest, doer *user_mo
|
|||||||
apiPullRequest.Head.RepoID = pr.HeadRepo.ID
|
apiPullRequest.Head.RepoID = pr.HeadRepo.ID
|
||||||
apiPullRequest.Head.Repository = ToRepo(pr.HeadRepo, p.AccessMode)
|
apiPullRequest.Head.Repository = ToRepo(pr.HeadRepo, p.AccessMode)
|
||||||
|
|
||||||
headGitRepo, err := git.OpenRepositoryCtx(ctx, pr.HeadRepo.RepoPath())
|
headGitRepo, err := git.OpenRepository(ctx, pr.HeadRepo.RepoPath())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error("OpenRepository[%s]: %v", pr.HeadRepo.RepoPath(), err)
|
log.Error("OpenRepository[%s]: %v", pr.HeadRepo.RepoPath(), err)
|
||||||
return nil
|
return nil
|
||||||
@ -174,7 +174,7 @@ func ToAPIPullRequest(ctx context.Context, pr *models.PullRequest, doer *user_mo
|
|||||||
}
|
}
|
||||||
|
|
||||||
if len(apiPullRequest.Head.Sha) == 0 && len(apiPullRequest.Head.Ref) != 0 {
|
if len(apiPullRequest.Head.Sha) == 0 && len(apiPullRequest.Head.Ref) != 0 {
|
||||||
baseGitRepo, err := git.OpenRepositoryCtx(ctx, pr.BaseRepo.RepoPath())
|
baseGitRepo, err := git.OpenRepository(ctx, pr.BaseRepo.RepoPath())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error("OpenRepository[%s]: %v", pr.BaseRepo.RepoPath(), err)
|
log.Error("OpenRepository[%s]: %v", pr.BaseRepo.RepoPath(), err)
|
||||||
return nil
|
return nil
|
||||||
|
@ -88,7 +88,7 @@ func checkEnablePushOptions(ctx context.Context, logger log.Logger, autofix bool
|
|||||||
|
|
||||||
if err := iterateRepositories(ctx, func(repo *repo_model.Repository) error {
|
if err := iterateRepositories(ctx, func(repo *repo_model.Repository) error {
|
||||||
numRepos++
|
numRepos++
|
||||||
r, err := git.OpenRepositoryCtx(git.DefaultContext, repo.RepoPath())
|
r, err := git.OpenRepository(ctx, repo.RepoPath())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -17,7 +17,7 @@ import (
|
|||||||
func TestBlob_Data(t *testing.T) {
|
func TestBlob_Data(t *testing.T) {
|
||||||
output := "file2\n"
|
output := "file2\n"
|
||||||
bareRepo1Path := filepath.Join(testReposDir, "repo1_bare")
|
bareRepo1Path := filepath.Join(testReposDir, "repo1_bare")
|
||||||
repo, err := OpenRepository(bareRepo1Path)
|
repo, err := openRepositoryWithDefaultContext(bareRepo1Path)
|
||||||
if !assert.NoError(t, err) {
|
if !assert.NoError(t, err) {
|
||||||
t.Fatal()
|
t.Fatal()
|
||||||
}
|
}
|
||||||
@ -39,7 +39,7 @@ func TestBlob_Data(t *testing.T) {
|
|||||||
|
|
||||||
func Benchmark_Blob_Data(b *testing.B) {
|
func Benchmark_Blob_Data(b *testing.B) {
|
||||||
bareRepo1Path := filepath.Join(testReposDir, "repo1_bare")
|
bareRepo1Path := filepath.Join(testReposDir, "repo1_bare")
|
||||||
repo, err := OpenRepository(bareRepo1Path)
|
repo, err := openRepositoryWithDefaultContext(bareRepo1Path)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
b.Fatal(err)
|
b.Fatal(err)
|
||||||
}
|
}
|
||||||
|
@ -112,7 +112,7 @@ func testGetCommitsInfo(t *testing.T, repo1 *Repository) {
|
|||||||
|
|
||||||
func TestEntries_GetCommitsInfo(t *testing.T) {
|
func TestEntries_GetCommitsInfo(t *testing.T) {
|
||||||
bareRepo1Path := filepath.Join(testReposDir, "repo1_bare")
|
bareRepo1Path := filepath.Join(testReposDir, "repo1_bare")
|
||||||
bareRepo1, err := OpenRepository(bareRepo1Path)
|
bareRepo1, err := openRepositoryWithDefaultContext(bareRepo1Path)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
defer bareRepo1.Close()
|
defer bareRepo1.Close()
|
||||||
|
|
||||||
@ -123,7 +123,7 @@ func TestEntries_GetCommitsInfo(t *testing.T) {
|
|||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
}
|
}
|
||||||
defer util.RemoveAll(clonedPath)
|
defer util.RemoveAll(clonedPath)
|
||||||
clonedRepo1, err := OpenRepository(clonedPath)
|
clonedRepo1, err := openRepositoryWithDefaultContext(clonedPath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
}
|
}
|
||||||
@ -156,7 +156,7 @@ func BenchmarkEntries_GetCommitsInfo(b *testing.B) {
|
|||||||
}
|
}
|
||||||
defer util.RemoveAll(repoPath)
|
defer util.RemoveAll(repoPath)
|
||||||
|
|
||||||
if repo, err = OpenRepository(repoPath); err != nil {
|
if repo, err = openRepositoryWithDefaultContext(repoPath); err != nil {
|
||||||
b.Fatal(err)
|
b.Fatal(err)
|
||||||
}
|
}
|
||||||
defer repo.Close()
|
defer repo.Close()
|
||||||
|
@ -64,7 +64,7 @@ gpgsig -----BEGIN PGP SIGNATURE-----
|
|||||||
empty commit`
|
empty commit`
|
||||||
|
|
||||||
sha := SHA1{0xfe, 0xaf, 0x4b, 0xa6, 0xbc, 0x63, 0x5f, 0xec, 0x44, 0x2f, 0x46, 0xdd, 0xd4, 0x51, 0x24, 0x16, 0xec, 0x43, 0xc2, 0xc2}
|
sha := SHA1{0xfe, 0xaf, 0x4b, 0xa6, 0xbc, 0x63, 0x5f, 0xec, 0x44, 0x2f, 0x46, 0xdd, 0xd4, 0x51, 0x24, 0x16, 0xec, 0x43, 0xc2, 0xc2}
|
||||||
gitRepo, err := OpenRepository(filepath.Join(testReposDir, "repo1_bare"))
|
gitRepo, err := openRepositoryWithDefaultContext(filepath.Join(testReposDir, "repo1_bare"))
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
assert.NotNil(t, gitRepo)
|
assert.NotNil(t, gitRepo)
|
||||||
|
|
||||||
@ -109,7 +109,7 @@ empty commit`, commitFromReader.Signature.Payload)
|
|||||||
func TestHasPreviousCommit(t *testing.T) {
|
func TestHasPreviousCommit(t *testing.T) {
|
||||||
bareRepo1Path := filepath.Join(testReposDir, "repo1_bare")
|
bareRepo1Path := filepath.Join(testReposDir, "repo1_bare")
|
||||||
|
|
||||||
repo, err := OpenRepository(bareRepo1Path)
|
repo, err := openRepositoryWithDefaultContext(bareRepo1Path)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
|
|
||||||
commit, err := repo.GetCommit("8006ff9adbf0cb94da7dad9e537e53817f9fa5c0")
|
commit, err := repo.GetCommit("8006ff9adbf0cb94da7dad9e537e53817f9fa5c0")
|
||||||
|
@ -51,7 +51,7 @@ func GetReverseRawDiff(ctx context.Context, repoPath, commitID string, writer io
|
|||||||
func GetRawDiffForFile(ctx context.Context, repoPath, startCommit, endCommit string, diffType RawDiffType, file string, writer io.Writer) error {
|
func GetRawDiffForFile(ctx context.Context, repoPath, startCommit, endCommit string, diffType RawDiffType, file string, writer io.Writer) error {
|
||||||
repo, closer, err := RepositoryFromContextOrOpen(ctx, repoPath)
|
repo, closer, err := RepositoryFromContextOrOpen(ctx, repoPath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("OpenRepository: %v", err)
|
return fmt.Errorf("RepositoryFromContextOrOpen: %v", err)
|
||||||
}
|
}
|
||||||
defer closer.Close()
|
defer closer.Close()
|
||||||
|
|
||||||
|
@ -14,7 +14,7 @@ import (
|
|||||||
|
|
||||||
func TestGetNotes(t *testing.T) {
|
func TestGetNotes(t *testing.T) {
|
||||||
bareRepo1Path := filepath.Join(testReposDir, "repo1_bare")
|
bareRepo1Path := filepath.Join(testReposDir, "repo1_bare")
|
||||||
bareRepo1, err := OpenRepository(bareRepo1Path)
|
bareRepo1, err := openRepositoryWithDefaultContext(bareRepo1Path)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
defer bareRepo1.Close()
|
defer bareRepo1.Close()
|
||||||
|
|
||||||
@ -27,7 +27,7 @@ func TestGetNotes(t *testing.T) {
|
|||||||
|
|
||||||
func TestGetNestedNotes(t *testing.T) {
|
func TestGetNestedNotes(t *testing.T) {
|
||||||
repoPath := filepath.Join(testReposDir, "repo3_notes")
|
repoPath := filepath.Join(testReposDir, "repo3_notes")
|
||||||
repo, err := OpenRepository(repoPath)
|
repo, err := openRepositoryWithDefaultContext(repoPath)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
defer repo.Close()
|
defer repo.Close()
|
||||||
|
|
||||||
@ -42,7 +42,7 @@ func TestGetNestedNotes(t *testing.T) {
|
|||||||
|
|
||||||
func TestGetNonExistentNotes(t *testing.T) {
|
func TestGetNonExistentNotes(t *testing.T) {
|
||||||
bareRepo1Path := filepath.Join(testReposDir, "repo1_bare")
|
bareRepo1Path := filepath.Join(testReposDir, "repo1_bare")
|
||||||
bareRepo1, err := OpenRepository(bareRepo1Path)
|
bareRepo1, err := openRepositoryWithDefaultContext(bareRepo1Path)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
defer bareRepo1.Close()
|
defer bareRepo1.Close()
|
||||||
|
|
||||||
|
@ -44,6 +44,6 @@ func RepositoryFromContextOrOpen(ctx context.Context, path string) (*Repository,
|
|||||||
return gitRepo, nopCloser(nil), nil
|
return gitRepo, nopCloser(nil), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
gitRepo, err := OpenRepositoryCtx(ctx, path)
|
gitRepo, err := OpenRepository(ctx, path)
|
||||||
return gitRepo, gitRepo, err
|
return gitRepo, gitRepo, err
|
||||||
}
|
}
|
||||||
|
@ -35,13 +35,13 @@ type Repository struct {
|
|||||||
Ctx context.Context
|
Ctx context.Context
|
||||||
}
|
}
|
||||||
|
|
||||||
// OpenRepository opens the repository at the given path.
|
// openRepositoryWithDefaultContext opens the repository at the given path with DefaultContext.
|
||||||
func OpenRepository(repoPath string) (*Repository, error) {
|
func openRepositoryWithDefaultContext(repoPath string) (*Repository, error) {
|
||||||
return OpenRepositoryCtx(DefaultContext, repoPath)
|
return OpenRepository(DefaultContext, repoPath)
|
||||||
}
|
}
|
||||||
|
|
||||||
// OpenRepositoryCtx opens the repository at the given path within the context.Context
|
// OpenRepository opens the repository at the given path within the context.Context
|
||||||
func OpenRepositoryCtx(ctx context.Context, repoPath string) (*Repository, error) {
|
func OpenRepository(ctx context.Context, repoPath string) (*Repository, error) {
|
||||||
repoPath, err := filepath.Abs(repoPath)
|
repoPath, err := filepath.Abs(repoPath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
@ -36,13 +36,13 @@ type Repository struct {
|
|||||||
Ctx context.Context
|
Ctx context.Context
|
||||||
}
|
}
|
||||||
|
|
||||||
// OpenRepository opens the repository at the given path.
|
// openRepositoryWithDefaultContext opens the repository at the given path with DefaultContext.
|
||||||
func OpenRepository(repoPath string) (*Repository, error) {
|
func openRepositoryWithDefaultContext(repoPath string) (*Repository, error) {
|
||||||
return OpenRepositoryCtx(DefaultContext, repoPath)
|
return OpenRepository(DefaultContext, repoPath)
|
||||||
}
|
}
|
||||||
|
|
||||||
// OpenRepositoryCtx opens the repository at the given path with the provided context.
|
// OpenRepository opens the repository at the given path with the provided context.
|
||||||
func OpenRepositoryCtx(ctx context.Context, repoPath string) (*Repository, error) {
|
func OpenRepository(ctx context.Context, repoPath string) (*Repository, error) {
|
||||||
repoPath, err := filepath.Abs(repoPath)
|
repoPath, err := filepath.Abs(repoPath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
@ -15,7 +15,7 @@ import (
|
|||||||
|
|
||||||
func TestRepository_GetBlob_Found(t *testing.T) {
|
func TestRepository_GetBlob_Found(t *testing.T) {
|
||||||
repoPath := filepath.Join(testReposDir, "repo1_bare")
|
repoPath := filepath.Join(testReposDir, "repo1_bare")
|
||||||
r, err := OpenRepository(repoPath)
|
r, err := openRepositoryWithDefaultContext(repoPath)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
defer r.Close()
|
defer r.Close()
|
||||||
|
|
||||||
@ -43,7 +43,7 @@ func TestRepository_GetBlob_Found(t *testing.T) {
|
|||||||
|
|
||||||
func TestRepository_GetBlob_NotExist(t *testing.T) {
|
func TestRepository_GetBlob_NotExist(t *testing.T) {
|
||||||
repoPath := filepath.Join(testReposDir, "repo1_bare")
|
repoPath := filepath.Join(testReposDir, "repo1_bare")
|
||||||
r, err := OpenRepository(repoPath)
|
r, err := openRepositoryWithDefaultContext(repoPath)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
defer r.Close()
|
defer r.Close()
|
||||||
|
|
||||||
@ -57,7 +57,7 @@ func TestRepository_GetBlob_NotExist(t *testing.T) {
|
|||||||
|
|
||||||
func TestRepository_GetBlob_NoId(t *testing.T) {
|
func TestRepository_GetBlob_NoId(t *testing.T) {
|
||||||
repoPath := filepath.Join(testReposDir, "repo1_bare")
|
repoPath := filepath.Join(testReposDir, "repo1_bare")
|
||||||
r, err := OpenRepository(repoPath)
|
r, err := openRepositoryWithDefaultContext(repoPath)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
defer r.Close()
|
defer r.Close()
|
||||||
|
|
||||||
|
@ -89,7 +89,7 @@ func (repo *Repository) GetBranch(branch string) (*Branch, error) {
|
|||||||
// GetBranchesByPath returns a branch by it's path
|
// GetBranchesByPath returns a branch by it's path
|
||||||
// if limit = 0 it will not limit
|
// if limit = 0 it will not limit
|
||||||
func GetBranchesByPath(ctx context.Context, path string, skip, limit int) ([]*Branch, int, error) {
|
func GetBranchesByPath(ctx context.Context, path string, skip, limit int) ([]*Branch, int, error) {
|
||||||
gitRepo, err := OpenRepositoryCtx(ctx, path)
|
gitRepo, err := OpenRepository(ctx, path)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, 0, err
|
return nil, 0, err
|
||||||
}
|
}
|
||||||
|
@ -88,7 +88,7 @@ func WalkReferences(ctx context.Context, repoPath string, walkfn func(sha1, refn
|
|||||||
repo := RepositoryFromContext(ctx, repoPath)
|
repo := RepositoryFromContext(ctx, repoPath)
|
||||||
if repo == nil {
|
if repo == nil {
|
||||||
var err error
|
var err error
|
||||||
repo, err = OpenRepositoryCtx(ctx, repoPath)
|
repo, err = OpenRepository(ctx, repoPath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return 0, err
|
return 0, err
|
||||||
}
|
}
|
||||||
|
@ -13,7 +13,7 @@ import (
|
|||||||
|
|
||||||
func TestRepository_GetBranches(t *testing.T) {
|
func TestRepository_GetBranches(t *testing.T) {
|
||||||
bareRepo1Path := filepath.Join(testReposDir, "repo1_bare")
|
bareRepo1Path := filepath.Join(testReposDir, "repo1_bare")
|
||||||
bareRepo1, err := OpenRepository(bareRepo1Path)
|
bareRepo1, err := openRepositoryWithDefaultContext(bareRepo1Path)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
defer bareRepo1.Close()
|
defer bareRepo1.Close()
|
||||||
|
|
||||||
@ -41,7 +41,7 @@ func TestRepository_GetBranches(t *testing.T) {
|
|||||||
|
|
||||||
func BenchmarkRepository_GetBranches(b *testing.B) {
|
func BenchmarkRepository_GetBranches(b *testing.B) {
|
||||||
bareRepo1Path := filepath.Join(testReposDir, "repo1_bare")
|
bareRepo1Path := filepath.Join(testReposDir, "repo1_bare")
|
||||||
bareRepo1, err := OpenRepository(bareRepo1Path)
|
bareRepo1, err := openRepositoryWithDefaultContext(bareRepo1Path)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
b.Fatal(err)
|
b.Fatal(err)
|
||||||
}
|
}
|
||||||
|
@ -13,7 +13,7 @@ import (
|
|||||||
|
|
||||||
func TestRepository_GetCommitBranches(t *testing.T) {
|
func TestRepository_GetCommitBranches(t *testing.T) {
|
||||||
bareRepo1Path := filepath.Join(testReposDir, "repo1_bare")
|
bareRepo1Path := filepath.Join(testReposDir, "repo1_bare")
|
||||||
bareRepo1, err := OpenRepository(bareRepo1Path)
|
bareRepo1, err := openRepositoryWithDefaultContext(bareRepo1Path)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
defer bareRepo1.Close()
|
defer bareRepo1.Close()
|
||||||
|
|
||||||
@ -40,7 +40,7 @@ func TestRepository_GetCommitBranches(t *testing.T) {
|
|||||||
|
|
||||||
func TestGetTagCommitWithSignature(t *testing.T) {
|
func TestGetTagCommitWithSignature(t *testing.T) {
|
||||||
bareRepo1Path := filepath.Join(testReposDir, "repo1_bare")
|
bareRepo1Path := filepath.Join(testReposDir, "repo1_bare")
|
||||||
bareRepo1, err := OpenRepository(bareRepo1Path)
|
bareRepo1, err := openRepositoryWithDefaultContext(bareRepo1Path)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
defer bareRepo1.Close()
|
defer bareRepo1.Close()
|
||||||
|
|
||||||
@ -54,7 +54,7 @@ func TestGetTagCommitWithSignature(t *testing.T) {
|
|||||||
|
|
||||||
func TestGetCommitWithBadCommitID(t *testing.T) {
|
func TestGetCommitWithBadCommitID(t *testing.T) {
|
||||||
bareRepo1Path := filepath.Join(testReposDir, "repo1_bare")
|
bareRepo1Path := filepath.Join(testReposDir, "repo1_bare")
|
||||||
bareRepo1, err := OpenRepository(bareRepo1Path)
|
bareRepo1, err := openRepositoryWithDefaultContext(bareRepo1Path)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
defer bareRepo1.Close()
|
defer bareRepo1.Close()
|
||||||
|
|
||||||
@ -66,7 +66,7 @@ func TestGetCommitWithBadCommitID(t *testing.T) {
|
|||||||
|
|
||||||
func TestIsCommitInBranch(t *testing.T) {
|
func TestIsCommitInBranch(t *testing.T) {
|
||||||
bareRepo1Path := filepath.Join(testReposDir, "repo1_bare")
|
bareRepo1Path := filepath.Join(testReposDir, "repo1_bare")
|
||||||
bareRepo1, err := OpenRepository(bareRepo1Path)
|
bareRepo1, err := openRepositoryWithDefaultContext(bareRepo1Path)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
defer bareRepo1.Close()
|
defer bareRepo1.Close()
|
||||||
|
|
||||||
@ -81,7 +81,7 @@ func TestIsCommitInBranch(t *testing.T) {
|
|||||||
|
|
||||||
func TestRepository_CommitsBetweenIDs(t *testing.T) {
|
func TestRepository_CommitsBetweenIDs(t *testing.T) {
|
||||||
bareRepo1Path := filepath.Join(testReposDir, "repo4_commitsbetween")
|
bareRepo1Path := filepath.Join(testReposDir, "repo4_commitsbetween")
|
||||||
bareRepo1, err := OpenRepository(bareRepo1Path)
|
bareRepo1, err := openRepositoryWithDefaultContext(bareRepo1Path)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
defer bareRepo1.Close()
|
defer bareRepo1.Close()
|
||||||
|
|
||||||
|
@ -24,7 +24,7 @@ func TestGetFormatPatch(t *testing.T) {
|
|||||||
}
|
}
|
||||||
defer util.RemoveAll(clonedPath)
|
defer util.RemoveAll(clonedPath)
|
||||||
|
|
||||||
repo, err := OpenRepository(clonedPath)
|
repo, err := openRepositoryWithDefaultContext(clonedPath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
return
|
return
|
||||||
@ -52,7 +52,7 @@ func TestGetFormatPatch(t *testing.T) {
|
|||||||
func TestReadPatch(t *testing.T) {
|
func TestReadPatch(t *testing.T) {
|
||||||
// Ensure we can read the patch files
|
// Ensure we can read the patch files
|
||||||
bareRepo1Path := filepath.Join(testReposDir, "repo1_bare")
|
bareRepo1Path := filepath.Join(testReposDir, "repo1_bare")
|
||||||
repo, err := OpenRepository(bareRepo1Path)
|
repo, err := openRepositoryWithDefaultContext(bareRepo1Path)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
return
|
return
|
||||||
@ -91,7 +91,7 @@ func TestReadWritePullHead(t *testing.T) {
|
|||||||
}
|
}
|
||||||
defer util.RemoveAll(clonedPath)
|
defer util.RemoveAll(clonedPath)
|
||||||
|
|
||||||
repo, err := OpenRepository(clonedPath)
|
repo, err := openRepositoryWithDefaultContext(clonedPath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
return
|
return
|
||||||
|
@ -16,7 +16,7 @@ import (
|
|||||||
|
|
||||||
func TestRepository_GetLanguageStats(t *testing.T) {
|
func TestRepository_GetLanguageStats(t *testing.T) {
|
||||||
repoPath := filepath.Join(testReposDir, "language_stats_repo")
|
repoPath := filepath.Join(testReposDir, "language_stats_repo")
|
||||||
gitRepo, err := OpenRepository(repoPath)
|
gitRepo, err := openRepositoryWithDefaultContext(repoPath)
|
||||||
if !assert.NoError(t, err) {
|
if !assert.NoError(t, err) {
|
||||||
t.Fatal()
|
t.Fatal()
|
||||||
}
|
}
|
||||||
|
@ -13,7 +13,7 @@ import (
|
|||||||
|
|
||||||
func TestRepository_GetRefs(t *testing.T) {
|
func TestRepository_GetRefs(t *testing.T) {
|
||||||
bareRepo1Path := filepath.Join(testReposDir, "repo1_bare")
|
bareRepo1Path := filepath.Join(testReposDir, "repo1_bare")
|
||||||
bareRepo1, err := OpenRepository(bareRepo1Path)
|
bareRepo1, err := openRepositoryWithDefaultContext(bareRepo1Path)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
defer bareRepo1.Close()
|
defer bareRepo1.Close()
|
||||||
|
|
||||||
@ -37,7 +37,7 @@ func TestRepository_GetRefs(t *testing.T) {
|
|||||||
|
|
||||||
func TestRepository_GetRefsFiltered(t *testing.T) {
|
func TestRepository_GetRefsFiltered(t *testing.T) {
|
||||||
bareRepo1Path := filepath.Join(testReposDir, "repo1_bare")
|
bareRepo1Path := filepath.Join(testReposDir, "repo1_bare")
|
||||||
bareRepo1, err := OpenRepository(bareRepo1Path)
|
bareRepo1, err := openRepositoryWithDefaultContext(bareRepo1Path)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
defer bareRepo1.Close()
|
defer bareRepo1.Close()
|
||||||
|
|
||||||
|
@ -14,7 +14,7 @@ import (
|
|||||||
|
|
||||||
func TestRepository_GetCodeActivityStats(t *testing.T) {
|
func TestRepository_GetCodeActivityStats(t *testing.T) {
|
||||||
bareRepo1Path := filepath.Join(testReposDir, "repo1_bare")
|
bareRepo1Path := filepath.Join(testReposDir, "repo1_bare")
|
||||||
bareRepo1, err := OpenRepository(bareRepo1Path)
|
bareRepo1, err := openRepositoryWithDefaultContext(bareRepo1Path)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
defer bareRepo1.Close()
|
defer bareRepo1.Close()
|
||||||
|
|
||||||
|
@ -15,7 +15,7 @@ import (
|
|||||||
|
|
||||||
func TestRepository_GetTags(t *testing.T) {
|
func TestRepository_GetTags(t *testing.T) {
|
||||||
bareRepo1Path := filepath.Join(testReposDir, "repo1_bare")
|
bareRepo1Path := filepath.Join(testReposDir, "repo1_bare")
|
||||||
bareRepo1, err := OpenRepository(bareRepo1Path)
|
bareRepo1, err := openRepositoryWithDefaultContext(bareRepo1Path)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
return
|
return
|
||||||
@ -44,7 +44,7 @@ func TestRepository_GetTag(t *testing.T) {
|
|||||||
}
|
}
|
||||||
defer util.RemoveAll(clonedPath)
|
defer util.RemoveAll(clonedPath)
|
||||||
|
|
||||||
bareRepo1, err := OpenRepository(clonedPath)
|
bareRepo1, err := openRepositoryWithDefaultContext(clonedPath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
return
|
return
|
||||||
@ -149,7 +149,7 @@ func TestRepository_GetAnnotatedTag(t *testing.T) {
|
|||||||
}
|
}
|
||||||
defer util.RemoveAll(clonedPath)
|
defer util.RemoveAll(clonedPath)
|
||||||
|
|
||||||
bareRepo1, err := OpenRepository(clonedPath)
|
bareRepo1, err := openRepositoryWithDefaultContext(clonedPath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
return
|
return
|
||||||
|
@ -23,7 +23,7 @@ func TestGetLatestCommitTime(t *testing.T) {
|
|||||||
|
|
||||||
func TestRepoIsEmpty(t *testing.T) {
|
func TestRepoIsEmpty(t *testing.T) {
|
||||||
emptyRepo2Path := filepath.Join(testReposDir, "repo2_empty")
|
emptyRepo2Path := filepath.Join(testReposDir, "repo2_empty")
|
||||||
repo, err := OpenRepository(emptyRepo2Path)
|
repo, err := openRepositoryWithDefaultContext(emptyRepo2Path)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
defer repo.Close()
|
defer repo.Close()
|
||||||
isEmpty, err := repo.IsEmpty()
|
isEmpty, err := repo.IsEmpty()
|
||||||
|
@ -57,7 +57,7 @@ func TestEntriesCustomSort(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestFollowLink(t *testing.T) {
|
func TestFollowLink(t *testing.T) {
|
||||||
r, err := OpenRepository("tests/repos/repo1_bare")
|
r, err := openRepositoryWithDefaultContext("tests/repos/repo1_bare")
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
defer r.Close()
|
defer r.Close()
|
||||||
|
|
||||||
|
@ -14,7 +14,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func BenchmarkGetCommitGraph(b *testing.B) {
|
func BenchmarkGetCommitGraph(b *testing.B) {
|
||||||
currentRepo, err := git.OpenRepository(".")
|
currentRepo, err := git.OpenRepository(git.DefaultContext, ".")
|
||||||
if err != nil || currentRepo == nil {
|
if err != nil || currentRepo == nil {
|
||||||
b.Error("Could not open repository")
|
b.Error("Could not open repository")
|
||||||
}
|
}
|
||||||
|
@ -35,7 +35,7 @@ func (db *DBIndexer) Index(id int64) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
gitRepo, err := git.OpenRepositoryCtx(ctx, repo.RepoPath())
|
gitRepo, err := git.OpenRepository(ctx, repo.RepoPath())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if err.Error() == "no such file or directory" {
|
if err.Error() == "no such file or directory" {
|
||||||
return nil
|
return nil
|
||||||
|
@ -1079,7 +1079,7 @@ func sha1CurrentPatternProcessor(ctx *RenderContext, node *html.Node) {
|
|||||||
if !inCache {
|
if !inCache {
|
||||||
if ctx.GitRepo == nil {
|
if ctx.GitRepo == nil {
|
||||||
var err error
|
var err error
|
||||||
ctx.GitRepo, err = git.OpenRepositoryCtx(ctx.Ctx, ctx.Metas["repoPath"])
|
ctx.GitRepo, err = git.OpenRepository(ctx.Ctx, ctx.Metas["repoPath"])
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error("unable to open repository: %s Error: %v", ctx.Metas["repoPath"], err)
|
log.Error("unable to open repository: %s Error: %v", ctx.Metas["repoPath"], err)
|
||||||
return
|
return
|
||||||
|
@ -219,7 +219,7 @@ func generateGitContent(ctx context.Context, repo, templateRepo, generateRepo *r
|
|||||||
repo.DefaultBranch = templateRepo.DefaultBranch
|
repo.DefaultBranch = templateRepo.DefaultBranch
|
||||||
}
|
}
|
||||||
|
|
||||||
gitRepo, err := git.OpenRepositoryCtx(ctx, repo.RepoPath())
|
gitRepo, err := git.OpenRepository(ctx, repo.RepoPath())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("openRepository: %v", err)
|
return fmt.Errorf("openRepository: %v", err)
|
||||||
}
|
}
|
||||||
|
@ -430,7 +430,7 @@ func initRepository(ctx context.Context, repoPath string, u *user_model.User, re
|
|||||||
|
|
||||||
if len(opts.DefaultBranch) > 0 {
|
if len(opts.DefaultBranch) > 0 {
|
||||||
repo.DefaultBranch = opts.DefaultBranch
|
repo.DefaultBranch = opts.DefaultBranch
|
||||||
gitRepo, err := git.OpenRepositoryCtx(ctx, repo.RepoPath())
|
gitRepo, err := git.OpenRepository(ctx, repo.RepoPath())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("openRepository: %v", err)
|
return fmt.Errorf("openRepository: %v", err)
|
||||||
}
|
}
|
||||||
|
@ -126,7 +126,7 @@ func MigrateRepositoryGitData(ctx context.Context, u *user_model.User,
|
|||||||
return repo, fmt.Errorf("error in MigrateRepositoryGitData(git update-server-info): %v", err)
|
return repo, fmt.Errorf("error in MigrateRepositoryGitData(git update-server-info): %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
gitRepo, err := git.OpenRepositoryCtx(ctx, repoPath)
|
gitRepo, err := git.OpenRepository(ctx, repoPath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return repo, fmt.Errorf("OpenRepository: %v", err)
|
return repo, fmt.Errorf("OpenRepository: %v", err)
|
||||||
}
|
}
|
||||||
|
@ -66,7 +66,7 @@ func LoadRepo(t *testing.T, ctx *context.Context, repoID int64) {
|
|||||||
|
|
||||||
// LoadRepoCommit loads a repo's commit into a test context.
|
// LoadRepoCommit loads a repo's commit into a test context.
|
||||||
func LoadRepoCommit(t *testing.T, ctx *context.Context) {
|
func LoadRepoCommit(t *testing.T, ctx *context.Context) {
|
||||||
gitRepo, err := git.OpenRepositoryCtx(ctx, ctx.Repo.Repository.RepoPath())
|
gitRepo, err := git.OpenRepository(ctx, ctx.Repo.Repository.RepoPath())
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
defer gitRepo.Close()
|
defer gitRepo.Close()
|
||||||
branch, err := gitRepo.GetHEADBranch()
|
branch, err := gitRepo.GetHEADBranch()
|
||||||
@ -88,7 +88,7 @@ func LoadUser(t *testing.T, ctx *context.Context, userID int64) {
|
|||||||
func LoadGitRepo(t *testing.T, ctx *context.Context) {
|
func LoadGitRepo(t *testing.T, ctx *context.Context) {
|
||||||
assert.NoError(t, ctx.Repo.Repository.GetOwner(ctx))
|
assert.NoError(t, ctx.Repo.Repository.GetOwner(ctx))
|
||||||
var err error
|
var err error
|
||||||
ctx.Repo.GitRepo, err = git.OpenRepositoryCtx(ctx, ctx.Repo.Repository.RepoPath())
|
ctx.Repo.GitRepo, err = git.OpenRepository(ctx, ctx.Repo.Repository.RepoPath())
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -122,7 +122,7 @@ func GetArchive(ctx *context.APIContext) {
|
|||||||
|
|
||||||
repoPath := repo_model.RepoPath(ctx.Params(":username"), ctx.Params(":reponame"))
|
repoPath := repo_model.RepoPath(ctx.Params(":username"), ctx.Params(":reponame"))
|
||||||
if ctx.Repo.GitRepo == nil {
|
if ctx.Repo.GitRepo == nil {
|
||||||
gitRepo, err := git.OpenRepositoryCtx(ctx, repoPath)
|
gitRepo, err := git.OpenRepository(ctx, repoPath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "OpenRepository", err)
|
ctx.Error(http.StatusInternalServerError, "OpenRepository", err)
|
||||||
return
|
return
|
||||||
|
@ -136,7 +136,7 @@ func CreateFork(ctx *context.APIContext) {
|
|||||||
name = *form.Name
|
name = *form.Name
|
||||||
}
|
}
|
||||||
|
|
||||||
fork, err := repo_service.ForkRepository(ctx.Doer, forker, repo_service.ForkRepoOptions{
|
fork, err := repo_service.ForkRepository(ctx, ctx.Doer, forker, repo_service.ForkRepoOptions{
|
||||||
BaseRepo: repo,
|
BaseRepo: repo,
|
||||||
Name: name,
|
Name: name,
|
||||||
Description: repo.Description,
|
Description: repo.Description,
|
||||||
|
@ -55,7 +55,7 @@ func GetNote(ctx *context.APIContext) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func getNote(ctx *context.APIContext, identifier string) {
|
func getNote(ctx *context.APIContext, identifier string) {
|
||||||
gitRepo, err := git.OpenRepositoryCtx(ctx, ctx.Repo.Repository.RepoPath())
|
gitRepo, err := git.OpenRepository(ctx, ctx.Repo.Repository.RepoPath())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "OpenRepository", err)
|
ctx.Error(http.StatusInternalServerError, "OpenRepository", err)
|
||||||
return
|
return
|
||||||
|
@ -887,7 +887,7 @@ func MergePullRequest(ctx *context.APIContext) {
|
|||||||
if ctx.Repo != nil && ctx.Repo.Repository != nil && ctx.Repo.Repository.ID == pr.HeadRepoID && ctx.Repo.GitRepo != nil {
|
if ctx.Repo != nil && ctx.Repo.Repository != nil && ctx.Repo.Repository.ID == pr.HeadRepoID && ctx.Repo.GitRepo != nil {
|
||||||
headRepo = ctx.Repo.GitRepo
|
headRepo = ctx.Repo.GitRepo
|
||||||
} else {
|
} else {
|
||||||
headRepo, err = git.OpenRepositoryCtx(ctx, pr.HeadRepo.RepoPath())
|
headRepo, err = git.OpenRepository(ctx, pr.HeadRepo.RepoPath())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.ServerError(fmt.Sprintf("OpenRepository[%s]", pr.HeadRepo.RepoPath()), err)
|
ctx.ServerError(fmt.Sprintf("OpenRepository[%s]", pr.HeadRepo.RepoPath()), err)
|
||||||
return
|
return
|
||||||
@ -981,7 +981,7 @@ func parseCompareInfo(ctx *context.APIContext, form api.CreatePullRequestOption)
|
|||||||
headRepo = ctx.Repo.Repository
|
headRepo = ctx.Repo.Repository
|
||||||
headGitRepo = ctx.Repo.GitRepo
|
headGitRepo = ctx.Repo.GitRepo
|
||||||
} else {
|
} else {
|
||||||
headGitRepo, err = git.OpenRepositoryCtx(ctx, repo_model.RepoPath(headUser.Name, headRepo.Name))
|
headGitRepo, err = git.OpenRepository(ctx, repo_model.RepoPath(headUser.Name, headRepo.Name))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "OpenRepository", err)
|
ctx.Error(http.StatusInternalServerError, "OpenRepository", err)
|
||||||
return nil, nil, nil, nil, "", ""
|
return nil, nil, nil, nil, "", ""
|
||||||
|
@ -711,7 +711,7 @@ func updateBasicProperties(ctx *context.APIContext, opts api.EditRepoOption) err
|
|||||||
|
|
||||||
if ctx.Repo.GitRepo == nil && !repo.IsEmpty {
|
if ctx.Repo.GitRepo == nil && !repo.IsEmpty {
|
||||||
var err error
|
var err error
|
||||||
ctx.Repo.GitRepo, err = git.OpenRepositoryCtx(ctx, ctx.Repo.Repository.RepoPath())
|
ctx.Repo.GitRepo, err = git.OpenRepository(ctx, ctx.Repo.Repository.RepoPath())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "Unable to OpenRepository", err)
|
ctx.Error(http.StatusInternalServerError, "Unable to OpenRepository", err)
|
||||||
return err
|
return err
|
||||||
|
@ -458,7 +458,7 @@ func findEntryForFile(commit *git.Commit, target string) (*git.TreeEntry, error)
|
|||||||
// findWikiRepoCommit opens the wiki repo and returns the latest commit, writing to context on error.
|
// findWikiRepoCommit opens the wiki repo and returns the latest commit, writing to context on error.
|
||||||
// The caller is responsible for closing the returned repo again
|
// The caller is responsible for closing the returned repo again
|
||||||
func findWikiRepoCommit(ctx *context.APIContext) (*git.Repository, *git.Commit) {
|
func findWikiRepoCommit(ctx *context.APIContext) (*git.Repository, *git.Commit) {
|
||||||
wikiRepo, err := git.OpenRepositoryCtx(ctx, ctx.Repo.Repository.WikiPath())
|
wikiRepo, err := git.OpenRepository(ctx, ctx.Repo.Repository.WikiPath())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
||||||
if git.IsErrNotExist(err) || err.Error() == "no such file or directory" {
|
if git.IsErrNotExist(err) || err.Error() == "no such file or directory" {
|
||||||
|
@ -36,7 +36,7 @@ func ResolveRefOrSha(ctx *context.APIContext, ref string) string {
|
|||||||
func GetGitRefs(ctx *context.APIContext, filter string) ([]*git.Reference, string, error) {
|
func GetGitRefs(ctx *context.APIContext, filter string) ([]*git.Reference, string, error) {
|
||||||
if ctx.Repo.GitRepo == nil {
|
if ctx.Repo.GitRepo == nil {
|
||||||
var err error
|
var err error
|
||||||
ctx.Repo.GitRepo, err = git.OpenRepositoryCtx(ctx, ctx.Repo.Repository.RepoPath())
|
ctx.Repo.GitRepo, err = git.OpenRepository(ctx, ctx.Repo.Repository.RepoPath())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, "OpenRepository", err
|
return nil, "OpenRepository", err
|
||||||
}
|
}
|
||||||
|
@ -43,7 +43,7 @@ func RepoAssignment(ctx *gitea_context.PrivateContext) context.CancelFunc {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
gitRepo, err := git.OpenRepositoryCtx(ctx, repo.RepoPath())
|
gitRepo, err := git.OpenRepository(ctx, repo.RepoPath())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error("Failed to open repository: %s/%s Error: %v", ownerName, repoName, err)
|
log.Error("Failed to open repository: %s/%s Error: %v", ownerName, repoName, err)
|
||||||
ctx.JSON(http.StatusInternalServerError, map[string]interface{}{
|
ctx.JSON(http.StatusInternalServerError, map[string]interface{}{
|
||||||
|
@ -290,7 +290,7 @@ func loadOneBranch(ctx *context.Context, rawBranch, defaultBranch *git.Branch, p
|
|||||||
if pr.HasMerged {
|
if pr.HasMerged {
|
||||||
baseGitRepo, ok := repoIDToGitRepo[pr.BaseRepoID]
|
baseGitRepo, ok := repoIDToGitRepo[pr.BaseRepoID]
|
||||||
if !ok {
|
if !ok {
|
||||||
baseGitRepo, err = git.OpenRepositoryCtx(ctx, pr.BaseRepo.RepoPath())
|
baseGitRepo, err = git.OpenRepository(ctx, pr.BaseRepo.RepoPath())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.ServerError("OpenRepository", err)
|
ctx.ServerError("OpenRepository", err)
|
||||||
return nil
|
return nil
|
||||||
|
@ -265,7 +265,7 @@ func Diff(ctx *context.Context) {
|
|||||||
)
|
)
|
||||||
|
|
||||||
if ctx.Data["PageIsWiki"] != nil {
|
if ctx.Data["PageIsWiki"] != nil {
|
||||||
gitRepo, err = git.OpenRepositoryCtx(ctx, ctx.Repo.Repository.WikiPath())
|
gitRepo, err = git.OpenRepository(ctx, ctx.Repo.Repository.WikiPath())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.ServerError("Repo.GitRepo.GetCommit", err)
|
ctx.ServerError("Repo.GitRepo.GetCommit", err)
|
||||||
return
|
return
|
||||||
|
@ -389,7 +389,7 @@ func ParseCompareInfo(ctx *context.Context) *CompareInfo {
|
|||||||
ci.HeadRepo = ctx.Repo.Repository
|
ci.HeadRepo = ctx.Repo.Repository
|
||||||
ci.HeadGitRepo = ctx.Repo.GitRepo
|
ci.HeadGitRepo = ctx.Repo.GitRepo
|
||||||
} else if has {
|
} else if has {
|
||||||
ci.HeadGitRepo, err = git.OpenRepositoryCtx(ctx, ci.HeadRepo.RepoPath())
|
ci.HeadGitRepo, err = git.OpenRepository(ctx, ci.HeadRepo.RepoPath())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.ServerError("OpenRepository", err)
|
ctx.ServerError("OpenRepository", err)
|
||||||
return nil
|
return nil
|
||||||
@ -661,7 +661,7 @@ func PrepareCompareDiff(
|
|||||||
}
|
}
|
||||||
|
|
||||||
func getBranchesAndTagsForRepo(ctx gocontext.Context, repo *repo_model.Repository) (branches, tags []string, err error) {
|
func getBranchesAndTagsForRepo(ctx gocontext.Context, repo *repo_model.Repository) (branches, tags []string, err error) {
|
||||||
gitRepo, err := git.OpenRepositoryCtx(ctx, repo.RepoPath())
|
gitRepo, err := git.OpenRepository(ctx, repo.RepoPath())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, nil, err
|
return nil, nil, err
|
||||||
}
|
}
|
||||||
@ -795,7 +795,7 @@ func ExcerptBlob(ctx *context.Context) {
|
|||||||
gitRepo := ctx.Repo.GitRepo
|
gitRepo := ctx.Repo.GitRepo
|
||||||
if ctx.FormBool("wiki") {
|
if ctx.FormBool("wiki") {
|
||||||
var err error
|
var err error
|
||||||
gitRepo, err = git.OpenRepositoryCtx(ctx, ctx.Repo.Repository.WikiPath())
|
gitRepo, err = git.OpenRepository(ctx, ctx.Repo.Repository.WikiPath())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.ServerError("OpenRepository", err)
|
ctx.ServerError("OpenRepository", err)
|
||||||
return
|
return
|
||||||
|
@ -67,7 +67,7 @@ func TestGetClosestParentWithFiles(t *testing.T) {
|
|||||||
|
|
||||||
repo := ctx.Repo.Repository
|
repo := ctx.Repo.Repository
|
||||||
branch := repo.DefaultBranch
|
branch := repo.DefaultBranch
|
||||||
gitRepo, _ := git.OpenRepository(repo.RepoPath())
|
gitRepo, _ := git.OpenRepository(git.DefaultContext, repo.RepoPath())
|
||||||
defer gitRepo.Close()
|
defer gitRepo.Close()
|
||||||
commit, _ := gitRepo.GetBranchCommit(branch)
|
commit, _ := gitRepo.GetBranchCommit(branch)
|
||||||
expectedTreePath := ""
|
expectedTreePath := ""
|
||||||
|
@ -124,7 +124,7 @@ func LFSLocks(ctx *context.Context) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
gitRepo, err := git.OpenRepositoryCtx(ctx, tmpBasePath)
|
gitRepo, err := git.OpenRepository(ctx, tmpBasePath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error("Unable to open temporary repository: %s (%v)", tmpBasePath, err)
|
log.Error("Unable to open temporary repository: %s (%v)", tmpBasePath, err)
|
||||||
ctx.ServerError("LFSLocks", fmt.Errorf("failed to open new temporary repository in: %s %v", tmpBasePath, err))
|
ctx.ServerError("LFSLocks", fmt.Errorf("failed to open new temporary repository in: %s %v", tmpBasePath, err))
|
||||||
|
@ -227,7 +227,7 @@ func ForkPost(ctx *context.Context) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
repo, err := repo_service.ForkRepository(ctx.Doer, ctxUser, repo_service.ForkRepoOptions{
|
repo, err := repo_service.ForkRepository(ctx, ctx.Doer, ctxUser, repo_service.ForkRepoOptions{
|
||||||
BaseRepo: forkRepo,
|
BaseRepo: forkRepo,
|
||||||
Name: form.RepoName,
|
Name: form.RepoName,
|
||||||
Description: form.Description,
|
Description: form.Description,
|
||||||
@ -418,7 +418,7 @@ func PrepareViewPullInfo(ctx *context.Context, issue *models.Issue) *git.Compare
|
|||||||
if pull.BaseRepoID == ctx.Repo.Repository.ID && ctx.Repo.GitRepo != nil {
|
if pull.BaseRepoID == ctx.Repo.Repository.ID && ctx.Repo.GitRepo != nil {
|
||||||
baseGitRepo = ctx.Repo.GitRepo
|
baseGitRepo = ctx.Repo.GitRepo
|
||||||
} else {
|
} else {
|
||||||
baseGitRepo, err := git.OpenRepositoryCtx(ctx, pull.BaseRepo.RepoPath())
|
baseGitRepo, err := git.OpenRepository(ctx, pull.BaseRepo.RepoPath())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.ServerError("OpenRepository", err)
|
ctx.ServerError("OpenRepository", err)
|
||||||
return nil
|
return nil
|
||||||
@ -470,7 +470,7 @@ func PrepareViewPullInfo(ctx *context.Context, issue *models.Issue) *git.Compare
|
|||||||
var headBranchSha string
|
var headBranchSha string
|
||||||
// HeadRepo may be missing
|
// HeadRepo may be missing
|
||||||
if pull.HeadRepo != nil {
|
if pull.HeadRepo != nil {
|
||||||
headGitRepo, err := git.OpenRepositoryCtx(ctx, pull.HeadRepo.RepoPath())
|
headGitRepo, err := git.OpenRepository(ctx, pull.HeadRepo.RepoPath())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.ServerError("OpenRepository", err)
|
ctx.ServerError("OpenRepository", err)
|
||||||
return nil
|
return nil
|
||||||
@ -1070,7 +1070,7 @@ func MergePullRequest(ctx *context.Context) {
|
|||||||
if ctx.Repo != nil && ctx.Repo.Repository != nil && pr.HeadRepoID == ctx.Repo.Repository.ID && ctx.Repo.GitRepo != nil {
|
if ctx.Repo != nil && ctx.Repo.Repository != nil && pr.HeadRepoID == ctx.Repo.Repository.ID && ctx.Repo.GitRepo != nil {
|
||||||
headRepo = ctx.Repo.GitRepo
|
headRepo = ctx.Repo.GitRepo
|
||||||
} else {
|
} else {
|
||||||
headRepo, err = git.OpenRepositoryCtx(ctx, pr.HeadRepo.RepoPath())
|
headRepo, err = git.OpenRepository(ctx, pr.HeadRepo.RepoPath())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.ServerError(fmt.Sprintf("OpenRepository[%s]", pr.HeadRepo.RepoPath()), err)
|
ctx.ServerError(fmt.Sprintf("OpenRepository[%s]", pr.HeadRepo.RepoPath()), err)
|
||||||
return
|
return
|
||||||
@ -1280,7 +1280,7 @@ func CleanUpPullRequest(ctx *context.Context) {
|
|||||||
gitBaseRepo = ctx.Repo.GitRepo
|
gitBaseRepo = ctx.Repo.GitRepo
|
||||||
} else {
|
} else {
|
||||||
// If not just open it
|
// If not just open it
|
||||||
gitBaseRepo, err = git.OpenRepositoryCtx(ctx, pr.BaseRepo.RepoPath())
|
gitBaseRepo, err = git.OpenRepository(ctx, pr.BaseRepo.RepoPath())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.ServerError(fmt.Sprintf("OpenRepository[%s]", pr.BaseRepo.RepoPath()), err)
|
ctx.ServerError(fmt.Sprintf("OpenRepository[%s]", pr.BaseRepo.RepoPath()), err)
|
||||||
return
|
return
|
||||||
@ -1295,7 +1295,7 @@ func CleanUpPullRequest(ctx *context.Context) {
|
|||||||
gitRepo = ctx.Repo.GitRepo
|
gitRepo = ctx.Repo.GitRepo
|
||||||
} else if pr.BaseRepoID != pr.HeadRepoID {
|
} else if pr.BaseRepoID != pr.HeadRepoID {
|
||||||
// Otherwise just load it up
|
// Otherwise just load it up
|
||||||
gitRepo, err = git.OpenRepositoryCtx(ctx, pr.HeadRepo.RepoPath())
|
gitRepo, err = git.OpenRepository(ctx, pr.HeadRepo.RepoPath())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.ServerError(fmt.Sprintf("OpenRepository[%s]", pr.HeadRepo.RepoPath()), err)
|
ctx.ServerError(fmt.Sprintf("OpenRepository[%s]", pr.HeadRepo.RepoPath()), err)
|
||||||
return
|
return
|
||||||
|
@ -90,7 +90,7 @@ func findEntryForFile(commit *git.Commit, target string) (*git.TreeEntry, error)
|
|||||||
}
|
}
|
||||||
|
|
||||||
func findWikiRepoCommit(ctx *context.Context) (*git.Repository, *git.Commit, error) {
|
func findWikiRepoCommit(ctx *context.Context) (*git.Repository, *git.Commit, error) {
|
||||||
wikiRepo, err := git.OpenRepositoryCtx(ctx, ctx.Repo.Repository.WikiPath())
|
wikiRepo, err := git.OpenRepository(ctx, ctx.Repo.Repository.WikiPath())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.ServerError("OpenRepository", err)
|
ctx.ServerError("OpenRepository", err)
|
||||||
return nil, nil, err
|
return nil, nil, err
|
||||||
|
@ -26,7 +26,7 @@ const (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func wikiEntry(t *testing.T, repo *repo_model.Repository, wikiName string) *git.TreeEntry {
|
func wikiEntry(t *testing.T, repo *repo_model.Repository, wikiName string) *git.TreeEntry {
|
||||||
wikiRepo, err := git.OpenRepository(repo.WikiPath())
|
wikiRepo, err := git.OpenRepository(git.DefaultContext, repo.WikiPath())
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
defer wikiRepo.Close()
|
defer wikiRepo.Close()
|
||||||
commit, err := wikiRepo.GetBranchCommit("master")
|
commit, err := wikiRepo.GetBranchCommit("master")
|
||||||
|
@ -195,7 +195,7 @@ Loop:
|
|||||||
return false, "", nil, &ErrWontSign{twofa}
|
return false, "", nil, &ErrWontSign{twofa}
|
||||||
}
|
}
|
||||||
case parentSigned:
|
case parentSigned:
|
||||||
gitRepo, err := git.OpenRepositoryCtx(ctx, repoWikiPath)
|
gitRepo, err := git.OpenRepository(ctx, repoWikiPath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return false, "", nil, err
|
return false, "", nil, err
|
||||||
}
|
}
|
||||||
@ -248,7 +248,7 @@ Loop:
|
|||||||
return false, "", nil, &ErrWontSign{twofa}
|
return false, "", nil, &ErrWontSign{twofa}
|
||||||
}
|
}
|
||||||
case parentSigned:
|
case parentSigned:
|
||||||
gitRepo, err := git.OpenRepositoryCtx(ctx, tmpBasePath)
|
gitRepo, err := git.OpenRepository(ctx, tmpBasePath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return false, "", nil, err
|
return false, "", nil, err
|
||||||
}
|
}
|
||||||
@ -322,7 +322,7 @@ Loop:
|
|||||||
}
|
}
|
||||||
case baseSigned:
|
case baseSigned:
|
||||||
if gitRepo == nil {
|
if gitRepo == nil {
|
||||||
gitRepo, err = git.OpenRepositoryCtx(ctx, tmpBasePath)
|
gitRepo, err = git.OpenRepository(ctx, tmpBasePath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return false, "", nil, err
|
return false, "", nil, err
|
||||||
}
|
}
|
||||||
@ -338,7 +338,7 @@ Loop:
|
|||||||
}
|
}
|
||||||
case headSigned:
|
case headSigned:
|
||||||
if gitRepo == nil {
|
if gitRepo == nil {
|
||||||
gitRepo, err = git.OpenRepositoryCtx(ctx, tmpBasePath)
|
gitRepo, err = git.OpenRepository(ctx, tmpBasePath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return false, "", nil, err
|
return false, "", nil, err
|
||||||
}
|
}
|
||||||
@ -354,7 +354,7 @@ Loop:
|
|||||||
}
|
}
|
||||||
case commitsSigned:
|
case commitsSigned:
|
||||||
if gitRepo == nil {
|
if gitRepo == nil {
|
||||||
gitRepo, err = git.OpenRepositoryCtx(ctx, tmpBasePath)
|
gitRepo, err = git.OpenRepository(ctx, tmpBasePath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return false, "", nil, err
|
return false, "", nil, err
|
||||||
}
|
}
|
||||||
|
@ -690,7 +690,7 @@ func TestDiffLine_GetCommentSide(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestGetDiffRangeWithWhitespaceBehavior(t *testing.T) {
|
func TestGetDiffRangeWithWhitespaceBehavior(t *testing.T) {
|
||||||
gitRepo, err := git.OpenRepository("./testdata/academic-module")
|
gitRepo, err := git.OpenRepository(git.DefaultContext, "./testdata/academic-module")
|
||||||
if !assert.NoError(t, err) {
|
if !assert.NoError(t, err) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -182,7 +182,7 @@ func (g *RepositoryDumper) CreateRepo(repo *base.Repository, opts base.MigrateOp
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
g.gitRepo, err = git.OpenRepositoryCtx(g.ctx, g.gitPath())
|
g.gitRepo, err = git.OpenRepository(g.ctx, g.gitPath())
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -136,7 +136,7 @@ func (g *GiteaLocalUploader) CreateRepo(repo *base.Repository, opts base.Migrate
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
g.gitRepo, err = git.OpenRepositoryCtx(g.ctx, r.RepoPath())
|
g.gitRepo, err = git.OpenRepository(g.ctx, r.RepoPath())
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -247,7 +247,7 @@ func TestGiteaUploadUpdateGitForPullRequest(t *testing.T) {
|
|||||||
Author: &signature,
|
Author: &signature,
|
||||||
Message: "Initial Commit",
|
Message: "Initial Commit",
|
||||||
}))
|
}))
|
||||||
fromGitRepo, err := git.OpenRepositoryCtx(git.DefaultContext, fromRepo.RepoPath())
|
fromGitRepo, err := git.OpenRepository(git.DefaultContext, fromRepo.RepoPath())
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
defer fromGitRepo.Close()
|
defer fromGitRepo.Close()
|
||||||
baseSHA, err := fromGitRepo.GetBranchCommitID(baseRef)
|
baseSHA, err := fromGitRepo.GetBranchCommitID(baseRef)
|
||||||
@ -290,7 +290,7 @@ func TestGiteaUploadUpdateGitForPullRequest(t *testing.T) {
|
|||||||
Author: &signature,
|
Author: &signature,
|
||||||
Message: "branch2 commit",
|
Message: "branch2 commit",
|
||||||
}))
|
}))
|
||||||
forkGitRepo, err := git.OpenRepositoryCtx(git.DefaultContext, forkRepo.RepoPath())
|
forkGitRepo, err := git.OpenRepository(git.DefaultContext, forkRepo.RepoPath())
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
defer forkGitRepo.Close()
|
defer forkGitRepo.Close()
|
||||||
forkHeadSHA, err := forkGitRepo.GetBranchCommitID(forkHeadRef)
|
forkHeadSHA, err := forkGitRepo.GetBranchCommitID(forkHeadRef)
|
||||||
|
@ -281,7 +281,7 @@ func runSync(ctx context.Context, m *repo_model.Mirror) ([]*mirrorSyncResult, bo
|
|||||||
log.Error("SyncMirrors [repo: %-v]: %v", m.Repo, err)
|
log.Error("SyncMirrors [repo: %-v]: %v", m.Repo, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
gitRepo, err := git.OpenRepositoryCtx(ctx, repoPath)
|
gitRepo, err := git.OpenRepository(ctx, repoPath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error("SyncMirrors [repo: %-v]: failed to OpenRepository: %v", m.Repo, err)
|
log.Error("SyncMirrors [repo: %-v]: failed to OpenRepository: %v", m.Repo, err)
|
||||||
return nil, false
|
return nil, false
|
||||||
@ -438,7 +438,7 @@ func SyncPullMirror(ctx context.Context, repoID int64) bool {
|
|||||||
log.Trace("SyncMirrors [repo: %-v]: no branches updated", m.Repo)
|
log.Trace("SyncMirrors [repo: %-v]: no branches updated", m.Repo)
|
||||||
} else {
|
} else {
|
||||||
log.Trace("SyncMirrors [repo: %-v]: %d branches updated", m.Repo, len(results))
|
log.Trace("SyncMirrors [repo: %-v]: %d branches updated", m.Repo, len(results))
|
||||||
gitRepo, err = git.OpenRepositoryCtx(ctx, m.Repo.RepoPath())
|
gitRepo, err = git.OpenRepository(ctx, m.Repo.RepoPath())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error("SyncMirrors [repo: %-v]: unable to OpenRepository: %v", m.Repo, err)
|
log.Error("SyncMirrors [repo: %-v]: unable to OpenRepository: %v", m.Repo, err)
|
||||||
return false
|
return false
|
||||||
|
@ -137,7 +137,7 @@ func runPushSync(ctx context.Context, m *repo_model.PushMirror) error {
|
|||||||
if setting.LFS.StartServer {
|
if setting.LFS.StartServer {
|
||||||
log.Trace("SyncMirrors [repo: %-v]: syncing LFS objects...", m.Repo)
|
log.Trace("SyncMirrors [repo: %-v]: syncing LFS objects...", m.Repo)
|
||||||
|
|
||||||
gitRepo, err := git.OpenRepositoryCtx(ctx, path)
|
gitRepo, err := git.OpenRepository(ctx, path)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error("OpenRepository: %v", err)
|
log.Error("OpenRepository: %v", err)
|
||||||
return errors.New("Unexpected error")
|
return errors.New("Unexpected error")
|
||||||
|
@ -121,7 +121,7 @@ func getMergeCommit(ctx context.Context, pr *models.PullRequest) (*git.Commit, e
|
|||||||
mergeCommit = commitID[:40]
|
mergeCommit = commitID[:40]
|
||||||
}
|
}
|
||||||
|
|
||||||
gitRepo, err := git.OpenRepositoryCtx(ctx, pr.BaseRepo.RepoPath())
|
gitRepo, err := git.OpenRepository(ctx, pr.BaseRepo.RepoPath())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("OpenRepository: %v", err)
|
return nil, fmt.Errorf("OpenRepository: %v", err)
|
||||||
}
|
}
|
||||||
|
@ -69,7 +69,7 @@ func TestPatch(pr *models.PullRequest) error {
|
|||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
|
|
||||||
gitRepo, err := git.OpenRepositoryCtx(ctx, tmpBasePath)
|
gitRepo, err := git.OpenRepository(ctx, tmpBasePath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("OpenRepository: %v", err)
|
return fmt.Errorf("OpenRepository: %v", err)
|
||||||
}
|
}
|
||||||
|
@ -83,7 +83,7 @@ func NewPullRequest(ctx context.Context, repo *repo_model.Repository, pull *mode
|
|||||||
}
|
}
|
||||||
|
|
||||||
// add first push codes comment
|
// add first push codes comment
|
||||||
baseGitRepo, err := git.OpenRepositoryCtx(prCtx, pr.BaseRepo.RepoPath())
|
baseGitRepo, err := git.OpenRepository(prCtx, pr.BaseRepo.RepoPath())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -224,7 +224,7 @@ func checkForInvalidation(ctx context.Context, requests models.PullRequestList,
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("GetRepositoryByID: %v", err)
|
return fmt.Errorf("GetRepositoryByID: %v", err)
|
||||||
}
|
}
|
||||||
gitRepo, err := git.OpenRepositoryCtx(ctx, repo.RepoPath())
|
gitRepo, err := git.OpenRepository(ctx, repo.RepoPath())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("git.OpenRepository: %v", err)
|
return fmt.Errorf("git.OpenRepository: %v", err)
|
||||||
}
|
}
|
||||||
@ -352,7 +352,7 @@ func checkIfPRContentChanged(ctx context.Context, pr *models.PullRequest, oldCom
|
|||||||
return false, fmt.Errorf("LoadBaseRepo: %v", err)
|
return false, fmt.Errorf("LoadBaseRepo: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
headGitRepo, err := git.OpenRepositoryCtx(ctx, pr.HeadRepo.RepoPath())
|
headGitRepo, err := git.OpenRepository(ctx, pr.HeadRepo.RepoPath())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return false, fmt.Errorf("OpenRepository: %v", err)
|
return false, fmt.Errorf("OpenRepository: %v", err)
|
||||||
}
|
}
|
||||||
@ -752,7 +752,7 @@ func GetIssuesLastCommitStatus(ctx context.Context, issues models.IssueList) (ma
|
|||||||
}
|
}
|
||||||
gitRepo, ok := gitRepos[issue.RepoID]
|
gitRepo, ok := gitRepos[issue.RepoID]
|
||||||
if !ok {
|
if !ok {
|
||||||
gitRepo, err = git.OpenRepositoryCtx(ctx, issue.Repo.RepoPath())
|
gitRepo, err = git.OpenRepository(ctx, issue.Repo.RepoPath())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error("Cannot open git repository %-v for issue #%d[%d]. Error: %v", issue.Repo, issue.Index, issue.ID, err)
|
log.Error("Cannot open git repository %-v for issue #%d[%d]. Error: %v", issue.Repo, issue.Index, issue.ID, err)
|
||||||
continue
|
continue
|
||||||
|
@ -127,7 +127,7 @@ func createCodeComment(ctx context.Context, doer *user_model.User, repo *repo_mo
|
|||||||
}
|
}
|
||||||
gitRepo, closer, err := git.RepositoryFromContextOrOpen(ctx, pr.BaseRepo.RepoPath())
|
gitRepo, closer, err := git.RepositoryFromContextOrOpen(ctx, pr.BaseRepo.RepoPath())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("OpenRepository: %v", err)
|
return nil, fmt.Errorf("RepositoryFromContextOrOpen: %v", err)
|
||||||
}
|
}
|
||||||
defer closer.Close()
|
defer closer.Close()
|
||||||
|
|
||||||
|
@ -31,7 +31,7 @@ func TestRelease_Create(t *testing.T) {
|
|||||||
repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 1}).(*repo_model.Repository)
|
repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 1}).(*repo_model.Repository)
|
||||||
repoPath := repo_model.RepoPath(user.Name, repo.Name)
|
repoPath := repo_model.RepoPath(user.Name, repo.Name)
|
||||||
|
|
||||||
gitRepo, err := git.OpenRepository(repoPath)
|
gitRepo, err := git.OpenRepository(git.DefaultContext, repoPath)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
defer gitRepo.Close()
|
defer gitRepo.Close()
|
||||||
|
|
||||||
@ -135,7 +135,7 @@ func TestRelease_Update(t *testing.T) {
|
|||||||
repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 1}).(*repo_model.Repository)
|
repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 1}).(*repo_model.Repository)
|
||||||
repoPath := repo_model.RepoPath(user.Name, repo.Name)
|
repoPath := repo_model.RepoPath(user.Name, repo.Name)
|
||||||
|
|
||||||
gitRepo, err := git.OpenRepository(repoPath)
|
gitRepo, err := git.OpenRepository(git.DefaultContext, repoPath)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
defer gitRepo.Close()
|
defer gitRepo.Close()
|
||||||
|
|
||||||
@ -277,7 +277,7 @@ func TestRelease_createTag(t *testing.T) {
|
|||||||
repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 1}).(*repo_model.Repository)
|
repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 1}).(*repo_model.Repository)
|
||||||
repoPath := repo_model.RepoPath(user.Name, repo.Name)
|
repoPath := repo_model.RepoPath(user.Name, repo.Name)
|
||||||
|
|
||||||
gitRepo, err := git.OpenRepository(repoPath)
|
gitRepo, err := git.OpenRepository(git.DefaultContext, repoPath)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
defer gitRepo.Close()
|
defer gitRepo.Close()
|
||||||
|
|
||||||
|
@ -123,7 +123,7 @@ func adoptRepository(ctx context.Context, repoPath string, u *user_model.User, r
|
|||||||
repo.IsEmpty = false
|
repo.IsEmpty = false
|
||||||
|
|
||||||
// Don't bother looking this repo in the context it won't be there
|
// Don't bother looking this repo in the context it won't be there
|
||||||
gitRepo, err := git.OpenRepositoryCtx(ctx, repo.RepoPath())
|
gitRepo, err := git.OpenRepository(ctx, repo.RepoPath())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("openRepository: %v", err)
|
return fmt.Errorf("openRepository: %v", err)
|
||||||
}
|
}
|
||||||
|
@ -178,7 +178,7 @@ func doArchive(r *ArchiveRequest) (*repo_model.RepoArchiver, error) {
|
|||||||
return nil, fmt.Errorf("archiver.LoadRepo failed: %v", err)
|
return nil, fmt.Errorf("archiver.LoadRepo failed: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
gitRepo, err := git.OpenRepositoryCtx(ctx, repo.RepoPath())
|
gitRepo, err := git.OpenRepository(ctx, repo.RepoPath())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -109,7 +109,7 @@ func TestGetFileResponseFromCommit(t *testing.T) {
|
|||||||
repo := ctx.Repo.Repository
|
repo := ctx.Repo.Repository
|
||||||
branch := repo.DefaultBranch
|
branch := repo.DefaultBranch
|
||||||
treePath := "README.md"
|
treePath := "README.md"
|
||||||
gitRepo, _ := git.OpenRepositoryCtx(ctx, repo.RepoPath())
|
gitRepo, _ := git.OpenRepository(ctx, repo.RepoPath())
|
||||||
defer gitRepo.Close()
|
defer gitRepo.Close()
|
||||||
commit, _ := gitRepo.GetBranchCommit(branch)
|
commit, _ := gitRepo.GetBranchCommit(branch)
|
||||||
expectedFileResponse := getExpectedFileResponse()
|
expectedFileResponse := getExpectedFileResponse()
|
||||||
|
@ -69,7 +69,7 @@ func (t *TemporaryUploadRepository) Clone(branch string) error {
|
|||||||
return fmt.Errorf("Clone: %v %s", err, stderr)
|
return fmt.Errorf("Clone: %v %s", err, stderr)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
gitRepo, err := git.OpenRepositoryCtx(t.ctx, t.basePath)
|
gitRepo, err := git.OpenRepository(t.ctx, t.basePath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -82,7 +82,7 @@ func (t *TemporaryUploadRepository) Init() error {
|
|||||||
if err := git.InitRepository(t.ctx, t.basePath, false); err != nil {
|
if err := git.InitRepository(t.ctx, t.basePath, false); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
gitRepo, err := git.OpenRepositoryCtx(t.ctx, t.basePath)
|
gitRepo, err := git.OpenRepository(t.ctx, t.basePath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -30,8 +30,8 @@ type ForkRepoOptions struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// ForkRepository forks a repository
|
// ForkRepository forks a repository
|
||||||
func ForkRepository(doer, owner *user_model.User, opts ForkRepoOptions) (_ *repo_model.Repository, err error) {
|
func ForkRepository(ctx context.Context, doer, owner *user_model.User, opts ForkRepoOptions) (*repo_model.Repository, error) {
|
||||||
forkedRepo, err := repo_model.GetUserFork(opts.BaseRepo.ID, owner.ID)
|
forkedRepo, err := repo_model.GetUserFork(ctx, opts.BaseRepo.ID, owner.ID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@ -91,24 +91,24 @@ func ForkRepository(doer, owner *user_model.User, opts ForkRepoOptions) (_ *repo
|
|||||||
panic(panicErr)
|
panic(panicErr)
|
||||||
}()
|
}()
|
||||||
|
|
||||||
err = db.WithTx(func(ctx context.Context) error {
|
err = db.WithTx(func(txCtx context.Context) error {
|
||||||
if err = models.CreateRepository(ctx, doer, owner, repo, false); err != nil {
|
if err = models.CreateRepository(txCtx, doer, owner, repo, false); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
if err = models.IncrementRepoForkNum(ctx, opts.BaseRepo.ID); err != nil {
|
if err = models.IncrementRepoForkNum(txCtx, opts.BaseRepo.ID); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
// copy lfs files failure should not be ignored
|
// copy lfs files failure should not be ignored
|
||||||
if err = models.CopyLFS(ctx, repo, opts.BaseRepo); err != nil {
|
if err = models.CopyLFS(txCtx, repo, opts.BaseRepo); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
needsRollback = true
|
needsRollback = true
|
||||||
|
|
||||||
repoPath := repo_model.RepoPath(owner.Name, repo.Name)
|
repoPath := repo_model.RepoPath(owner.Name, repo.Name)
|
||||||
if stdout, err := git.NewCommand(ctx,
|
if stdout, err := git.NewCommand(txCtx,
|
||||||
"clone", "--bare", oldRepoPath, repoPath).
|
"clone", "--bare", oldRepoPath, repoPath).
|
||||||
SetDescription(fmt.Sprintf("ForkRepository(git clone): %s to %s", opts.BaseRepo.FullName(), repo.FullName())).
|
SetDescription(fmt.Sprintf("ForkRepository(git clone): %s to %s", opts.BaseRepo.FullName(), repo.FullName())).
|
||||||
RunInDirTimeout(10*time.Minute, ""); err != nil {
|
RunInDirTimeout(10*time.Minute, ""); err != nil {
|
||||||
@ -116,11 +116,11 @@ func ForkRepository(doer, owner *user_model.User, opts ForkRepoOptions) (_ *repo
|
|||||||
return fmt.Errorf("git clone: %v", err)
|
return fmt.Errorf("git clone: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := models.CheckDaemonExportOK(ctx, repo); err != nil {
|
if err := models.CheckDaemonExportOK(txCtx, repo); err != nil {
|
||||||
return fmt.Errorf("checkDaemonExportOK: %v", err)
|
return fmt.Errorf("checkDaemonExportOK: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if stdout, err := git.NewCommand(ctx, "update-server-info").
|
if stdout, err := git.NewCommand(txCtx, "update-server-info").
|
||||||
SetDescription(fmt.Sprintf("ForkRepository(git update-server-info): %s", repo.FullName())).
|
SetDescription(fmt.Sprintf("ForkRepository(git update-server-info): %s", repo.FullName())).
|
||||||
RunInDir(repoPath); err != nil {
|
RunInDir(repoPath); err != nil {
|
||||||
log.Error("Fork Repository (git update-server-info) failed for %v:\nStdout: %s\nError: %v", repo, stdout, err)
|
log.Error("Fork Repository (git update-server-info) failed for %v:\nStdout: %s\nError: %v", repo, stdout, err)
|
||||||
@ -139,14 +139,14 @@ func ForkRepository(doer, owner *user_model.User, opts ForkRepoOptions) (_ *repo
|
|||||||
}
|
}
|
||||||
|
|
||||||
// even if below operations failed, it could be ignored. And they will be retried
|
// even if below operations failed, it could be ignored. And they will be retried
|
||||||
if err := models.UpdateRepoSize(db.DefaultContext, repo); err != nil {
|
if err := models.UpdateRepoSize(ctx, repo); err != nil {
|
||||||
log.Error("Failed to update size for repository: %v", err)
|
log.Error("Failed to update size for repository: %v", err)
|
||||||
}
|
}
|
||||||
if err := repo_model.CopyLanguageStat(opts.BaseRepo, repo); err != nil {
|
if err := repo_model.CopyLanguageStat(opts.BaseRepo, repo); err != nil {
|
||||||
log.Error("Copy language stat from oldRepo failed: %v", err)
|
log.Error("Copy language stat from oldRepo failed: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
gitRepo, err := git.OpenRepositoryCtx(git.DefaultContext, repo.RepoPath())
|
gitRepo, err := git.OpenRepository(ctx, repo.RepoPath())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error("Open created git repository failed: %v", err)
|
log.Error("Open created git repository failed: %v", err)
|
||||||
} else {
|
} else {
|
||||||
|
@ -11,6 +11,7 @@ import (
|
|||||||
repo_model "code.gitea.io/gitea/models/repo"
|
repo_model "code.gitea.io/gitea/models/repo"
|
||||||
"code.gitea.io/gitea/models/unittest"
|
"code.gitea.io/gitea/models/unittest"
|
||||||
user_model "code.gitea.io/gitea/models/user"
|
user_model "code.gitea.io/gitea/models/user"
|
||||||
|
"code.gitea.io/gitea/modules/git"
|
||||||
|
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
)
|
)
|
||||||
@ -22,7 +23,7 @@ func TestForkRepository(t *testing.T) {
|
|||||||
user := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 13}).(*user_model.User)
|
user := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 13}).(*user_model.User)
|
||||||
repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 10}).(*repo_model.Repository)
|
repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 10}).(*repo_model.Repository)
|
||||||
|
|
||||||
fork, err := ForkRepository(user, user, ForkRepoOptions{
|
fork, err := ForkRepository(git.DefaultContext, user, user, ForkRepoOptions{
|
||||||
BaseRepo: repo,
|
BaseRepo: repo,
|
||||||
Name: "test",
|
Name: "test",
|
||||||
Description: "test",
|
Description: "test",
|
||||||
|
@ -54,13 +54,13 @@ func SyncRepositoryHooks(ctx context.Context) error {
|
|||||||
|
|
||||||
// GenerateGitHooks generates git hooks from a template repository
|
// GenerateGitHooks generates git hooks from a template repository
|
||||||
func GenerateGitHooks(ctx context.Context, templateRepo, generateRepo *repo_model.Repository) error {
|
func GenerateGitHooks(ctx context.Context, templateRepo, generateRepo *repo_model.Repository) error {
|
||||||
generateGitRepo, err := git.OpenRepositoryCtx(ctx, generateRepo.RepoPath())
|
generateGitRepo, err := git.OpenRepository(ctx, generateRepo.RepoPath())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
defer generateGitRepo.Close()
|
defer generateGitRepo.Close()
|
||||||
|
|
||||||
templateGitRepo, err := git.OpenRepositoryCtx(ctx, templateRepo.RepoPath())
|
templateGitRepo, err := git.OpenRepository(ctx, templateRepo.RepoPath())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -89,7 +89,7 @@ func pushUpdates(optsList []*repo_module.PushUpdateOptions) error {
|
|||||||
|
|
||||||
repoPath := repo.RepoPath()
|
repoPath := repo.RepoPath()
|
||||||
|
|
||||||
gitRepo, err := git.OpenRepositoryCtx(ctx, repoPath)
|
gitRepo, err := git.OpenRepository(ctx, repoPath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("OpenRepository[%s]: %v", repoPath, err)
|
return fmt.Errorf("OpenRepository[%s]: %v", repoPath, err)
|
||||||
}
|
}
|
||||||
|
@ -156,7 +156,7 @@ func updateWikiPage(ctx context.Context, doer *user_model.User, repo *repo_model
|
|||||||
return fmt.Errorf("Failed to clone repository: %s (%v)", repo.FullName(), err)
|
return fmt.Errorf("Failed to clone repository: %s (%v)", repo.FullName(), err)
|
||||||
}
|
}
|
||||||
|
|
||||||
gitRepo, err := git.OpenRepositoryCtx(ctx, basePath)
|
gitRepo, err := git.OpenRepository(ctx, basePath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error("Unable to open temporary repository: %s (%v)", basePath, err)
|
log.Error("Unable to open temporary repository: %s (%v)", basePath, err)
|
||||||
return fmt.Errorf("Failed to open new temporary repository in: %s %v", basePath, err)
|
return fmt.Errorf("Failed to open new temporary repository in: %s %v", basePath, err)
|
||||||
@ -305,7 +305,7 @@ func DeleteWikiPage(ctx context.Context, doer *user_model.User, repo *repo_model
|
|||||||
return fmt.Errorf("Failed to clone repository: %s (%v)", repo.FullName(), err)
|
return fmt.Errorf("Failed to clone repository: %s (%v)", repo.FullName(), err)
|
||||||
}
|
}
|
||||||
|
|
||||||
gitRepo, err := git.OpenRepositoryCtx(ctx, basePath)
|
gitRepo, err := git.OpenRepository(ctx, basePath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error("Unable to open temporary repository: %s (%v)", basePath, err)
|
log.Error("Unable to open temporary repository: %s (%v)", basePath, err)
|
||||||
return fmt.Errorf("Failed to open new temporary repository in: %s %v", basePath, err)
|
return fmt.Errorf("Failed to open new temporary repository in: %s %v", basePath, err)
|
||||||
|
@ -138,7 +138,7 @@ func TestRepository_AddWikiPage(t *testing.T) {
|
|||||||
t.Parallel()
|
t.Parallel()
|
||||||
assert.NoError(t, AddWikiPage(git.DefaultContext, doer, repo, wikiName, wikiContent, commitMsg))
|
assert.NoError(t, AddWikiPage(git.DefaultContext, doer, repo, wikiName, wikiContent, commitMsg))
|
||||||
// Now need to show that the page has been added:
|
// Now need to show that the page has been added:
|
||||||
gitRepo, err := git.OpenRepositoryCtx(git.DefaultContext, repo.WikiPath())
|
gitRepo, err := git.OpenRepository(git.DefaultContext, repo.WikiPath())
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
defer gitRepo.Close()
|
defer gitRepo.Close()
|
||||||
masterTree, err := gitRepo.GetTree("master")
|
masterTree, err := gitRepo.GetTree("master")
|
||||||
@ -183,7 +183,7 @@ func TestRepository_EditWikiPage(t *testing.T) {
|
|||||||
assert.NoError(t, EditWikiPage(git.DefaultContext, doer, repo, "Home", newWikiName, newWikiContent, commitMsg))
|
assert.NoError(t, EditWikiPage(git.DefaultContext, doer, repo, "Home", newWikiName, newWikiContent, commitMsg))
|
||||||
|
|
||||||
// Now need to show that the page has been added:
|
// Now need to show that the page has been added:
|
||||||
gitRepo, err := git.OpenRepositoryCtx(git.DefaultContext, repo.WikiPath())
|
gitRepo, err := git.OpenRepository(git.DefaultContext, repo.WikiPath())
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
masterTree, err := gitRepo.GetTree("master")
|
masterTree, err := gitRepo.GetTree("master")
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
@ -207,7 +207,7 @@ func TestRepository_DeleteWikiPage(t *testing.T) {
|
|||||||
assert.NoError(t, DeleteWikiPage(git.DefaultContext, doer, repo, "Home"))
|
assert.NoError(t, DeleteWikiPage(git.DefaultContext, doer, repo, "Home"))
|
||||||
|
|
||||||
// Now need to show that the page has been added:
|
// Now need to show that the page has been added:
|
||||||
gitRepo, err := git.OpenRepositoryCtx(git.DefaultContext, repo.WikiPath())
|
gitRepo, err := git.OpenRepository(git.DefaultContext, repo.WikiPath())
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
defer gitRepo.Close()
|
defer gitRepo.Close()
|
||||||
masterTree, err := gitRepo.GetTree("master")
|
masterTree, err := gitRepo.GetTree("master")
|
||||||
@ -220,7 +220,7 @@ func TestRepository_DeleteWikiPage(t *testing.T) {
|
|||||||
func TestPrepareWikiFileName(t *testing.T) {
|
func TestPrepareWikiFileName(t *testing.T) {
|
||||||
unittest.PrepareTestEnv(t)
|
unittest.PrepareTestEnv(t)
|
||||||
repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 1}).(*repo_model.Repository)
|
repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 1}).(*repo_model.Repository)
|
||||||
gitRepo, err := git.OpenRepositoryCtx(git.DefaultContext, repo.WikiPath())
|
gitRepo, err := git.OpenRepository(git.DefaultContext, repo.WikiPath())
|
||||||
defer gitRepo.Close()
|
defer gitRepo.Close()
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
|
|
||||||
@ -283,7 +283,7 @@ func TestPrepareWikiFileName_FirstPage(t *testing.T) {
|
|||||||
err = git.InitRepository(git.DefaultContext, tmpDir, true)
|
err = git.InitRepository(git.DefaultContext, tmpDir, true)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
|
|
||||||
gitRepo, err := git.OpenRepository(tmpDir)
|
gitRepo, err := git.OpenRepository(git.DefaultContext, tmpDir)
|
||||||
defer gitRepo.Close()
|
defer gitRepo.Close()
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user