@@ -142,35 +142,39 @@ type remoteAddress struct {
142142Password string
143143}
144144
145- func mirrorRemoteAddress (ctx context.Context , m * repo_model.Repository , remoteName string , ignoreOriginalURL bool ) remoteAddress {
146- a := remoteAddress {}
147-
148- remoteURL := m .OriginalURL
149- if ignoreOriginalURL || remoteURL == "" {
150- var err error
151- remoteURL , err = git .GetRemoteAddress (ctx , m .RepoPath (), remoteName )
152- if err != nil {
153- log .Error ("GetRemoteURL %v" , err )
154- return a
155- }
145+ func mirrorRemoteAddress (ctx context.Context , m * repo_model.Repository , remoteName string ) remoteAddress {
146+ ret := remoteAddress {}
147+ remoteURL , err := git .GetRemoteAddress (ctx , m .RepoPath (), remoteName )
148+ if err != nil {
149+ log .Error ("GetRemoteURL %v" , err )
150+ return ret
156151}
157152
158153u , err := giturl .Parse (remoteURL )
159154if err != nil {
160155log .Error ("giturl.Parse %v" , err )
161- return a
156+ return ret
162157}
163158
164159if u .Scheme != "ssh" && u .Scheme != "file" {
165160if u .User != nil {
166- a .Username = u .User .Username ()
167- a .Password , _ = u .User .Password ()
161+ ret .Username = u .User .Username ()
162+ ret .Password , _ = u .User .Password ()
168163}
169- u .User = nil
170164}
171- a .Address = u .String ()
172165
173- return a
166+ // The URL stored in the git repo could contain authentication,
167+ // erase it, or it will be shown in the UI.
168+ u .User = nil
169+ ret .Address = u .String ()
170+ // Why not use m.OriginalURL to set ret.Address?
171+ // It should be OK to use it, since m.OriginalURL should be the same as the authentication-erased URL from the Git repository.
172+ // However, the old code has already stored authentication in m.OriginalURL when updating mirror settings.
173+ // That means we need to use "giturl.Parse" for m.OriginalURL again to ensure authentication is erased.
174+ // Instead of doing this, why not directly use the authentication-erased URL from the Git repository?
175+ // It should be the same as long as there are no bugs.
176+
177+ return ret
174178}
175179
176180func FilenameIsImage (filename string ) bool {
0 commit comments