Skip to content

Commit

Permalink
Merge pull request datalad#7431 from adswa/git-version
Browse files Browse the repository at this point in the history
Increase minimal Git version to 2.25
  • Loading branch information
yarikoptic authored Jul 17, 2023
2 parents 3665940 + 11cbdbc commit d20bc40
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 59 deletions.
3 changes: 3 additions & 0 deletions changelog.d/pr-7431.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
### 🚀 Enhancements and New Features

- Increase minimal Git version to 2.25. Fixes [#7389](https://github.com/datalad/datalad/issues/7389) via [PR #7431](https://github.com/datalad/datalad/pull/7431) (by [@adswa](https://github.com/adswa))
9 changes: 3 additions & 6 deletions datalad/core/local/tests/test_diff.py
Original file line number Diff line number Diff line change
Expand Up @@ -373,12 +373,9 @@ def test_path_diff(_path=None, linkpath=None):
eq_(plain_recursive, ds.diff(path=['.', '.'], recursive=True, annex='all',
result_renderer='disabled'))
# neither do nested paths
if not "2.24.0" <= ds.repo.git_version < "2.25.0":
# Release 2.24.0 contained a regression that was fixed with 072a231016
# (2019-12-10).
eq_(plain_recursive,
ds.diff(path=['.', 'subds_modified'], recursive=True, annex='all',
result_renderer='disabled'))
eq_(plain_recursive,
ds.diff(path=['.', 'subds_modified'], recursive=True, annex='all',
result_renderer='disabled'))
# when invoked in a subdir of a dataset it still reports on the full thing
# just like `git status`, as long as there are no paths specified
with chpwd(op.join(path, 'directory_untracked')):
Expand Down
35 changes: 10 additions & 25 deletions datalad/core/local/tests/test_save.py
Original file line number Diff line number Diff line change
Expand Up @@ -800,12 +800,9 @@ def test_surprise_subds(path=None):
# If subrepo is an adjusted branch, it would have a commit, making most of
# this test irrelevant because it is about the unborn branch edge case.
adjusted = somerepo.is_managed_branch()
# This edge case goes away with Git v2.22.0.
fixed_git = somerepo.git_version >= '2.22.0'

# save non-recursive
res = ds.save(recursive=False, on_failure='ignore')
if not adjusted and fixed_git:
if not adjusted:
# We get an appropriate error about no commit being checked out.
assert_in_results(res, action='add_submodule', status='error')

Expand All @@ -814,30 +811,18 @@ def test_surprise_subds(path=None):
assert_repo_status(subds.path, untracked=['subfile'])
assert_repo_status(somerepo.path, untracked=['subfile'])

if adjusted or fixed_git:
if adjusted:
# adjusted branch: #datalad/3178 (that would have a commit)
modified = [subds.repo.pathobj, somerepo.pathobj]
untracked = []
else:
# Newer Git versions refuse to add a sub-repository with no commits
# checked out.
modified = [subds.repo.pathobj]
untracked = ['d1']
if adjusted:
# adjusted branch: #datalad/3178 (that would have a commit)
modified = [subds.repo.pathobj, somerepo.pathobj]
untracked = []
else:
# Newer Git versions refuse to add a sub-repository with no commits
# checked out.
modified = [subds.repo.pathobj]
untracked = ['d1']
assert_repo_status(ds.path, modified=modified, untracked=untracked)
assert_not_in(ds.repo.pathobj / 'd1' / 'subrepo' / 'subfile',
ds.repo.get_content_info())
else:
# however, while the subdataset is added (and reported as modified
# because it content is still untracked) the subrepo
# cannot be added (it has no commit)
# worse: its untracked file add been added to the superdataset
assert_repo_status(ds.path, modified=['d2/subds'])
assert_in(ds.repo.pathobj / 'd1' / 'subrepo' / 'subfile',
ds.repo.get_content_info())
# with proper subdatasets, all evil is gone
assert_not_in(ds.repo.pathobj / 'd2' / 'subds' / 'subfile',
ds.repo.get_content_info())


@with_tree({"foo": ""})
Expand Down
31 changes: 3 additions & 28 deletions datalad/support/gitrepo.py
Original file line number Diff line number Diff line change
Expand Up @@ -388,25 +388,8 @@ def remap_filenames(out):

return _wrap_normalize_paths


if "2.24.0" <= external_versions["cmd:git"] < "2.25.0":
# An unintentional change in Git 2.24.0 led to `ls-files -o` traversing
# into untracked submodules when multiple pathspecs are given, returning
# repositories that are deeper than the first level. This helper filters
# these deeper levels out so that save_() doesn't fail trying to add them.
#
# This regression fixed with upstream's 072a231016 (2019-12-10).
def _prune_deeper_repos(repos: list[Path]) -> list[Path]:
firstlevel_repos = []
prev = None
for repo in sorted(repos):
if not (prev and str(repo).startswith(prev)):
prev = str(repo)
firstlevel_repos.append(repo)
return firstlevel_repos
else:
def _prune_deeper_repos(repos: list[Path]) -> list[Path]:
return repos
def _prune_deeper_repos(repos: list[Path]) -> list[Path]:
return repos


class GitProgress(WitlessProtocol):
Expand Down Expand Up @@ -834,7 +817,7 @@ class GitRepo(CoreGitRepo):
# should do it once
_config_checked = False

GIT_MIN_VERSION = "2.19.1"
GIT_MIN_VERSION = "2.25"
git_version = None

@classmethod
Expand Down Expand Up @@ -2949,14 +2932,6 @@ def _get_content_info_line_helper(self, ref: Optional[str], info: dict[Path, dic
inf: dict[str, str | int | None] = {}
props = props_re.match(line)
if not props:
# Kludge: Filter out paths starting with .git/ to work around
# an `ls-files -o` bug that was fixed in Git 2.25.
#
# TODO: Drop this condition when GIT_MIN_VERSION is at least
# 2.25.
if line.startswith(".git/"):
lgr.debug("Filtering out .git/ file: %s", line)
continue
# not known to Git, but Git always reports POSIX
path = ut.PurePosixPath(line)
inf['gitshasum'] = None
Expand Down

0 comments on commit d20bc40

Please sign in to comment.