Skip to content

allow calling index.add, index.move and index.remove with single items #840

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion git/index/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -569,6 +569,11 @@ def _preprocess_add_items(self, items):
""" Split the items into two lists of path strings and BaseEntries. """
paths = []
entries = []
# check if is iterable, else put in list
try:
test_item = iter(items)
except TypeError:
items = [items]

for item in items:
if isinstance(item, string_types):
Expand All @@ -580,7 +585,7 @@ def _preprocess_add_items(self, items):
else:
raise TypeError("Invalid Type: %r" % item)
# END for each item
return (paths, entries)
return paths, entries

def _store_path(self, filepath, fprogress):
"""Store file at filepath in the database and return the base index entry
Expand Down Expand Up @@ -801,6 +806,12 @@ def _items_to_rela_paths(self, items):
"""Returns a list of repo-relative paths from the given items which
may be absolute or relative paths, entries or blobs"""
paths = []
# check if is iterable, else put in list
try:
test_item = iter(items)
except TypeError:
items = [items]

for item in items:
if isinstance(item, (BaseIndexEntry, (Blob, Submodule))):
paths.append(self._to_relative_path(item.path))
Expand Down
9 changes: 8 additions & 1 deletion git/test/test_index.py
Original file line number Diff line number Diff line change
Expand Up @@ -772,7 +772,14 @@ def test_compare_write_tree(self, rw_repo):
orig_tree = commit.tree
self.assertEqual(index.write_tree(), orig_tree)
# END for each commit


@with_rw_repo('HEAD', bare=False)
def test_index_single_addremove(self, rw_repo):
path = osp.join('git', 'test', 'test_index.py')
self._assert_entries(rw_repo.index.add(path))
deleted_files = rw_repo.index.remove(path)
assert deleted_files

def test_index_new(self):
B = self.rorepo.tree("6d9b1f4f9fa8c9f030e3207e7deacc5d5f8bba4e")
H = self.rorepo.tree("25dca42bac17d511b7e2ebdd9d1d679e7626db5f")
Expand Down