diff --git a/dvc/commands/add.py b/dvc/commands/add.py index 1e0ccd7ae..38146b30e 100644 --- a/dvc/commands/add.py +++ b/dvc/commands/add.py @@ -51,6 +51,7 @@ class CmdAdd(CmdBase): to_remote=self.args.to_remote, remote_jobs=self.args.remote_jobs, force=self.args.force, + relink=self.args.relink, ) except FileNotFoundError: logger.exception("") @@ -119,6 +120,13 @@ def add_parser(subparsers, parent_parser): default=False, help="Override local file or folder if exists.", ) + parser.add_argument( + "--no-relink", + dest="relink", + action="store_false", + help="Don't recreate links from cache to workspace.", + ) + parser.set_defaults(relink=True) parser.add_argument( "targets", nargs="+", help="Input files/directories to add." ).complete = completion.FILE diff --git a/dvc/commands/commit.py b/dvc/commands/commit.py index ef37e9cd9..a97019a3f 100644 --- a/dvc/commands/commit.py +++ b/dvc/commands/commit.py @@ -20,6 +20,7 @@ class CmdCommit(CmdBase): with_deps=self.args.with_deps, recursive=self.args.recursive, force=self.args.force, + relink=self.args.relink, ) except DvcException: logger.exception("failed to commit%s", (" " + target) if target else "") @@ -64,6 +65,13 @@ def add_parser(subparsers, parent_parser): default=False, help="Commit cache for subdirectories of the specified directory.", ) + commit_parser.add_argument( + "--no-relink", + dest="relink", + action="store_false", + help="Don't recreate links from cache to workspace.", + ) + commit_parser.set_defaults(relink=True) commit_parser.add_argument( "targets", nargs="*", diff --git a/dvc/repo/add.py b/dvc/repo/add.py index a7285be4d..7cbacad79 100644 --- a/dvc/repo/add.py +++ b/dvc/repo/add.py @@ -171,11 +171,16 @@ def _add_transfer( stage.dump() -def _add(stage: "Stage", source: Optional[str] = None, no_commit: bool = False) -> None: +def _add( + stage: "Stage", + source: Optional[str] = None, + no_commit: bool = False, + relink: bool = True, +) -> None: out = stage.outs[0] path = out.fs.abspath(source) if source else None try: - stage.add_outs(path, no_commit=no_commit) + stage.add_outs(path, no_commit=no_commit, relink=relink) except CacheLinkError: stage.dump() raise @@ -194,6 +199,7 @@ def add( to_remote: bool = False, remote_jobs: Optional[int] = None, force: bool = False, + relink: bool = True, ) -> list["Stage"]: add_targets = find_targets(targets, glob=glob) if not add_targets: @@ -224,7 +230,12 @@ def add( with warn_link_failures() as link_failures: for source, (stage, output_exists) in progress_iter(stages_with_targets): try: - _add(stage, source if output_exists else None, no_commit=no_commit) + _add( + stage, + source if output_exists else None, + no_commit=no_commit, + relink=relink, + ) except CacheLinkError: link_failures.append(stage.relpath) return stages