Skip to content

Commit 8533a7a

Browse files
fix: avoid empty commits when adding files (#842)
1 parent abc713b commit 8533a7a

File tree

3 files changed

+30
-0
lines changed

3 files changed

+30
-0
lines changed

renku/core/commands/dataset.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,8 @@ def edit_dataset(client, dataset_id, transform_fn):
131131
clean=False,
132132
commit=True,
133133
commit_only=COMMIT_DIFF_STRATEGY,
134+
commit_empty=False,
135+
raise_if_empty=True
134136
)
135137
def add_file(
136138
client,

renku/core/management/datasets.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,10 @@ def add_data_to_dataset(
234234
# commit all new data
235235
file_paths = {str(data['path']) for data in files if str(data['path'])}
236236
self.repo.git.add(*(file_paths - set(ignored)))
237+
238+
if not self.repo.is_dirty():
239+
return warning_message
240+
237241
self.repo.index.commit(
238242
'renku dataset: commiting {} newly added files'.
239243
format(len(file_paths) + len(ignored))

tests/cli/test_datasets.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1168,3 +1168,27 @@ def test_dataset_clean_up_when_add_fails(runner, client):
11681168
assert result.exit_code == 2
11691169
ref = client.renku_path / 'refs' / 'datasets' / 'new-dataset'
11701170
assert not ref.is_symlink() and not ref.exists()
1171+
1172+
1173+
def test_add_removes_local_path_information(runner, client, directory_tree):
1174+
"""Test local paths are removed when adding to a dataset."""
1175+
runner.invoke(cli, ['dataset', 'create', 'my-dataset'])
1176+
1177+
commit_sha_before = client.repo.head.object.hexsha
1178+
result = runner.invoke(
1179+
cli, ['dataset', 'add', 'my-dataset', directory_tree.strpath]
1180+
)
1181+
assert 0 == result.exit_code
1182+
1183+
commit_sha_after = client.repo.head.object.hexsha
1184+
assert commit_sha_before != commit_sha_after
1185+
1186+
commit_sha_before = commit_sha_after
1187+
result = runner.invoke(
1188+
cli, ['dataset', 'add', 'my-dataset', directory_tree.strpath]
1189+
)
1190+
assert 1 == result.exit_code
1191+
1192+
commit_sha_after = client.repo.head.object.hexsha
1193+
assert commit_sha_before == commit_sha_after
1194+
assert 'Error: There is nothing to commit.' in result.output

0 commit comments

Comments
 (0)