Skip to content

Commit

Permalink
Remove repo.is_empty from codebase
Browse files Browse the repository at this point in the history
Replace with repo.head_is_unborn:

- repo.is_empty - repo has no commits, no extra config, and is on an
  unborn branch with the default branch name
- repo.head_is_unborn - repo HEAD points at an unborn branch

The second one is what we actually care about - using the first one
means we can get false negatives (the no-commits codepath won't trigger
because of some other minor change in the repo)
  • Loading branch information
olsen232 committed Jun 9, 2022
1 parent e39154a commit ec3e010
Show file tree
Hide file tree
Showing 6 changed files with 11 additions and 17 deletions.
10 changes: 2 additions & 8 deletions kart/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,7 @@ def data(ctx, **kwargs):
def data_ls(ctx, output_format, refish):
"""List all of the datasets in the Kart repository"""
repo = ctx.obj.get_repo(allowed_states=KartRepoState.ALL_STATES)
if repo.is_empty:
ds_paths = []
else:
ds_paths = [ds.path for ds in repo.datasets(refish)]
ds_paths = list(repo.datasets(refish).all_paths())

if output_format == "text":
if ds_paths:
Expand Down Expand Up @@ -79,10 +76,7 @@ def data_rm(ctx, message, output_format, datasets):
raise click.UsageError("Specify a dataset to delete: eg `kart data rm DATASET`")

repo = ctx.obj.get_repo()
if repo.is_empty:
existing_ds_paths = set()
else:
existing_ds_paths = set(ds.path for ds in repo.datasets())
existing_ds_paths = set(repo.datasets().all_paths())

for ds_path in datasets:
if ds_path not in existing_ds_paths:
Expand Down
2 changes: 1 addition & 1 deletion tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,7 @@ def _data_imported(archive, source_gpkg, table):
assert r.exit_code == 0, r.stderr

repo = KartRepo(import_path)
assert repo.is_empty
assert repo.head_is_unborn
repo.free()
del repo

Expand Down
4 changes: 2 additions & 2 deletions tests/test_init.py
Original file line number Diff line number Diff line change
Expand Up @@ -650,7 +650,7 @@ def test_init_import(

repo = KartRepo(repo_path)
assert not repo.is_bare
assert not repo.is_empty
assert not repo.head_is_unborn

assert repo.head.name == "refs/heads/main"
assert repo.head.shorthand == "main"
Expand Down Expand Up @@ -772,7 +772,7 @@ def test_init_import_name_clash(data_archive, cli_runner):

repo = KartRepo(repo_path)
assert not repo.is_bare
assert not repo.is_empty
assert not repo.head_is_unborn

# working copy exists
wc = repo_path / "editing.gpkg"
Expand Down
2 changes: 1 addition & 1 deletion tests/test_remote.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ def test_clone(
print("git config file:", r.decode("utf-8").splitlines())

repo = KartRepo(repo_path)
assert not repo.is_empty
assert not repo.head_is_unborn
assert repo.head.name == f"refs/heads/{branch_name}"

if branch_ref == "HEAD^":
Expand Down
8 changes: 4 additions & 4 deletions tests/test_structure.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,12 +175,12 @@ def _benchmark_reset(*args, **kwargs):
assert r.exit_code == 0, r

repo = KartRepo(repo_path)
assert repo.is_empty
assert repo.head_is_unborn

r = cli_runner.invoke(["import", str(data / source_gpkg), table])
assert r.exit_code == 0, r

assert not repo.is_empty
assert not repo.head_is_unborn
assert repo.head.name == "refs/heads/main"
assert repo.head.shorthand == "main"

Expand Down Expand Up @@ -889,7 +889,7 @@ def test_import_multiple(data_archive, chdir, cli_runner, tmp_path):
assert r.exit_code == 0, r

repo = KartRepo(repo_path)
assert repo.is_empty
assert repo.head_is_unborn

LAYERS = (
("gpkg-points", "nz-pa-points-topo-150k.gpkg", H.POINTS.LAYER),
Expand Down Expand Up @@ -1033,7 +1033,7 @@ def test_fast_import(data_archive, tmp_path, cli_runner, chdir):

fast_import.fast_import_tables(repo, [source], from_commit=None)

assert not repo.is_empty
assert not repo.head_is_unborn
assert repo.head.name == "refs/heads/main"
assert repo.head.shorthand == "main"

Expand Down
2 changes: 1 addition & 1 deletion tests/test_working_copy_postgis.py
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ def test_postgis_wc_with_long_index_name(

repo = KartRepo(repo_path)
assert not repo.is_bare
assert not repo.is_empty
assert not repo.head_is_unborn

table_wc = repo.working_copy.tabular
insp = inspect(table_wc.engine)
Expand Down

0 comments on commit ec3e010

Please sign in to comment.