diff --git a/mercurial/hg.py b/mercurial/hg.py --- a/mercurial/hg.py +++ b/mercurial/hg.py @@ -672,8 +672,8 @@ def clone( """ if isinstance(source, bytes): - origsource = ui.expandpath(source) - source, branches = urlutil.parseurl(origsource, branch) + src = urlutil.get_clone_path(ui, source, branch) + origsource, source, branches = src srcpeer = peer(ui, peeropts, source) else: srcpeer = source.peer() # in case we were called with a localrepo diff --git a/mercurial/utils/urlutil.py b/mercurial/utils/urlutil.py --- a/mercurial/utils/urlutil.py +++ b/mercurial/utils/urlutil.py @@ -471,6 +471,13 @@ def get_pull_paths(repo, ui, sources, de yield parseurl(url, default_branches) +def get_clone_path(ui, source, default_branches=()): + """return the `(origsource, path, branch)` selected as clone source""" + url = ui.expandpath(source) + path, branch = parseurl(url, default_branches) + return url, path, branch + + def parseurl(path, branches=None): '''parse url#branch, returning (url, (branch, branches))''' u = url(path)