Skip to content

Commit fd197ad

Browse files
committed
fix(iter_gitstatus): support newly added submodules
This are new containers. The previous implementation only expected modification of containers, not new submodule container directly, and crashed. This change adds support for this case and a test that verifies it.
1 parent 51a4d91 commit fd197ad

File tree

2 files changed

+20
-2
lines changed

2 files changed

+20
-2
lines changed

datalad_next/iter_collections/gitstatus.py

+5-2
Original file line numberDiff line numberDiff line change
@@ -364,8 +364,11 @@ def _yield_hierarchy_items(
364364
# repository, hence no submodule item is emitted
365365
sm_head = item.gitsha or item.prev_gitsha
366366

367-
if GitContainerModificationType.new_commits in item.modification_types:
368-
# this is a submodule that has new commits compared to
367+
if item.modification_types is None \
368+
or GitContainerModificationType.new_commits \
369+
in item.modification_types:
370+
# this is a submodule that is either entriely new (added),
371+
# or it has new commits compared to
369372
# its state in the parent dataset. We need to yield this
370373
# item, even if nothing else is modified, because otherwise
371374
# this (unsafed) changed would go unnoticed

datalad_next/iter_collections/tests/test_itergitstatus.py

+15
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from itertools import chain
22
import pytest
33

4+
from datalad_next.datasets import Dataset
45
from datalad_next.runners import (
56
call_git_success,
67
)
@@ -254,3 +255,17 @@ def test_status_nohead_staged(tmp_path):
254255
{i.name: i for i in iter_gitstatus(tmp_path)},
255256
[{'name': 'probe', 'status': GitDiffStatus.addition}],
256257
)
258+
259+
260+
def test_status_submodule_added(existing_dataset, no_result_rendering):
261+
p = existing_dataset.pathobj
262+
subm_name = 'sub'
263+
Dataset(p / subm_name).create()
264+
assert call_git_success(
265+
['submodule', '--quiet', 'add', f'./{subm_name}', subm_name],
266+
cwd=p)
267+
# check that we get the status on a submodule that was just added with
268+
# no additional changes
269+
res = list(iter_gitstatus(p, recursive='monolithic'))
270+
assert any(i.name == subm_name and i.gitsha and i.prev_gitsha is None
271+
for i in res)

0 commit comments

Comments
 (0)