diff options
author | 6543 <6543@obermui.de> | 2020-09-15 16:37:44 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-09-15 22:37:44 +0800 |
commit | 6c61f498ea6edb9260bc2b2b8db5bc3cb9214522 (patch) | |
tree | 9d1322d4ff85aec9d24f98f65d72c5a54cc1838d /modules/migrations | |
parent | 3d0ad2885a25012ba08c42a4ed181dc22dd72770 (diff) | |
download | gitea-6c61f498ea6edb9260bc2b2b8db5bc3cb9214522.tar.gz gitea-6c61f498ea6edb9260bc2b2b8db5bc3cb9214522.zip |
On Migration respect old DefaultBranch (#12843)
* On Migration respect old DefaultBranch
* add DefaultBranch int test set
Co-authored-by: zeripath <art27@cantab.net>
Diffstat (limited to 'modules/migrations')
-rw-r--r-- | modules/migrations/base/repo.go | 19 | ||||
-rw-r--r-- | modules/migrations/gitea.go | 1 | ||||
-rw-r--r-- | modules/migrations/github.go | 18 | ||||
-rw-r--r-- | modules/migrations/github_test.go | 11 | ||||
-rw-r--r-- | modules/migrations/gitlab.go | 13 | ||||
-rw-r--r-- | modules/migrations/gitlab_test.go | 11 |
6 files changed, 42 insertions, 31 deletions
diff --git a/modules/migrations/base/repo.go b/modules/migrations/base/repo.go index 5cfb0de920..d2052da90d 100644 --- a/modules/migrations/base/repo.go +++ b/modules/migrations/base/repo.go @@ -7,13 +7,14 @@ package base // Repository defines a standard repository information type Repository struct { - Name string - Owner string - IsPrivate bool - IsMirror bool - Description string - AuthUsername string - AuthPassword string - CloneURL string - OriginalURL string + Name string + Owner string + IsPrivate bool + IsMirror bool + Description string + AuthUsername string + AuthPassword string + CloneURL string + OriginalURL string + DefaultBranch string } diff --git a/modules/migrations/gitea.go b/modules/migrations/gitea.go index b70ad7b0ce..d4ba66fd38 100644 --- a/modules/migrations/gitea.go +++ b/modules/migrations/gitea.go @@ -122,6 +122,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, base.MigrateOptions{ RepoName: g.repoName, diff --git a/modules/migrations/github.go b/modules/migrations/github.go index e5cc3b8223..d31db136e6 100644 --- a/modules/migrations/github.go +++ b/modules/migrations/github.go @@ -143,14 +143,20 @@ 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, - Name: gr.GetName(), - IsPrivate: *gr.Private, - Description: gr.GetDescription(), - OriginalURL: gr.GetHTMLURL(), - CloneURL: gr.GetCloneURL(), + Owner: g.repoOwner, + Name: gr.GetName(), + IsPrivate: *gr.Private, + Description: gr.GetDescription(), + OriginalURL: gr.GetHTMLURL(), + CloneURL: gr.GetCloneURL(), + DefaultBranch: defaultBranch, }, nil } diff --git a/modules/migrations/github_test.go b/modules/migrations/github_test.go index 660e82d645..955050107c 100644 --- a/modules/migrations/github_test.go +++ b/modules/migrations/github_test.go @@ -72,11 +72,12 @@ func TestGitHubDownloadRepo(t *testing.T) { repo, err := downloader.GetRepoInfo() assert.NoError(t, err) assert.EqualValues(t, &base.Repository{ - Name: "test_repo", - Owner: "go-gitea", - 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", + Name: "test_repo", + Owner: "go-gitea", + 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() diff --git a/modules/migrations/gitlab.go b/modules/migrations/gitlab.go index 13d2618030..e6529af9de 100644 --- a/modules/migrations/gitlab.go +++ b/modules/migrations/gitlab.go @@ -139,12 +139,13 @@ func (g *GitlabDownloader) GetRepoInfo() (*base.Repository, error) { // convert gitlab repo to stand Repo return &base.Repository{ - Owner: owner, - Name: gr.Name, - IsPrivate: private, - Description: gr.Description, - OriginalURL: gr.WebURL, - CloneURL: gr.HTTPURLToRepo, + Owner: owner, + Name: gr.Name, + IsPrivate: private, + Description: gr.Description, + OriginalURL: gr.WebURL, + CloneURL: gr.HTTPURLToRepo, + DefaultBranch: gr.DefaultBranch, }, nil } diff --git a/modules/migrations/gitlab_test.go b/modules/migrations/gitlab_test.go index 936201b1f2..11c3aefeaf 100644 --- a/modules/migrations/gitlab_test.go +++ b/modules/migrations/gitlab_test.go @@ -37,11 +37,12 @@ func TestGitlabDownloadRepo(t *testing.T) { assert.NoError(t, err) // Repo Owner is blank in Gitlab Group repos assert.EqualValues(t, &base.Repository{ - Name: "test_repo", - Owner: "", - 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", + Name: "test_repo", + Owner: "", + 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() |