Skip to content
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
1 change: 1 addition & 0 deletions dvc/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ class RelPath(str):
Optional("analytics", default=True): Bool,
Optional("hardlink_lock", default=False): Bool,
Optional("no_scm", default=False): Bool,
Optional("autostage", default=False): Bool,
Optional("experiments", default=False): Bool,
Optional("check_update", default=True): Bool,
},
Expand Down
6 changes: 5 additions & 1 deletion dvc/repo/scm_context.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,11 @@ def run(repo, *args, **kw):
try:
result = method(repo, *args, **kw)
repo.scm.reset_ignores()
repo.scm.remind_to_track()
autostage = repo.config.get("core", {}).get("autostage", False)
if autostage:
repo.scm.track_changed_files()
else:
repo.scm.remind_to_track()
repo.scm.reset_tracked_files()
return result
except Exception:
Expand Down
5 changes: 5 additions & 0 deletions dvc/scm/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,11 @@ def remind_to_track(self):
Method to remind user to track newly created files handled by scm
"""

def track_changed_files(self):
"""
Method to stage files that have changed
"""

def track_file(self, path):
"""
Method to add file to mechanism that will remind user
Expand Down
6 changes: 6 additions & 0 deletions dvc/scm/git.py
Original file line number Diff line number Diff line change
Expand Up @@ -381,6 +381,12 @@ def remind_to_track(self):
"\tgit add {files}".format(files=files)
)

def track_changed_files(self):
if not self.files_to_track:
return

self.add(self.files_to_track)

def track_file(self, path):
self.files_to_track.add(path)

Expand Down
15 changes: 15 additions & 0 deletions tests/unit/scm/test_scm.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ def test_should_successfully_perform_method(self):
method = mock.Mock()
wrapped = scm_context(method)

self.repo_mock.configure_mock(config={})
wrapped(self.repo_mock)

self.assertEqual(1, method.call_count)
Expand All @@ -25,6 +26,20 @@ def test_should_successfully_perform_method(self):

self.assertEqual(0, self.scm_mock.cleanup_ignores.call_count)

def test_should_check_autostage(self):
method = mock.Mock()
wrapped = scm_context(method)

config_autostage_attrs = {"config": {"core": {"autostage": True}}}
self.repo_mock.configure_mock(**config_autostage_attrs)
wrapped(self.repo_mock)

self.assertEqual(1, method.call_count)
self.assertEqual(1, self.scm_mock.reset_ignores.call_count)
self.assertEqual(1, self.scm_mock.track_changed_files.call_count)

self.assertEqual(0, self.scm_mock.cleanup_ignores.call_count)

def test_should_throw_and_cleanup(self):
method = mock.Mock(side_effect=Exception("some problem"))
wrapped = scm_context(method)
Expand Down