From e43ff6618425e2bef57fdcfec215e71ca75246c0 Mon Sep 17 00:00:00 2001 From: "Mr. Outis" Date: Wed, 12 Feb 2020 12:33:34 -0600 Subject: [PATCH] git: quote filenames @ remind_to_track Fix #3303 --- dvc/scm/git/__init__.py | 5 ++++- tests/unit/scm/test_scm.py | 6 ++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/dvc/scm/git/__init__.py b/dvc/scm/git/__init__.py index 8f05ad0296..e70d6f7b0f 100644 --- a/dvc/scm/git/__init__.py +++ b/dvc/scm/git/__init__.py @@ -3,6 +3,7 @@ import logging import os import yaml +import shlex from funcy import cached_property from pathspec.patterns import GitWildMatchPattern @@ -321,11 +322,13 @@ def remind_to_track(self): if not self.files_to_track: return + files = " ".join(shlex.quote(path) for path in self.files_to_track) + logger.info( "\n" "To track the changes with git, run:\n" "\n" - "\tgit add {files}".format(files=" ".join(self.files_to_track)) + "\tgit add {files}".format(files=files) ) def track_file(self, path): diff --git a/tests/unit/scm/test_scm.py b/tests/unit/scm/test_scm.py index 513653139c..4fb590fc54 100644 --- a/tests/unit/scm/test_scm.py +++ b/tests/unit/scm/test_scm.py @@ -37,3 +37,9 @@ def test_should_throw_and_cleanup(self): self.assertEqual(0, self.scm_mock.reset_ignores.call_count) self.assertEqual(0, self.scm_mock.remind_to_track.call_count) + + +def test_remind_to_track(scm, caplog): + scm.files_to_track = ["fname with spaces.txt", "тест", "foo"] + scm.remind_to_track() + assert "git add 'fname with spaces.txt' 'тест' foo" in caplog.text