Skip to content

Commit

Permalink
Merge pull request #6795 from mih/bf-4967-again
Browse files Browse the repository at this point in the history
Fix broken annex symlink after git-mv before saving
  • Loading branch information
bpoldrack committed Jul 6, 2022
2 parents 8b4f05b + bb02d64 commit dd6e795
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
13 changes: 13 additions & 0 deletions datalad/core/local/tests/test_save.py
Original file line number Diff line number Diff line change
Expand Up @@ -949,6 +949,19 @@ def test_save_diff_ignore_submodules_config(path=None):
assert_repo_status(ds.path)


@with_tree({"subdir": {"foo": "foocontent"}})
def test_save_git_mv_fixup(path=None):
ds = Dataset(path).create(force=True)
ds.save()
assert_repo_status(ds.path)
ds.repo.call_git(["mv", op.join("subdir", "foo"), "foo"])
ds.save()
# Was link adjusted properly? (gh-3686)
assert (ds.pathobj / 'foo').read_text() == "foocontent"
# all clean
assert_repo_status(ds.path)


@with_tree(tree={'somefile': 'file content',
'subds': {'file_in_sub': 'other'}})
def test_save_amend(dspath=None):
Expand Down
17 changes: 16 additions & 1 deletion datalad/support/gitrepo.py
Original file line number Diff line number Diff line change
Expand Up @@ -3342,7 +3342,22 @@ def save_(self, message=None, paths=None, _status=None, **kwargs):
# - commit (with all paths that have been touched, to bypass
# potential pre-staged bits)

need_partial_commit = True if self.get_staged_paths() else False
staged_paths = self.get_staged_paths()
need_partial_commit = bool(staged_paths)
if need_partial_commit and hasattr(self, "call_annex"):
# so we have some staged content. let's check which ones
# are symlinks -- those could be annex key links that
# are broken after a `git-mv` operation
# https://github.com/datalad/datalad/issues/4967
# call `git-annex pre-commit` on them to rectify this before
# saving the wrong symlinks
added = status_state['added']
tofix = [
sp for sp in staged_paths
if added.get(self.pathobj / sp, {}).get("type") == "symlink"
]
if tofix:
self.call_annex(['pre-commit'], files=tofix)

# remove first, because removal of a subds would cause a
# modification of .gitmodules to be added to the todo list
Expand Down

0 comments on commit dd6e795

Please sign in to comment.