Skip to content

Commit

Permalink
Merge pull request #3702 from mih/rf-obsolete
Browse files Browse the repository at this point in the history
Remove obsolete code, trim deps on GitPy
  • Loading branch information
mih committed Sep 24, 2019
2 parents cb23629 + c97d103 commit 0050f09
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 57 deletions.
64 changes: 14 additions & 50 deletions datalad/support/gitrepo.py
Expand Up @@ -1110,16 +1110,6 @@ def get_toppath(cls, path, follow_up=True, git_options=None):

return toppath

# classmethod so behavior could be tuned in derived classes
@classmethod
def _get_added_files_commit_msg(cls, files):
if not files:
return "No files were added"
msg = "Added %d file" % len(files)
if len(files) > 1:
msg += "s"
return msg + '\n\nFiles:\n' + '\n'.join(files)

@normalize_paths
def add(self, files, git=True, git_options=None, update=False):
"""Adds file(s) to the repository.
Expand Down Expand Up @@ -1427,6 +1417,8 @@ def commit(self, msg=None, options=None, _datalad_msg=False, careless=True,
else:
raise

# TODO usage is primarily in the tests, consider making a test helper and
# remove from GitRepo API
def get_indexed_files(self):
"""Get a list of files in git's index
Expand All @@ -1436,8 +1428,11 @@ def get_indexed_files(self):
list of paths rooting in git's base dir
"""

return [x[0] for x in self.cmd_call_wrapper(
self.repo.index.entries.keys)]
return [
str(r.relative_to(self.pathobj))
for r in self.get_content_info(
paths=None, ref=None, untracked='no', eval_file_type=False)
]

def format_commit(self, fmt, commitish=None):
"""Return `git show` output for `commitish`.
Expand Down Expand Up @@ -1730,6 +1725,8 @@ def get_remotes(self, with_urls_only=False):
]
return remotes

# TODO this is practically unused outside the tests, consider turning
# into a test helper and trim from the API
def get_files(self, branch=None):
"""Get a list of files in git.
Expand All @@ -1745,14 +1742,11 @@ def get_files(self, branch=None):
[str]
list of files.
"""
# TODO: RF codes base and melt get_indexed_files() in

if branch is None:
# active branch can be queried way faster:
return self.get_indexed_files()
else:
return [item.path for item in self.repo.tree(branch).traverse()
if isinstance(item, Blob)]
return [
str(p.relative_to(self.pathobj))
for p in self.get_content_info(
paths=None, ref=branch, untracked='no', eval_file_type=False)
]

def get_file_content(self, file_, branch='HEAD'):
"""
Expand Down Expand Up @@ -2468,36 +2462,6 @@ def key(x):
xs = sorted(xs, key=key)
return list(xs)

def is_submodule_modified(self, name, options=[]):
"""Whether a submodule has new commits
Note: This is an adhoc method. It parses output of
'git submodule summary' and currently is not able to distinguish whether
or not this change is staged in `self` and whether this would be
reported 'added' or 'modified' by 'git status'.
Parsing isn't heavily tested yet.
Parameters
----------
name: str
the submodule's name
options: list
options to pass to 'git submodule summary'
Returns
-------
bool
True if there are commits in the submodule, differing from
what is registered in `self`
--------
"""

out, err = self._git_custom_command('',
['git', 'submodule', 'summary'] + \
options + ['--', name])
return any([line.split()[1] == name
for line in out.splitlines()
if line and len(line.split()) > 1])

def add_submodule(self, path, name=None, url=None, branch=None):
"""Add a new submodule to the repository.
Expand Down
7 changes: 0 additions & 7 deletions datalad/support/tests/test_gitrepo.py
Expand Up @@ -952,13 +952,6 @@ def test_split_remote_branch():
assert_raises(AssertionError, split_remote_branch, "TrailingSlash/")


def test_get_added_files_commit_msg():
f = GitRepo._get_added_files_commit_msg
eq_(f([]), 'No files were added')
eq_(f(["f1"]), 'Added 1 file\n\nFiles:\nf1')
eq_(f(["f1", "f2"]), 'Added 2 files\n\nFiles:\nf1\nf2')


@with_testrepos(flavors=['local'])
@with_tempfile(mkdir=True)
def test_get_tracking_branch(o_path, c_path):
Expand Down

0 comments on commit 0050f09

Please sign in to comment.