Skip to content

Commit

Permalink
Merge pull request #6790 from mih/bf-6547
Browse files Browse the repository at this point in the history
Make sure a subdataset is saved with a complete .gitmodules record
  • Loading branch information
yarikoptic committed Jul 5, 2022
2 parents 6039593 + 2c1d4ab commit 935f4b1
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 6 deletions.
12 changes: 7 additions & 5 deletions datalad/core/local/save.py
Original file line number Diff line number Diff line change
Expand Up @@ -279,14 +279,16 @@ def __call__(path=None,
sub_status = superds_status.get(subds_path, {})
if not (sub_status.get("state") == "clean" and
sub_status.get("type") == "dataset"):
# TODO actually start from an entry that may already
# exist in the status record
superds_status[subds_path] = dict(
# start from an entry that may already exist in the
# status record
superds_status[subds_path] = superds_status.get(
subds_path,
# if we got nothing yet:
# shot from the hip, some status config
# to trigger this specific super/sub
# relation to be saved
state='untracked',
type='dataset')
dict(state='untracked', type='dataset')
)
paths_by_ds[superds] = superds_status

def save_ds(args, version_tag=None):
Expand Down
14 changes: 14 additions & 0 deletions datalad/core/local/tests/test_save.py
Original file line number Diff line number Diff line change
Expand Up @@ -1092,3 +1092,17 @@ def test_save_amend(dspath=None):
)
assert_not_in(last_sha, ds.repo.get_branch_commits_(branch))
eq_(ds.repo.format_commit("%B", branch).strip(), "new initial commit")


@with_tempfile
def test_save_sub_trailing_sep_bf6547(path=None):
ds = Dataset(path).create()
# create not-yet-subdataset inside
subds = Dataset(ds.pathobj / 'sub').create()
ds.save(path='sub' + os.path.sep)
assert_in_results(
ds.subdatasets(result_renderer='disabled'),
path=subds.path,
)
# make sure it has the .gitmodules record
assert 'sub' in (ds.pathobj / '.gitmodules').read_text()
3 changes: 2 additions & 1 deletion datalad/support/gitrepo.py
Original file line number Diff line number Diff line change
Expand Up @@ -3656,7 +3656,8 @@ def _save_add_submodules(self, paths):
# a subdataset
# TODO: we could update the URL, and branch info at this point,
# even for previously registered subdatasets
if i['type'] != 'dataset':
if i['type'] != 'dataset' or (
i['type'] == 'dataset' and i['state'] == 'untracked'):
gmprops = dict(path=i['rpath'], url=i['url'])
if i['id']:
gmprops['datalad-id'] = i['id']
Expand Down

0 comments on commit 935f4b1

Please sign in to comment.