Skip to content

Commit

Permalink
TST: annexrepo: Update test for "no commits" sub-repo fix in Git
Browse files Browse the repository at this point in the history
As of Git 2.22.0, specifically b22827045e (dir: do not traverse
repositories with no commits, 2019-04-09), 'git ls-files' now treats a
repository on an unborn branch as a repository rather than a
directory.

Fixes #3490.
  • Loading branch information
kyleam committed Jun 28, 2019
1 parent fb8825f commit f2c8f7f
Showing 1 changed file with 26 additions and 5 deletions.
31 changes: 26 additions & 5 deletions datalad/support/tests/test_annexrepo.py
Original file line number Diff line number Diff line change
Expand Up @@ -1989,27 +1989,48 @@ def sync_wrapper(push=False, pull=False, commit=False):

# create a subrepo:
sub = AnnexRepo(opj(ar.path, 'submod'), create=True)
# nothing changed, it's empty besides .git, which is ignored

# Git v2.22.0 changed the way it treats sub-repositories without a commit
# checked out, so we need to condition the checks on that.
# ATTN: We look at the bundled git rather than "cmd:git" because `git annex
# status` will use it regardless of DATALAD_USE_DEFAULT_GIT.
bundled = external_versions['cmd:bundled-git']
if bundled is external_versions.UNKNOWN:
git_version = external_versions['cmd:git']
else:
git_version = bundled
fixed_git = git_version >= '2.22.0'

if fixed_git:
# Newer Git versions consider a repo without a commit a repository, not
# a directory.
stat["untracked"].append("submod/")
eq_(stat, ar.get_status())

# file in subrepo
with open(opj(ar.path, 'submod', 'fourth'), 'w') as f:
f.write("this is a birth certificate")
stat['untracked'].append(opj('submod', 'fourth'))

if not fixed_git:
# In the fixed case, nothing changes, since the empty repo is still
# seen as a repo.
stat['untracked'].append(opj('submod', 'fourth'))
eq_(stat, ar.get_status())

# add to subrepo
sub.add('fourth')
sub.commit(msg="birther mod init'ed")
stat['untracked'].remove(opj('submod', 'fourth'))
if not fixed_git:
stat['untracked'].remove(opj('submod', 'fourth'))

if ar.get_active_branch().endswith('(unlocked)') and \
'adjusted' in ar.get_active_branch():
# we are running on adjusted branch => do it in submodule, too
sub.adjust()

# Note, that now the non-empty repo is untracked
stat['untracked'].append('submod/')
if not fixed_git:
# Note, that now the non-empty repo is untracked
stat['untracked'].append('submod/')
eq_(stat, ar.get_status())

# add the submodule
Expand Down

0 comments on commit f2c8f7f

Please sign in to comment.