Skip to content

Commit

Permalink
Merge pull request #6859 from mih/master
Browse files Browse the repository at this point in the history
Merge `maint`, resolving conflicts between typechange-related PRs
  • Loading branch information
yarikoptic committed Jul 20, 2022
2 parents afc2ecf + 399688c commit 4f7735f
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 1 deletion.
11 changes: 11 additions & 0 deletions datalad/support/gitrepo.py
Original file line number Diff line number Diff line change
Expand Up @@ -3705,6 +3705,17 @@ def _get_save_status_state(status):
if state == 'clean':
# we don't care about clean
continue
if state == 'modified' and props.get('gitshasum') \
and props.get('gitshasum') == props.get('prev_gitshasum'):
# reported as modified, but with identical shasums -> typechange
# a subdataset maybe? do increasingly expensive tests for
# speed reasons
if props.get('type') != 'dataset' and f.is_dir() \
and GitRepo.is_valid_repo(f):
# it was not a dataset, but now there is one.
# we declare it untracked to engage the discovery tooling.
state = 'untracked'
props = dict(type='dataset', state='untracked')
status_state[state][f] = props
# The hybrid one to retain the same order as in original status
if state in ('modified', 'untracked'):
Expand Down
51 changes: 50 additions & 1 deletion datalad/support/tests/test_repo_save.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
# ## ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ##
"""Test saveds function"""

import shutil

from datalad.api import create
from datalad.distribution.dataset import Dataset
Expand All @@ -25,7 +26,10 @@
slow,
with_tempfile,
)
from datalad.utils import rmtree
from datalad.utils import (
on_windows,
rmtree,
)


@with_tempfile
Expand Down Expand Up @@ -81,6 +85,51 @@ def test_annexrepo_save_all(path=None):
_test_save_all(path, AnnexRepo)


@with_tempfile
def test_save_typechange(path=None):
ckwa = dict(result_renderer='disabled')
ds = Dataset(path).create(**ckwa)
foo = ds.pathobj / 'foo'
# save a file
foo.write_text('some')
ds.save(**ckwa)
# now delete the file and replace with a directory and a file in it
foo.unlink()
foo.mkdir()
bar = foo / 'bar'
bar.write_text('foobar')
res = ds.save(**ckwa)
assert_in_results(res, path=str(bar), action='add', status='ok')
assert_repo_status(ds.repo)
if not on_windows:
# now replace file with subdataset
# (this is https://github.com/datalad/datalad/issues/5418)
bar.unlink()
Dataset(ds.pathobj / 'tmp').create(**ckwa)
shutil.move(ds.pathobj / 'tmp', bar)
res = ds.save(**ckwa)
assert_repo_status(ds.repo)
assert len(ds.subdatasets(**ckwa)) == 1
# now replace directory with subdataset
rmtree(foo)
Dataset(ds.pathobj / 'tmp').create(**ckwa)
shutil.move(ds.pathobj / 'tmp', foo)
# right now a first save() will save the subdataset removal only
ds.save(**ckwa)
# subdataset is gone
assert len(ds.subdatasets(**ckwa)) == 0
# but it takes a second save() run to get a valid status report
# to understand that there is a new subdataset on a higher level
ds.save(**ckwa)
assert_repo_status(ds.repo)
assert len(ds.subdatasets(**ckwa)) == 1
# now replace subdataset with a file
rmtree(foo)
foo.write_text('some')
ds.save(**ckwa)
assert_repo_status(ds.repo)


@with_tempfile
def test_save_to_git(path=None):
ds = Dataset(path).create(result_renderer='disabled')
Expand Down

0 comments on commit 4f7735f

Please sign in to comment.