forked from gitea/gitea
1
0
Fork 0

On Migration respect old DefaultBranch (#12843) (#12858)

* On Migration respect old DefaultBranch

* add DefaultBranch int test set

Co-authored-by: zeripath <art27@cantab.net>

Co-authored-by: zeripath <art27@cantab.net>
This commit is contained in:
6543 2020-09-15 18:12:07 +02:00 committed by GitHub
parent ff9d99f63d
commit 6305f07fdc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 56 additions and 41 deletions

View File

@ -16,4 +16,5 @@ type Repository struct {
AuthPassword string
CloneURL string
OriginalURL string
DefaultBranch string
}

View File

@ -119,6 +119,7 @@ func (g *GiteaLocalUploader) CreateRepo(repo *base.Repository, opts base.Migrate
if err != nil {
return err
}
r.DefaultBranch = repo.DefaultBranch
r, err = repository.MigrateRepositoryGitData(g.doer, owner, r, structs.MigrateRepoOption{
RepoName: g.repoName,

View File

@ -154,6 +154,11 @@ func (g *GithubDownloaderV3) GetRepoInfo() (*base.Repository, error) {
}
g.rate = &resp.Rate
defaultBranch := ""
if gr.DefaultBranch != nil {
defaultBranch = *gr.DefaultBranch
}
// convert github repo to stand Repo
return &base.Repository{
Owner: g.repoOwner,
@ -162,6 +167,7 @@ func (g *GithubDownloaderV3) GetRepoInfo() (*base.Repository, error) {
Description: gr.GetDescription(),
OriginalURL: gr.GetHTMLURL(),
CloneURL: gr.GetCloneURL(),
DefaultBranch: defaultBranch,
}, nil
}

View File

@ -76,6 +76,7 @@ func TestGitHubDownloadRepo(t *testing.T) {
Description: "Test repository for testing migration from github to gitea",
CloneURL: "https://github.com/go-gitea/test_repo.git",
OriginalURL: "https://github.com/go-gitea/test_repo",
DefaultBranch: "master",
}, repo)
topics, err := downloader.GetTopics()

View File

@ -163,6 +163,7 @@ func (g *GitlabDownloader) GetRepoInfo() (*base.Repository, error) {
Description: gr.Description,
OriginalURL: gr.WebURL,
CloneURL: gr.HTTPURLToRepo,
DefaultBranch: gr.DefaultBranch,
}, nil
}

View File

@ -40,6 +40,7 @@ func TestGitlabDownloadRepo(t *testing.T) {
Description: "Test repository for testing migration from gitlab to gitea",
CloneURL: "https://gitlab.com/gitea/test_repo.git",
OriginalURL: "https://gitlab.com/gitea/test_repo",
DefaultBranch: "master",
}, repo)
topics, err := downloader.GetTopics()

View File

@ -102,7 +102,8 @@ func MigrateRepositoryGitData(doer, u *models.User, repo *models.Repository, opt
return repo, fmt.Errorf("git.IsEmpty: %v", err)
}
if !opts.Releases && !repo.IsEmpty {
if !repo.IsEmpty {
if len(repo.DefaultBranch) == 0 {
// Try to get HEAD branch and set it as default branch.
headBranch, err := gitRepo.GetHEADBranch()
if err != nil {
@ -111,11 +112,14 @@ func MigrateRepositoryGitData(doer, u *models.User, repo *models.Repository, opt
if headBranch != nil {
repo.DefaultBranch = headBranch.Name
}
}
if !opts.Releases {
if err = SyncReleasesWithTags(repo, gitRepo); err != nil {
log.Error("Failed to synchronize tags to releases for repository: %v", err)
}
}
}
if err = repo.UpdateSize(models.DefaultDBContext()); err != nil {
log.Error("Failed to update size for repository: %v", err)