Skip to content

Commit

Permalink
Bugfix: sending geojson diff output to stdout...
Browse files Browse the repository at this point in the history
 ... didn't work in a multi-dataset repo, even if only one dataset had changed.
  • Loading branch information
olsen232 committed Aug 24, 2022
1 parent 70f980b commit bde1deb
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 11 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ _When adding new entries to the changelog, please include issue/PR numbers where
## 0.11.6 (UNRELEASED)

- "Primary key conflicts" - conflicts caused by reusing a primary key which is already assigned to a feature outside the spatial filter - are renamed to "spatial filter conflicts" for future proofing with other dataset types. Consequently, commit option `--allow-pk-conflicts` is renamed to `--allow-spatial-filter-conflicts`.
- Bugfix: directing geojson diff output to the console didn't work in a multi-dataset repo, even if only one dataset had changed. [#702](https://github.com/koordinates/kart/issues/702)

## 0.11.5

Expand Down
13 changes: 4 additions & 9 deletions kart/json_diff_writers.py
Original file line number Diff line number Diff line change
Expand Up @@ -398,20 +398,16 @@ def _check_output_path(cls, repo, output_path):
return output_path

def write_diff(self):
has_changes = False

if len(self.all_ds_paths) > 1 and not isinstance(self.output_path, Path):
repo_diff = self.get_repo_diff()
self.has_changes = bool(repo_diff)
if len(repo_diff) > 1 and not isinstance(self.output_path, Path):
raise click.BadParameter(
"Need to specify a directory via --output for GeoJSON with more than one dataset",
param_hint="--output",
)
for ds_path in self.all_ds_paths:
ds_diff = self.get_dataset_diff(ds_path)
if not ds_diff:
continue

for ds_path, ds_diff in repo_diff.items():
self._warn_about_any_non_feature_diffs(ds_path, ds_diff)
has_changes = True
output_obj = {
"type": "FeatureCollection",
"features": self.filtered_dataset_deltas_as_geojson(ds_path, ds_diff),
Expand All @@ -427,7 +423,6 @@ def write_diff(self):
ds_output_path,
json_style=self.json_style,
)
self.has_changes = has_changes
self.write_warnings_footer()

def _warn_about_any_non_feature_diffs(
Expand Down
14 changes: 12 additions & 2 deletions tests/test_diff.py
Original file line number Diff line number Diff line change
Expand Up @@ -1897,14 +1897,24 @@ def test_diff_geojson_usage(data_archive, cli_runner, tmp_path):
r = cli_runner.invoke(["-C", repo_path, "import", src_gpkg_path])
assert r.exit_code == 0, r.stderr

# file/stdout output isn't allowed when there are multiple datasets
# stdout output is allowed even though there are multiple datasets - as long as only one has changed:
r = cli_runner.invoke(
[
"diff",
"--output-format=geojson",
"HEAD^...",
]
)
assert r.exit_code == 0, r.stderr

# stdout output is not allowed when there are changes to multiple datasets:
r = cli_runner.invoke(
[
"diff",
"--output-format=geojson",
"HEAD^^...",
]
)
assert r.exit_code == 2, r.stderr
assert (
r.stderr.splitlines()[-1]
Expand All @@ -1920,7 +1930,7 @@ def test_diff_geojson_usage(data_archive, cli_runner, tmp_path):
"diff",
"--output-format=geojson",
f"--output={myfile}",
"HEAD^...",
"HEAD^^...",
]
)
assert r.exit_code == 2, r.stderr
Expand Down

0 comments on commit bde1deb

Please sign in to comment.