Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

exp init: autostage .gitignores, dvc.yaml and params file #6871

Merged
merged 1 commit into from
Nov 2, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 9 additions & 7 deletions dvc/repo/experiments/init.py
Original file line number Diff line number Diff line change
Expand Up @@ -224,13 +224,13 @@ def init(
assert "cmd" in context

params_kv = []
if context.get("params"):
params = context.get("params")
if params:
from dvc.utils.serialize import LOADERS

path = context["params"]
assert isinstance(path, str)
_, ext = os.path.splitext(path)
params_kv = [{path: list(LOADERS[ext](path))}]
assert isinstance(params, str)
_, ext = os.path.splitext(params)
params_kv = [{params: list(LOADERS[ext](params))}]

checkpoint_out = bool(context.get("live"))
models = context.get("models")
Expand All @@ -255,9 +255,11 @@ def init(
if not interactive or ui.confirm(
"Do you want to add the above contents to dvc.yaml?"
):
with _disable_logging():
scm = repo.scm
with _disable_logging(), scm.track_file_changes(autostage=True):
stage.dump(update_lock=False)
stage.ignore_outs()
stage.ignore_outs()
scm.track_file(params)
else:
raise DvcException("Aborting ...")
return stage
6 changes: 4 additions & 2 deletions dvc/scm/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,8 +183,10 @@ def track_file(self, path):
"""

@contextmanager
def track_file_changes(self, config=None):
autostage = get_in(config or {}, ["core", "autostage"])
def track_file_changes(self, config=None, autostage=False):
autostage = get_in(
config or {}, ["core", "autostage"], default=autostage
)

try:
yield
Expand Down