mirror of
https://github.com/Stone-Red-Code/dvc.git
synced 2026-11-29 15:28:28 +01:00
experiments: add dvc exp push/pull/list (#5042)
* git: add support for on_diverged in push_refspec * experiments: update executor for push-refspec changes * experiments: implement push() * tests: add tests for experiments.push * git: add iter_remote_refs * roughly equivalent to `git ls-remote --refs` * experiments: add experiments.list for listing local and remote experiments * refactor git upstream/downstream in tests * experiments: add experiments.pull * experiments: add CLI commands for push/pull/list * exp list: drop short options * experiments: s/list/ls/ * dulwich: catch not repo errors when creating remote client * fix remote rev resolution for list * fix command test * add tests for push/pull with ambiguous experiment names
This commit is contained in:
@@ -524,6 +524,68 @@ class CmdExperimentsBranch(CmdBase):
|
||||
return 0
|
||||
|
||||
|
||||
class CmdExperimentsList(CmdBase):
|
||||
def run(self):
|
||||
|
||||
exps = self.repo.experiments.ls(
|
||||
rev=self.args.rev,
|
||||
git_remote=self.args.git_remote,
|
||||
all_=self.args.all,
|
||||
)
|
||||
for baseline in exps:
|
||||
tag = self.repo.scm.describe(baseline)
|
||||
if not tag:
|
||||
branch = self.repo.scm.describe(baseline, base="refs/heads")
|
||||
if branch:
|
||||
tag = branch.split("/")[-1]
|
||||
name = tag if tag else baseline[:7]
|
||||
logger.info(f"{name}:")
|
||||
for exp_name in exps[baseline]:
|
||||
logger.info(f"\t{exp_name}")
|
||||
|
||||
return 0
|
||||
|
||||
|
||||
class CmdExperimentsPush(CmdBase):
|
||||
def run(self):
|
||||
|
||||
self.repo.experiments.push(
|
||||
self.args.git_remote, self.args.experiment, force=self.args.force
|
||||
)
|
||||
|
||||
logger.info(
|
||||
(
|
||||
"Pushed experiment '%s' to Git remote '%s'. "
|
||||
"To push cache for this experiment to a DVC remote run:\n\n"
|
||||
"\tdvc push ..."
|
||||
),
|
||||
self.args.experiment,
|
||||
self.args.git_remote,
|
||||
)
|
||||
|
||||
return 0
|
||||
|
||||
|
||||
class CmdExperimentsPull(CmdBase):
|
||||
def run(self):
|
||||
|
||||
self.repo.experiments.pull(
|
||||
self.args.git_remote, self.args.experiment, force=self.args.force
|
||||
)
|
||||
|
||||
logger.info(
|
||||
(
|
||||
"Pulled experiment '%s' from Git remote '%s'. "
|
||||
"To pull cache for this experiment from a DVC remote run:\n\n"
|
||||
"\tdvc pull ..."
|
||||
),
|
||||
self.args.experiment,
|
||||
self.args.git_remote,
|
||||
)
|
||||
|
||||
return 0
|
||||
|
||||
|
||||
def add_parser(subparsers, parent_parser):
|
||||
EXPERIMENTS_HELP = "Commands to run and compare experiments."
|
||||
|
||||
@@ -842,6 +904,88 @@ def add_parser(subparsers, parent_parser):
|
||||
)
|
||||
experiments_branch_parser.set_defaults(func=CmdExperimentsBranch)
|
||||
|
||||
EXPERIMENTS_LIST_HELP = "List local and remote experiments."
|
||||
experiments_list_parser = experiments_subparsers.add_parser(
|
||||
"list",
|
||||
parents=[parent_parser],
|
||||
description=append_doc_link(EXPERIMENTS_LIST_HELP, "experiments/list"),
|
||||
help=EXPERIMENTS_LIST_HELP,
|
||||
formatter_class=argparse.RawDescriptionHelpFormatter,
|
||||
)
|
||||
experiments_list_parser.add_argument(
|
||||
"--rev",
|
||||
type=str,
|
||||
default=None,
|
||||
help=(
|
||||
"List experiments derived from the specified revision. "
|
||||
"Defaults to HEAD if neither `--rev` nor `--all` are specified."
|
||||
),
|
||||
metavar="<rev>",
|
||||
)
|
||||
experiments_list_parser.add_argument(
|
||||
"--all", action="store_true", help="List all experiments.",
|
||||
)
|
||||
experiments_list_parser.add_argument(
|
||||
"git_remote",
|
||||
nargs="?",
|
||||
default=None,
|
||||
help=(
|
||||
"Optional Git remote name or Git URL. If provided, experiments "
|
||||
"from the specified Git repository will be listed instead of "
|
||||
"local experiments."
|
||||
),
|
||||
metavar="[<git_remote>]",
|
||||
)
|
||||
experiments_list_parser.set_defaults(func=CmdExperimentsList)
|
||||
|
||||
EXPERIMENTS_PUSH_HELP = "Push a local experiment to a Git remote."
|
||||
experiments_push_parser = experiments_subparsers.add_parser(
|
||||
"push",
|
||||
parents=[parent_parser],
|
||||
description=append_doc_link(EXPERIMENTS_PUSH_HELP, "experiments/push"),
|
||||
help=EXPERIMENTS_PUSH_HELP,
|
||||
formatter_class=argparse.RawDescriptionHelpFormatter,
|
||||
)
|
||||
experiments_push_parser.add_argument(
|
||||
"-f",
|
||||
"--force",
|
||||
action="store_true",
|
||||
help="Replace experiment in the remote if it already exists.",
|
||||
)
|
||||
experiments_push_parser.add_argument(
|
||||
"git_remote",
|
||||
help="Git remote name or Git URL.",
|
||||
metavar="<git_remote>",
|
||||
)
|
||||
experiments_push_parser.add_argument(
|
||||
"experiment", help="Experiment to push.", metavar="<experiment>",
|
||||
)
|
||||
experiments_push_parser.set_defaults(func=CmdExperimentsPush)
|
||||
|
||||
EXPERIMENTS_PULL_HELP = "Pull an experiment from a Git remote."
|
||||
experiments_pull_parser = experiments_subparsers.add_parser(
|
||||
"pull",
|
||||
parents=[parent_parser],
|
||||
description=append_doc_link(EXPERIMENTS_PULL_HELP, "experiments/pull"),
|
||||
help=EXPERIMENTS_PULL_HELP,
|
||||
formatter_class=argparse.RawDescriptionHelpFormatter,
|
||||
)
|
||||
experiments_pull_parser.add_argument(
|
||||
"-f",
|
||||
"--force",
|
||||
action="store_true",
|
||||
help="Replace local experiment already exists.",
|
||||
)
|
||||
experiments_pull_parser.add_argument(
|
||||
"git_remote",
|
||||
help="Git remote name or Git URL.",
|
||||
metavar="<git_remote>",
|
||||
)
|
||||
experiments_pull_parser.add_argument(
|
||||
"experiment", help="Experiment to pull.", metavar="<experiment>",
|
||||
)
|
||||
experiments_pull_parser.set_defaults(func=CmdExperimentsPull)
|
||||
|
||||
|
||||
def _add_run_common(parser):
|
||||
"""Add common args for 'exp run' and 'exp resume'."""
|
||||
|
||||
@@ -652,3 +652,18 @@ class Experiments:
|
||||
from dvc.repo.experiments.gc import gc
|
||||
|
||||
return gc(self.repo, *args, **kwargs)
|
||||
|
||||
def push(self, *args, **kwargs):
|
||||
from dvc.repo.experiments.push import push
|
||||
|
||||
return push(self.repo, *args, **kwargs)
|
||||
|
||||
def pull(self, *args, **kwargs):
|
||||
from dvc.repo.experiments.pull import pull
|
||||
|
||||
return pull(self.repo, *args, **kwargs)
|
||||
|
||||
def ls(self, *args, **kwargs):
|
||||
from dvc.repo.experiments.ls import ls
|
||||
|
||||
return ls(self.repo, *args, **kwargs)
|
||||
|
||||
@@ -152,21 +152,18 @@ class BaseExecutor:
|
||||
if not ref.startswith(EXEC_NAMESPACE) and ref != EXPS_STASH:
|
||||
refs.append(ref)
|
||||
|
||||
def on_diverged_ref(orig_ref, new_rev):
|
||||
def on_diverged_ref(orig_ref: str, new_rev: str):
|
||||
orig_rev = dest_scm.get_ref(orig_ref)
|
||||
if dest_scm.diff(orig_rev, new_rev):
|
||||
if force:
|
||||
logger.debug(
|
||||
"Replacing existing experiment '%s'",
|
||||
os.fsdecode(orig_ref),
|
||||
"Replacing existing experiment '%s'", orig_ref,
|
||||
)
|
||||
return True
|
||||
if on_diverged:
|
||||
checkpoint = self.scm.get_ref(EXEC_CHECKPOINT) is not None
|
||||
on_diverged(orig_ref, checkpoint)
|
||||
logger.debug(
|
||||
"Reproduced existing experiment '%s'", os.fsdecode(orig_ref)
|
||||
)
|
||||
logger.debug("Reproduced existing experiment '%s'", orig_ref)
|
||||
return False
|
||||
|
||||
# fetch experiments
|
||||
|
||||
@@ -0,0 +1,50 @@
|
||||
import logging
|
||||
from collections import defaultdict
|
||||
|
||||
from dvc.repo import locked
|
||||
from dvc.repo.scm_context import scm_context
|
||||
from dvc.scm.base import RevError
|
||||
|
||||
from .utils import (
|
||||
exp_refs,
|
||||
exp_refs_by_baseline,
|
||||
remote_exp_refs,
|
||||
remote_exp_refs_by_baseline,
|
||||
)
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
@locked
|
||||
@scm_context
|
||||
def ls(repo, *args, rev=None, git_remote=None, all_=False, **kwargs):
|
||||
from dvc.scm.git import Git
|
||||
|
||||
if rev:
|
||||
try:
|
||||
rev = repo.scm.resolve_rev(rev)
|
||||
except RevError:
|
||||
if not (git_remote and Git.is_sha(rev)):
|
||||
# This could be a remote rev that has not been fetched yet
|
||||
raise
|
||||
elif not all_:
|
||||
rev = repo.scm.get_rev()
|
||||
|
||||
results = defaultdict(list)
|
||||
|
||||
if rev:
|
||||
if git_remote:
|
||||
gen = remote_exp_refs_by_baseline(repo.scm, git_remote, rev)
|
||||
else:
|
||||
gen = exp_refs_by_baseline(repo.scm, rev)
|
||||
for info in gen:
|
||||
results[rev].append(info.name)
|
||||
elif all_:
|
||||
if git_remote:
|
||||
gen = remote_exp_refs(repo.scm, git_remote)
|
||||
else:
|
||||
gen = exp_refs(repo.scm)
|
||||
for info in gen:
|
||||
results[info.baseline_sha].append(info.name)
|
||||
|
||||
return results
|
||||
@@ -0,0 +1,57 @@
|
||||
import logging
|
||||
|
||||
from dvc.exceptions import DvcException, InvalidArgumentError
|
||||
from dvc.repo import locked
|
||||
from dvc.repo.scm_context import scm_context
|
||||
|
||||
from .utils import remote_exp_refs_by_name
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
@locked
|
||||
@scm_context
|
||||
def pull(repo, git_remote, exp_name, *args, force=False, **kwargs):
|
||||
exp_ref = _get_exp_ref(repo, git_remote, exp_name)
|
||||
|
||||
def on_diverged(refname: str, rev: str) -> bool:
|
||||
if repo.scm.get_ref(refname) == rev:
|
||||
return True
|
||||
raise DvcException(
|
||||
f"Local experiment '{exp_name}' has diverged from remote "
|
||||
"experiment with the same name. To override the local experiment "
|
||||
"re-run with '--force'."
|
||||
)
|
||||
|
||||
refspec = f"{exp_ref}:{exp_ref}"
|
||||
logger.debug("Pull '%s' -> '%s'", git_remote, refspec)
|
||||
repo.scm.fetch_refspecs(
|
||||
git_remote, [refspec], force=force, on_diverged=on_diverged
|
||||
)
|
||||
|
||||
|
||||
def _get_exp_ref(repo, git_remote, exp_name):
|
||||
if exp_name.startswith("refs/"):
|
||||
return exp_name
|
||||
|
||||
exp_refs = list(remote_exp_refs_by_name(repo.scm, git_remote, exp_name))
|
||||
if not exp_refs:
|
||||
raise InvalidArgumentError(
|
||||
f"Experiment '{exp_name}' does not exist in '{git_remote}'"
|
||||
)
|
||||
if len(exp_refs) > 1:
|
||||
cur_rev = repo.scm.get_rev()
|
||||
for info in exp_refs:
|
||||
if info.baseline_sha == cur_rev:
|
||||
return info
|
||||
msg = [
|
||||
(
|
||||
f"Ambiguous name '{exp_name}' refers to multiple "
|
||||
"experiments in '{git_remote}'. Use full refname to pull one "
|
||||
"of the following:"
|
||||
),
|
||||
"",
|
||||
]
|
||||
msg.extend([f"\t{info}" for info in exp_refs])
|
||||
raise InvalidArgumentError("\n".join(msg))
|
||||
return exp_refs[0]
|
||||
@@ -0,0 +1,57 @@
|
||||
import logging
|
||||
|
||||
from dvc.exceptions import DvcException, InvalidArgumentError
|
||||
from dvc.repo import locked
|
||||
from dvc.repo.scm_context import scm_context
|
||||
|
||||
from .utils import exp_refs_by_name
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
@locked
|
||||
@scm_context
|
||||
def push(repo, git_remote, exp_name, *args, force=False, **kwargs):
|
||||
exp_ref = _get_exp_ref(repo, exp_name)
|
||||
|
||||
def on_diverged(refname: str, rev: str) -> bool:
|
||||
if repo.scm.get_ref(refname) == rev:
|
||||
return True
|
||||
raise DvcException(
|
||||
f"Local experiment '{exp_name}' has diverged from remote "
|
||||
"experiment with the same name. To override the remote experiment "
|
||||
"re-run with '--force'."
|
||||
)
|
||||
|
||||
refname = str(exp_ref)
|
||||
logger.debug("Push '%s' -> '%s'", exp_ref, git_remote)
|
||||
repo.scm.push_refspec(
|
||||
git_remote, refname, refname, force=force, on_diverged=on_diverged
|
||||
)
|
||||
|
||||
|
||||
def _get_exp_ref(repo, exp_name):
|
||||
if exp_name.startswith("refs/"):
|
||||
return exp_name
|
||||
|
||||
exp_refs = list(exp_refs_by_name(repo.scm, exp_name))
|
||||
if not exp_refs:
|
||||
raise InvalidArgumentError(
|
||||
f"'{exp_name}' is not a valid experiment name"
|
||||
)
|
||||
if len(exp_refs) > 1:
|
||||
cur_rev = repo.scm.get_rev()
|
||||
for info in exp_refs:
|
||||
if info.baseline_sha == cur_rev:
|
||||
return info
|
||||
msg = [
|
||||
(
|
||||
f"Ambiguous name '{exp_name}' refers to multiple "
|
||||
"experiments. Use full refname to push one of the "
|
||||
"following:"
|
||||
),
|
||||
"",
|
||||
]
|
||||
msg.extend([f"\t{info}" for info in exp_refs])
|
||||
raise InvalidArgumentError("\n".join(msg))
|
||||
return exp_refs[0]
|
||||
@@ -30,3 +30,44 @@ def exp_refs_by_name(
|
||||
for ref_info in exp_refs(scm):
|
||||
if ref_info.name == name:
|
||||
yield ref_info
|
||||
|
||||
|
||||
def exp_refs_by_baseline(
|
||||
scm: "Git", rev: str
|
||||
) -> Generator["ExpRefInfo", None, None]:
|
||||
"""Iterate over all experiment refs with the specified baseline."""
|
||||
ref_info = ExpRefInfo(baseline_sha=rev)
|
||||
for ref in scm.iter_refs(base=str(ref_info)):
|
||||
if ref.startswith(EXEC_NAMESPACE) or ref == EXPS_STASH:
|
||||
continue
|
||||
yield ExpRefInfo.from_ref(ref)
|
||||
|
||||
|
||||
def remote_exp_refs(
|
||||
scm: "Git", url: str
|
||||
) -> Generator["ExpRefInfo", None, None]:
|
||||
"""Iterate over all remote experiment refs."""
|
||||
for ref in scm.iter_remote_refs(url, base=EXPS_NAMESPACE):
|
||||
if ref.startswith(EXEC_NAMESPACE) or ref == EXPS_STASH:
|
||||
continue
|
||||
yield ExpRefInfo.from_ref(ref)
|
||||
|
||||
|
||||
def remote_exp_refs_by_name(
|
||||
scm: "Git", url: str, name: str
|
||||
) -> Generator["ExpRefInfo", None, None]:
|
||||
"""Iterate over all remote experiment refs matching the specified name."""
|
||||
for ref_info in remote_exp_refs(scm, url):
|
||||
if ref_info.name == name:
|
||||
yield ref_info
|
||||
|
||||
|
||||
def remote_exp_refs_by_baseline(
|
||||
scm: "Git", url: str, rev: str
|
||||
) -> Generator["ExpRefInfo", None, None]:
|
||||
"""Iterate over all remote experiment refs with the specified baseline."""
|
||||
ref_info = ExpRefInfo(baseline_sha=rev)
|
||||
for ref in scm.iter_remote_refs(url, base=str(ref_info)):
|
||||
if ref.startswith(EXEC_NAMESPACE) or ref == EXPS_STASH:
|
||||
continue
|
||||
yield ExpRefInfo.from_ref(ref)
|
||||
|
||||
@@ -321,6 +321,7 @@ class Git(Base):
|
||||
get_ref = partialmethod(_backend_func, "get_ref")
|
||||
remove_ref = partialmethod(_backend_func, "remove_ref")
|
||||
iter_refs = partialmethod(_backend_func, "iter_refs")
|
||||
iter_remote_refs = partialmethod(_backend_func, "iter_remote_refs")
|
||||
get_refs_containing = partialmethod(_backend_func, "get_refs_containing")
|
||||
push_refspec = partialmethod(_backend_func, "push_refspec")
|
||||
fetch_refspecs = partialmethod(_backend_func, "fetch_refspecs")
|
||||
|
||||
@@ -174,22 +174,42 @@ class BaseGitBackend(ABC):
|
||||
If base is specified, only refs which begin with base will be yielded.
|
||||
"""
|
||||
|
||||
@abstractmethod
|
||||
def iter_remote_refs(self, url: str, base: Optional[str] = None):
|
||||
"""Iterate over all refs in the specified remote Git repo.
|
||||
|
||||
If base is specified, only refs which begin with base will be yielded.
|
||||
URL can be a named Git remote or URL.
|
||||
"""
|
||||
|
||||
@abstractmethod
|
||||
def get_refs_containing(self, rev: str, pattern: Optional[str] = None):
|
||||
"""Iterate over all git refs containing the specfied revision."""
|
||||
|
||||
@abstractmethod
|
||||
def push_refspec(self, url: str, src: Optional[str], dest: str):
|
||||
def push_refspec(
|
||||
self,
|
||||
url: str,
|
||||
src: Optional[str],
|
||||
dest: str,
|
||||
force: bool = False,
|
||||
on_diverged: Optional[Callable[[str, str], bool]] = None,
|
||||
):
|
||||
"""Push refspec to a remote Git repo.
|
||||
|
||||
Args:
|
||||
url: Remote repo Git URL (Note this must be a Git URL and not
|
||||
a remote name).
|
||||
url: Git remote name or absolute Git URL.
|
||||
src: Local refspec. If src ends with "/" it will be treated as a
|
||||
prefix, and all refs inside src will be pushed using dest
|
||||
as destination refspec prefix. If src is None, dest will be
|
||||
deleted from the remote.
|
||||
dest: Remote refspec.
|
||||
force: If True, remote refs will be overwritten.
|
||||
on_diverged: Callback function which will be called if local ref
|
||||
and remote have diverged and force is False. If the callback
|
||||
returns True the remote ref will be overwritten.
|
||||
Callback will be of the form:
|
||||
on_diverged(local_refname, remote_sha)
|
||||
"""
|
||||
|
||||
@abstractmethod
|
||||
@@ -198,7 +218,7 @@ class BaseGitBackend(ABC):
|
||||
url: str,
|
||||
refspecs: Iterable[str],
|
||||
force: Optional[bool] = False,
|
||||
on_diverged: Optional[Callable[[bytes, bytes], bool]] = None,
|
||||
on_diverged: Optional[Callable[[str, str], bool]] = None,
|
||||
):
|
||||
"""Fetch refspecs from a remote Git repo.
|
||||
|
||||
@@ -211,6 +231,8 @@ class BaseGitBackend(ABC):
|
||||
on_diverged: Callback function which will be called if local ref
|
||||
and remote have diverged and force is False. If the callback
|
||||
returns True the local ref will be overwritten.
|
||||
Callback will be of the form:
|
||||
on_diverged(local_refname, remote_sha)
|
||||
"""
|
||||
|
||||
@abstractmethod
|
||||
|
||||
@@ -185,11 +185,92 @@ class DulwichBackend(BaseGitBackend): # pylint:disable=abstract-method
|
||||
else:
|
||||
yield os.fsdecode(key)
|
||||
|
||||
def iter_remote_refs(self, url: str, base: Optional[str] = None):
|
||||
from dulwich.client import get_transport_and_path
|
||||
from dulwich.porcelain import get_remote_repo
|
||||
|
||||
try:
|
||||
_remote, location = get_remote_repo(self.repo, url)
|
||||
client, path = get_transport_and_path(location)
|
||||
except Exception as exc:
|
||||
raise SCMError(
|
||||
f"'{url}' is not a valid Git remote or URL"
|
||||
) from exc
|
||||
|
||||
if base:
|
||||
yield from (
|
||||
os.fsdecode(ref)
|
||||
for ref in client.get_refs(path)
|
||||
if ref.startswith(os.fsencode(base))
|
||||
)
|
||||
else:
|
||||
yield from (os.fsdecode(ref) for ref in client.get_refs(path))
|
||||
|
||||
def get_refs_containing(self, rev: str, pattern: Optional[str] = None):
|
||||
raise NotImplementedError
|
||||
|
||||
def push_refspec(self, url: str, src: Optional[str], dest: str):
|
||||
def push_refspec(
|
||||
self,
|
||||
url: str,
|
||||
src: Optional[str],
|
||||
dest: str,
|
||||
force: bool = False,
|
||||
on_diverged: Optional[Callable[[str, str], bool]] = None,
|
||||
):
|
||||
from dulwich.client import get_transport_and_path
|
||||
from dulwich.errors import NotGitRepository, SendPackError
|
||||
from dulwich.porcelain import (
|
||||
DivergedBranches,
|
||||
check_diverged,
|
||||
get_remote_repo,
|
||||
)
|
||||
|
||||
dest_refs, values = self._push_dest_refs(src, dest)
|
||||
|
||||
try:
|
||||
_remote, location = get_remote_repo(self.repo, url)
|
||||
client, path = get_transport_and_path(location)
|
||||
except Exception as exc:
|
||||
raise SCMError(
|
||||
f"'{url}' is not a valid Git remote or URL"
|
||||
) from exc
|
||||
|
||||
def update_refs(refs):
|
||||
new_refs = {}
|
||||
for ref, value in zip(dest_refs, values):
|
||||
if ref in refs:
|
||||
local_sha = self.repo.refs[ref]
|
||||
remote_sha = refs[ref]
|
||||
try:
|
||||
check_diverged(self.repo, remote_sha, local_sha)
|
||||
except DivergedBranches:
|
||||
if not force:
|
||||
overwrite = False
|
||||
if on_diverged:
|
||||
overwrite = on_diverged(
|
||||
os.fsdecode(ref), os.fsdecode(remote_sha),
|
||||
)
|
||||
if not overwrite:
|
||||
continue
|
||||
new_refs[ref] = value
|
||||
return new_refs
|
||||
|
||||
def progress(msg):
|
||||
logger.trace("git send_pack: %s", msg)
|
||||
|
||||
try:
|
||||
client.send_pack(
|
||||
path,
|
||||
update_refs,
|
||||
self.repo.object_store.generate_pack_data,
|
||||
progress=progress,
|
||||
)
|
||||
except (NotGitRepository, SendPackError) as exc:
|
||||
raise SCMError("Git failed to push '{src}' to '{url}'") from exc
|
||||
|
||||
def _push_dest_refs(
|
||||
self, src: str, dest: str
|
||||
) -> Tuple[Iterable[bytes], Iterable[bytes]]:
|
||||
from dulwich.objects import ZERO_SHA
|
||||
|
||||
if src is not None and src.endswith("/"):
|
||||
@@ -203,37 +284,22 @@ class DulwichBackend(BaseGitBackend): # pylint:disable=abstract-method
|
||||
else:
|
||||
values = [self.repo.refs[os.fsencode(src)]]
|
||||
dest_refs = [os.fsencode(dest)]
|
||||
|
||||
def update_refs(refs):
|
||||
for ref, value in zip(dest_refs, values):
|
||||
refs[ref] = value
|
||||
return refs
|
||||
|
||||
try:
|
||||
client, path = get_transport_and_path(url)
|
||||
except Exception as exc:
|
||||
raise SCMError("Could not get remote client") from exc
|
||||
|
||||
def progress(msg):
|
||||
logger.trace("git send_pack: %s", msg)
|
||||
|
||||
client.send_pack(
|
||||
path,
|
||||
update_refs,
|
||||
self.repo.object_store.generate_pack_data,
|
||||
progress=progress,
|
||||
)
|
||||
return dest_refs, values
|
||||
|
||||
def fetch_refspecs(
|
||||
self,
|
||||
url: str,
|
||||
refspecs: Iterable[str],
|
||||
force: Optional[bool] = False,
|
||||
on_diverged: Optional[Callable[[bytes, bytes], bool]] = None,
|
||||
on_diverged: Optional[Callable[[str, str], bool]] = None,
|
||||
):
|
||||
from dulwich.client import get_transport_and_path
|
||||
from dulwich.objectspec import parse_reftuples
|
||||
from dulwich.porcelain import DivergedBranches, check_diverged
|
||||
from dulwich.porcelain import (
|
||||
DivergedBranches,
|
||||
check_diverged,
|
||||
get_remote_repo,
|
||||
)
|
||||
|
||||
fetch_refs = []
|
||||
|
||||
@@ -253,10 +319,12 @@ class DulwichBackend(BaseGitBackend): # pylint:disable=abstract-method
|
||||
]
|
||||
|
||||
try:
|
||||
client, path = get_transport_and_path(url)
|
||||
_remote, location = get_remote_repo(self.repo, url)
|
||||
client, path = get_transport_and_path(location)
|
||||
except Exception as exc:
|
||||
|
||||
raise SCMError("Could not get remote client") from exc
|
||||
raise SCMError(
|
||||
f"'{url}' is not a valid Git remote or URL"
|
||||
) from exc
|
||||
|
||||
def progress(msg):
|
||||
logger.trace("git fetch: %s", msg)
|
||||
|
||||
@@ -362,6 +362,9 @@ class GitPythonBackend(BaseGitBackend): # pylint:disable=abstract-method
|
||||
base = base[:-1]
|
||||
yield "/".join([base, ref.name])
|
||||
|
||||
def iter_remote_refs(self, url: str, base: Optional[str] = None):
|
||||
raise NotImplementedError
|
||||
|
||||
def get_refs_containing(self, rev: str, pattern: Optional[str] = None):
|
||||
from git.exc import GitCommandError
|
||||
|
||||
@@ -379,7 +382,14 @@ class GitPythonBackend(BaseGitBackend): # pylint:disable=abstract-method
|
||||
except GitCommandError:
|
||||
pass
|
||||
|
||||
def push_refspec(self, url: str, src: Optional[str], dest: str):
|
||||
def push_refspec(
|
||||
self,
|
||||
url: str,
|
||||
src: Optional[str],
|
||||
dest: str,
|
||||
force: bool = False,
|
||||
on_diverged: Optional[Callable[[str, str], bool]] = None,
|
||||
):
|
||||
raise NotImplementedError
|
||||
|
||||
def fetch_refspecs(
|
||||
@@ -387,7 +397,7 @@ class GitPythonBackend(BaseGitBackend): # pylint:disable=abstract-method
|
||||
url: str,
|
||||
refspecs: Iterable[str],
|
||||
force: Optional[bool] = False,
|
||||
on_diverged: Optional[Callable[[bytes, bytes], bool]] = None,
|
||||
on_diverged: Optional[Callable[[str, str], bool]] = None,
|
||||
):
|
||||
raise NotImplementedError
|
||||
|
||||
|
||||
Reference in New Issue
Block a user