--no-git should skip git.maybegiturl() check

Reviewed By: muirdm

Differential Revision: D40292625

fbshipit-source-id: 03713c0df060f992a36d67c91b016cad05a34aa5
This commit is contained in:
Michael Bolin 2022-10-12 18:36:42 -07:00 committed by Facebook GitHub Bot
parent 87058a3e2c
commit 54f37eba6e
4 changed files with 38 additions and 10 deletions

View File

@ -0,0 +1,32 @@
# Copyright (c) Meta Platforms, Inc. and affiliates.
#
# This software may be used and distributed according to the terms of the
# GNU General Public License version 2.
from typing import Optional
from . import git
def determine_git_uri(git_flag: Optional[bool], source: str) -> Optional[str]:
"""Based on the git flag passed to clone and the source arg, determines the
Git URI to use for cloning, if appropriate.
git_flag is:
- True if --git was specified as an option to clone.
- False if --no-git was specified as an option to clone.
- None if neither --git nor --no-git were specified.
>>> determine_git_uri(True, "ssh://example.com/my/repo.git")
'ssh://example.com/my/repo.git'
>>> determine_git_uri(None, "git+ssh://example.com/my/repo.git")
'ssh://example.com/my/repo.git'
>>> determine_git_uri(False, "ssh://example.com/my/repo.git") is None
True
"""
if git_flag is False:
return None
elif git_flag is True:
return source
else:
return git.maybegiturl(source)

View File

@ -30,6 +30,7 @@ from .. import (
bookmarks,
bundle2,
changegroup,
cloneuri,
cmdutil,
context,
copies,
@ -1543,17 +1544,14 @@ def cat(ui, repo, file1, *pats, **opts):
True,
_("use remotefilelog (only turn it off in legacy tests) (ADVANCED)"),
),
("", "git", False, _("use git protocol (EXPERIMENTAL)")),
("", "git", None, _("use git protocol (EXPERIMENTAL)")),
],
norepo=True,
)
def clone(ui, source, dest=None, **opts):
if opts.get("noupdate") and opts.get("updaterev"):
raise error.Abort(_("cannot specify both --noupdate and --updaterev"))
if opts.get("git"):
giturl = source
else:
giturl = git.maybegiturl(source)
giturl = cloneuri.determine_git_uri(opts.get("git"), source)
if giturl is not None:
if opts.get("noupdate"):
update = False

View File

@ -134,6 +134,7 @@ from edenscm import (
bundle2,
changegroup,
changelog2,
cloneuri,
cmdutil,
commands,
context,
@ -141,7 +142,6 @@ from edenscm import (
error,
exchange,
extensions,
git,
hg,
localrepo,
match,
@ -286,10 +286,7 @@ def wrappackers():
def cloneshallow(orig, ui, source, *args, **opts):
# skip for (full) git repos
if opts.get("git"):
giturl = source
else:
giturl = git.maybegiturl(source)
giturl = cloneuri.determine_git_uri(opts.get("git"), source)
if opts.get("shallow") and giturl is None:
repos = []

View File

@ -40,6 +40,7 @@ testmod("edenscm.ext.github.submit")
testmod("edenscm.ext.github.templates")
testmod("edenscm.changegroup")
testmod("edenscm.changelog")
testmod("edenscm.cloneuri")
testmod("edenscm.cmdutil")
testmod("edenscm.color")
testmod("edenscm.config")