git: implement dulwich add --update (#5491)

* dulwich: implement add with --update

* add git backend test for add()

* fix list comprehension in dulwich status()

* allow adding single string path instead of list

* handle windows paths in add(update=...)
This commit is contained in:
Peter Rowlands (변기호)
2021-02-18 17:56:56 +09:00
committed by GitHub
parent 45477a2a81
commit 9909ee85a1
5 changed files with 76 additions and 18 deletions
+4 -2
View File
@@ -3,7 +3,7 @@ import locale
import logging
import os
from functools import partial
from typing import Callable, Iterable, List, Mapping, Optional, Tuple
from typing import Callable, Iterable, List, Mapping, Optional, Tuple, Union
from funcy import first, ignore
@@ -188,11 +188,13 @@ class GitPythonBackend(BaseGitBackend): # pylint:disable=abstract-method
def dir(self) -> str:
return self.repo.git_dir
def add(self, paths: Iterable[str], update=False):
def add(self, paths: Union[str, Iterable[str]], update=False):
# NOTE: GitPython is not currently able to handle index version >= 3.
# See https://github.com/iterative/dvc/issues/610 for more details.
try:
if update:
if isinstance(paths, str):
paths = [paths]
self.git.add(*paths, update=True)
else:
self.repo.index.add(paths)