diff --git a/dvc/command/stage.py b/dvc/command/stage.py index 06cc03bbb..b9491b2d6 100644 --- a/dvc/command/stage.py +++ b/dvc/command/stage.py @@ -113,8 +113,11 @@ def parse_cmd(commands: List[str]) -> str: """ def quote_argument(arg: str): - should_quote = " " in arg and '"' not in arg - return f'"{arg}"' if should_quote else arg + if not arg: + return '""' + if " " in arg and '"' not in arg: + return f'"{arg}"' + return arg if len(commands) < 2: return " ".join(commands) diff --git a/tests/unit/command/test_stage.py b/tests/unit/command/test_stage.py index d7e21aef8..237cd89f7 100644 --- a/tests/unit/command/test_stage.py +++ b/tests/unit/command/test_stage.py @@ -10,6 +10,7 @@ from dvc.command.stage import CmdStageAdd (["echo", "foo", "bar"], "echo foo bar"), (["echo", '"foo bar"'], 'echo "foo bar"'), (["echo", "foo bar"], 'echo "foo bar"'), + (["cmd", "--flag", ""], 'cmd --flag ""'), ], ) def test_stage_add(mocker, dvc, command, parsed_command):