mirror of
https://github.com/go-gitea/gitea
synced 2024-12-22 12:07:50 +01:00
On Migration respect old DefaultBranch (#12843)
* On Migration respect old DefaultBranch * add DefaultBranch int test set Co-authored-by: zeripath <art27@cantab.net>
This commit is contained in:
parent
3d0ad2885a
commit
6c61f498ea
@ -16,4 +16,5 @@ type Repository struct {
|
|||||||
AuthPassword string
|
AuthPassword string
|
||||||
CloneURL string
|
CloneURL string
|
||||||
OriginalURL string
|
OriginalURL string
|
||||||
|
DefaultBranch string
|
||||||
}
|
}
|
||||||
|
@ -122,6 +122,7 @@ func (g *GiteaLocalUploader) CreateRepo(repo *base.Repository, opts base.Migrate
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
r.DefaultBranch = repo.DefaultBranch
|
||||||
|
|
||||||
r, err = repository.MigrateRepositoryGitData(g.doer, owner, r, base.MigrateOptions{
|
r, err = repository.MigrateRepositoryGitData(g.doer, owner, r, base.MigrateOptions{
|
||||||
RepoName: g.repoName,
|
RepoName: g.repoName,
|
||||||
|
@ -143,6 +143,11 @@ func (g *GithubDownloaderV3) GetRepoInfo() (*base.Repository, error) {
|
|||||||
}
|
}
|
||||||
g.rate = &resp.Rate
|
g.rate = &resp.Rate
|
||||||
|
|
||||||
|
defaultBranch := ""
|
||||||
|
if gr.DefaultBranch != nil {
|
||||||
|
defaultBranch = *gr.DefaultBranch
|
||||||
|
}
|
||||||
|
|
||||||
// convert github repo to stand Repo
|
// convert github repo to stand Repo
|
||||||
return &base.Repository{
|
return &base.Repository{
|
||||||
Owner: g.repoOwner,
|
Owner: g.repoOwner,
|
||||||
@ -151,6 +156,7 @@ func (g *GithubDownloaderV3) GetRepoInfo() (*base.Repository, error) {
|
|||||||
Description: gr.GetDescription(),
|
Description: gr.GetDescription(),
|
||||||
OriginalURL: gr.GetHTMLURL(),
|
OriginalURL: gr.GetHTMLURL(),
|
||||||
CloneURL: gr.GetCloneURL(),
|
CloneURL: gr.GetCloneURL(),
|
||||||
|
DefaultBranch: defaultBranch,
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -77,6 +77,7 @@ func TestGitHubDownloadRepo(t *testing.T) {
|
|||||||
Description: "Test repository for testing migration from github to gitea",
|
Description: "Test repository for testing migration from github to gitea",
|
||||||
CloneURL: "https://github.com/go-gitea/test_repo.git",
|
CloneURL: "https://github.com/go-gitea/test_repo.git",
|
||||||
OriginalURL: "https://github.com/go-gitea/test_repo",
|
OriginalURL: "https://github.com/go-gitea/test_repo",
|
||||||
|
DefaultBranch: "master",
|
||||||
}, repo)
|
}, repo)
|
||||||
|
|
||||||
topics, err := downloader.GetTopics()
|
topics, err := downloader.GetTopics()
|
||||||
|
@ -145,6 +145,7 @@ func (g *GitlabDownloader) GetRepoInfo() (*base.Repository, error) {
|
|||||||
Description: gr.Description,
|
Description: gr.Description,
|
||||||
OriginalURL: gr.WebURL,
|
OriginalURL: gr.WebURL,
|
||||||
CloneURL: gr.HTTPURLToRepo,
|
CloneURL: gr.HTTPURLToRepo,
|
||||||
|
DefaultBranch: gr.DefaultBranch,
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -42,6 +42,7 @@ func TestGitlabDownloadRepo(t *testing.T) {
|
|||||||
Description: "Test repository for testing migration from gitlab to gitea",
|
Description: "Test repository for testing migration from gitlab to gitea",
|
||||||
CloneURL: "https://gitlab.com/gitea/test_repo.git",
|
CloneURL: "https://gitlab.com/gitea/test_repo.git",
|
||||||
OriginalURL: "https://gitlab.com/gitea/test_repo",
|
OriginalURL: "https://gitlab.com/gitea/test_repo",
|
||||||
|
DefaultBranch: "master",
|
||||||
}, repo)
|
}, repo)
|
||||||
|
|
||||||
topics, err := downloader.GetTopics()
|
topics, err := downloader.GetTopics()
|
||||||
|
@ -102,7 +102,8 @@ func MigrateRepositoryGitData(doer, u *models.User, repo *models.Repository, opt
|
|||||||
return repo, fmt.Errorf("git.IsEmpty: %v", err)
|
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.
|
// Try to get HEAD branch and set it as default branch.
|
||||||
headBranch, err := gitRepo.GetHEADBranch()
|
headBranch, err := gitRepo.GetHEADBranch()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -111,11 +112,14 @@ func MigrateRepositoryGitData(doer, u *models.User, repo *models.Repository, opt
|
|||||||
if headBranch != nil {
|
if headBranch != nil {
|
||||||
repo.DefaultBranch = headBranch.Name
|
repo.DefaultBranch = headBranch.Name
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if !opts.Releases {
|
||||||
if err = SyncReleasesWithTags(repo, gitRepo); err != nil {
|
if err = SyncReleasesWithTags(repo, gitRepo); err != nil {
|
||||||
log.Error("Failed to synchronize tags to releases for repository: %v", err)
|
log.Error("Failed to synchronize tags to releases for repository: %v", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if err = repo.UpdateSize(models.DefaultDBContext()); err != nil {
|
if err = repo.UpdateSize(models.DefaultDBContext()); err != nil {
|
||||||
log.Error("Failed to update size for repository: %v", err)
|
log.Error("Failed to update size for repository: %v", err)
|
||||||
|
Loading…
Reference in New Issue
Block a user