Skip to content

Commit

Permalink
Merge pull request #556 from koordinates/issue-555
Browse files Browse the repository at this point in the history
Fix for #555 - issues with merge + shallow clones
  • Loading branch information
olsen232 committed Feb 17, 2022
2 parents 6266126 + c1cf5de commit 6178e0e
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ Support for spatial filters - the spatial filter can be updated during an `init`
* Bugfix: better error message when `kart import` fails due to multiple XML metadata files for a single dataset, which Kart does not support [#547](https://github.com/koordinates/kart/issues/547)
* When there are two pieces of XML metadata for a single dataset, but one is simply a `GDALMultiDomainMetadata` wrapping the other, the wrapped version is ignored. [#547](https://github.com/koordinates/kart/issues/547)
* Bugfix: fixed a bug preventing `checkout -b NEW_BRANCH HEAD^` and similar commands from working
* Bugfix: fixed a bug where `kart merge` would fail in a shallow clone, in certain circumstances. [#555](https://github.com/koordinates/kart/issues/555)

## 0.10.8

Expand Down
12 changes: 12 additions & 0 deletions kart/repo.py
Original file line number Diff line number Diff line change
Expand Up @@ -780,6 +780,18 @@ def revparse_ext(self, revision):
revision = "HEAD"
return super().revparse_ext(revision)

def merge_base(self, oid1, oid2):
# FIXME: Overridden to work around https://github.com/koordinates/kart/issues/555
# Caused by https://github.com/libgit2/libgit2/issues/6123
try:
args = ["git", "-C", self.path, "merge-base", str(oid1), str(oid2)]
output = subprocess.check_output(
args, encoding="utf8", env=tool_environment()
)
return pygit2.Oid(hex=output.strip())
except subprocess.CalledProcessError:
return None

KART_COMMON_README = [
"",
"kart status",
Expand Down
25 changes: 25 additions & 0 deletions tests/test_merge.py
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,31 @@ def test_merge_true(
assert rowcount == num_inserts


def test_merge_shallow_clone(data_archive, tmp_path, cli_runner):
with data_archive("points") as repo1_path:
repo1_url = f"file://{repo1_path.resolve()}"
repo2_path = tmp_path / "repo2"

# Clone only 1 commit from repo with more than one commit:
r = cli_runner.invoke(["clone", repo1_url, repo2_path, "--depth=1"])
assert r.exit_code == 0, r.stderr

# Make a simple commit with that one commit as a parent.
r = cli_runner.invoke(["-C", repo2_path, "commit-files", "-m", "A1", "a=1"])
assert r.exit_code == 0, r.stderr

r = cli_runner.invoke(["-C", repo2_path, "checkout", "HEAD^"])
assert r.exit_code == 0, r.stderr

# Make another simple commit that clearly doesn't conflict, with the same parent.
r = cli_runner.invoke(["-C", repo2_path, "commit-files", "-m", "B2", "b=2"])
assert r.exit_code == 0, r.stderr

# Merge them together.
r = cli_runner.invoke(["-C", repo2_path, "merge", "main", "-m", "merged"])
assert r.exit_code == 0, r.stderr


@pytest.mark.parametrize(
"data",
[
Expand Down

0 comments on commit 6178e0e

Please sign in to comment.