Skip to content

Commit ed56db1

Browse files
6543techknowlogick
authored andcommitted
finaly fix gitlab migration with subdir (go-gitea#13629)
* finaly fix go-gitea#13535 * add logging
1 parent 2f6dad2 commit ed56db1

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

modules/migrations/gitlab.go

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,12 +90,17 @@ func NewGitlabDownloader(ctx context.Context, baseURL, repoPath, username, passw
9090

9191
// split namespace and subdirectory
9292
pathParts := strings.Split(strings.Trim(repoPath, "/"), "/")
93+
var resp *gitlab.Response
94+
u, _ := url.Parse(baseURL)
9395
for len(pathParts) > 2 {
94-
if _, _, err = gitlabClient.Version.GetVersion(); err == nil {
96+
_, resp, err = gitlabClient.Version.GetVersion()
97+
if err == nil || resp != nil && resp.StatusCode == 401 {
98+
err = nil // if no authentication given, this still should work
9599
break
96100
}
97101

98-
baseURL = path.Join(baseURL, pathParts[0])
102+
u.Path = path.Join(u.Path, pathParts[0])
103+
baseURL = u.String()
99104
pathParts = pathParts[1:]
100105
_ = gitlab.WithBaseURL(baseURL)(gitlabClient)
101106
repoPath = strings.Join(pathParts, "/")
@@ -105,6 +110,8 @@ func NewGitlabDownloader(ctx context.Context, baseURL, repoPath, username, passw
105110
return nil, err
106111
}
107112

113+
log.Trace("gitlab downloader: use BaseURL: '%s' and RepoPath: '%s'", baseURL, repoPath)
114+
108115
// Grab and store project/repo ID here, due to issues using the URL escaped path
109116
gr, _, err := gitlabClient.Projects.GetProject(repoPath, nil, nil, gitlab.WithContext(ctx))
110117
if err != nil {

0 commit comments

Comments
 (0)