Skip to content
Merged
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
138 changes: 0 additions & 138 deletions .basedpyright/baseline.json
Original file line number Diff line number Diff line change
Expand Up @@ -183,14 +183,6 @@
"lineCount": 1
}
},
{
"code": "reportPossiblyUnboundVariable",
"range": {
"startColumn": 52,
"endColumn": 59,
"lineCount": 1
}
},
{
"code": "reportSelfClsParameterName",
"range": {
Expand All @@ -207,14 +199,6 @@
"lineCount": 1
}
},
{
"code": "reportPossiblyUnboundVariable",
"range": {
"startColumn": 41,
"endColumn": 44,
"lineCount": 1
}
},
{
"code": "reportArgumentType",
"range": {
Expand Down Expand Up @@ -393,14 +377,6 @@
"lineCount": 1
}
},
{
"code": "reportPossiblyUnboundVariable",
"range": {
"startColumn": 19,
"endColumn": 25,
"lineCount": 1
}
},
{
"code": "reportArgumentType",
"range": {
Expand Down Expand Up @@ -467,30 +443,6 @@
"lineCount": 1
}
},
{
"code": "reportPossiblyUnboundVariable",
"range": {
"startColumn": 23,
"endColumn": 34,
"lineCount": 1
}
},
{
"code": "reportPossiblyUnboundVariable",
"range": {
"startColumn": 32,
"endColumn": 43,
"lineCount": 1
}
},
{
"code": "reportPossiblyUnboundVariable",
"range": {
"startColumn": 23,
"endColumn": 34,
"lineCount": 1
}
},
{
"code": "reportArgumentType",
"range": {
Expand All @@ -499,14 +451,6 @@
"lineCount": 1
}
},
{
"code": "reportPossiblyUnboundVariable",
"range": {
"startColumn": 28,
"endColumn": 32,
"lineCount": 1
}
},
{
"code": "reportAttributeAccessIssue",
"range": {
Expand Down Expand Up @@ -588,16 +532,6 @@
}
}
],
"./git/objects/submodule/root.py": [
{
"code": "reportPossiblyUnboundVariable",
"range": {
"startColumn": 18,
"endColumn": 21,
"lineCount": 1
}
}
],
"./git/objects/tag.py": [
{
"code": "reportIncompatibleVariableOverride",
Expand Down Expand Up @@ -701,14 +635,6 @@
"lineCount": 1
}
},
{
"code": "reportPossiblyUnboundVariable",
"range": {
"startColumn": 41,
"endColumn": 45,
"lineCount": 1
}
},
{
"code": "reportArgumentType",
"range": {
Expand Down Expand Up @@ -855,38 +781,6 @@
"lineCount": 1
}
},
{
"code": "reportPossiblyUnboundVariable",
"range": {
"startColumn": 26,
"endColumn": 34,
"lineCount": 1
}
},
{
"code": "reportPossiblyUnboundVariable",
"range": {
"startColumn": 32,
"endColumn": 40,
"lineCount": 1
}
},
{
"code": "reportPossiblyUnboundVariable",
"range": {
"startColumn": 18,
"endColumn": 26,
"lineCount": 1
}
},
{
"code": "reportPossiblyUnboundVariable",
"range": {
"startColumn": 22,
"endColumn": 30,
"lineCount": 1
}
},
{
"code": "reportReturnType",
"range": {
Expand Down Expand Up @@ -967,22 +861,6 @@
"lineCount": 1
}
},
{
"code": "reportPossiblyUnboundVariable",
"range": {
"startColumn": 39,
"endColumn": 47,
"lineCount": 1
}
},
{
"code": "reportPossiblyUnboundVariable",
"range": {
"startColumn": 43,
"endColumn": 51,
"lineCount": 1
}
},
{
"code": "reportArgumentType",
"range": {
Expand All @@ -998,22 +876,6 @@
"endColumn": 38,
"lineCount": 1
}
},
{
"code": "reportPossiblyUnboundVariable",
"range": {
"startColumn": 26,
"endColumn": 42,
"lineCount": 1
}
},
{
"code": "reportPossiblyUnboundVariable",
"range": {
"startColumn": 18,
"endColumn": 34,
"lineCount": 1
}
}
],
"./git/repo/fun.py": [
Expand Down
11 changes: 7 additions & 4 deletions git/index/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -730,14 +730,17 @@ def _entries_for_paths(
) -> List[BaseIndexEntry]:
entries_added: List[BaseIndexEntry] = []
if path_rewriter:
working_tree_dir = self.repo.working_tree_dir
if working_tree_dir is None:
raise InvalidGitRepositoryError("Cannot rewrite paths without a working tree")
working_tree_dir = str(working_tree_dir)
for path in paths:
if osp.isabs(path):
abspath = path
gitrelative_path = path[len(str(self.repo.working_tree_dir)) + 1 :]
gitrelative_path = path[len(working_tree_dir) + 1 :]
else:
gitrelative_path = path
if self.repo.working_tree_dir:
abspath = osp.join(self.repo.working_tree_dir, gitrelative_path)
abspath = osp.join(working_tree_dir, gitrelative_path)
# END obtain relative and absolute paths

blob = Blob(
Expand Down Expand Up @@ -1467,8 +1470,8 @@ def reset(
nie = new_inst.entries
for path in paths:
path = self._to_relative_path(path)
key = entry_key(path, 0)
try:
key = entry_key(path, 0)
self.entries[key] = nie[key]
except KeyError:
# If key is not in theirs, it mustn't be in ours.
Expand Down
7 changes: 5 additions & 2 deletions git/objects/commit.py
Original file line number Diff line number Diff line change
Expand Up @@ -575,11 +575,14 @@ def _iter_from_process_or_stream(cls, repo: "Repo", proc_or_stream: Union[Popen,

if hasattr(proc_or_stream, "wait"):
proc_or_stream = cast(Popen, proc_or_stream)
if proc_or_stream.stdout is not None:
stream = proc_or_stream.stdout
stream = proc_or_stream.stdout
if stream is None:
raise ValueError("Process has no stdout stream")
elif hasattr(proc_or_stream, "readline"):
proc_or_stream = cast(IO, proc_or_stream) # type: ignore[redundant-cast]
stream = proc_or_stream
else:
raise TypeError("Expected a process or stream")

readline = stream.readline
while True:
Expand Down
2 changes: 2 additions & 0 deletions git/objects/submodule/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -877,6 +877,7 @@ def fetch_remotes(module_repo: "Repo") -> None:
#############################
binsha = self.binsha
hexsha = self.hexsha
is_detached = False
if mrepo is not None:
# mrepo is only set if we are not in dry-run mode or if the module
# existed.
Expand Down Expand Up @@ -1221,6 +1222,7 @@ def remove(
for remote in mod.remotes:
num_branches_with_new_commits = 0
rrefs = remote.refs
rref = None
for rref in rrefs:
num_branches_with_new_commits += len(mod.git.cherry(rref)) != 0
# END for each remote ref
Expand Down
5 changes: 3 additions & 2 deletions git/objects/submodule/root.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

import git
from git.exc import InvalidGitRepositoryError
from git.util import IterableList

from .base import Submodule, UpdateProgress
from .util import find_first_remote_branch
Expand All @@ -19,7 +20,6 @@

if TYPE_CHECKING:
from git.repo import Repo
from git.util import IterableList

# ----------------------------------------------------------------------------

Expand Down Expand Up @@ -162,6 +162,7 @@ def update( # type: ignore[override]
prefix = "DRY-RUN: "

repo = self.repo
sms: "IterableList[Submodule]" = IterableList("name")

try:
# SETUP BASE COMMIT
Expand All @@ -182,7 +183,7 @@ def update( # type: ignore[override]
# END handle previous commit

psms: "IterableList[Submodule]" = self.list_items(repo, parent_commit=previous_commit)
sms: "IterableList[Submodule]" = self.list_items(repo)
sms = self.list_items(repo)
spsms = set(psms)
ssms = set(sms)

Expand Down
1 change: 1 addition & 0 deletions git/refs/log.py
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,7 @@ def entry_at(cls, filepath: PathLike, index: int) -> "RefLogEntry":
return RefLogEntry.from_line(fp.readlines()[index].strip())
# Read until index is reached.

line = b""
for i in range(index + 1):
line = fp.readline()
if not line:
Expand Down
18 changes: 12 additions & 6 deletions git/repo/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -933,13 +933,17 @@ def is_valid_object(self, sha: str, object_type: Union[str, None] = None) -> boo
return False

def _get_daemon_export(self) -> bool:
if self.git_dir:
filename = osp.join(self.git_dir, self.DAEMON_EXPORT_FILE)
git_dir = getattr(self, "git_dir", None)
if git_dir is None:
return False
filename = osp.join(git_dir, self.DAEMON_EXPORT_FILE)
return osp.exists(filename)
Comment thread
Byron marked this conversation as resolved.

def _set_daemon_export(self, value: object) -> None:
if self.git_dir:
filename = osp.join(self.git_dir, self.DAEMON_EXPORT_FILE)
git_dir = getattr(self, "git_dir", None)
if git_dir is None:
return
filename = osp.join(git_dir, self.DAEMON_EXPORT_FILE)
fileexists = osp.exists(filename)
if value and not fileexists:
touch(filename)
Expand Down Expand Up @@ -1279,6 +1283,7 @@ class InfoTD(TypedDict, total=False):

keepends = True
for line_bytes in data.splitlines(keepends):
line_str = ""
try:
line_str = line_bytes.rstrip().decode(defenc)
except UnicodeDecodeError:
Expand Down Expand Up @@ -1737,8 +1742,9 @@ def currently_rebasing_on(self) -> Commit | None:

``None`` if we are not currently rebasing.
"""
if self.git_dir:
rebase_head_file = osp.join(self.git_dir, "REBASE_HEAD")
if not self.git_dir:
return None
rebase_head_file = osp.join(self.git_dir, "REBASE_HEAD")
if not osp.isfile(rebase_head_file):
return None
with open(rebase_head_file, "rt") as f:
Expand Down
5 changes: 5 additions & 0 deletions test/test_commit.py
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,11 @@ def test_rev_list_bisect_all(self):
for sha1, commit in zip(expected_ids, commits):
self.assertEqual(sha1, commit.hexsha)

def test_iter_from_invalid_process_or_stream(self):
for source, error in ((Mock(wait=Mock(), stdout=None), ValueError), (object(), TypeError)):
with self.assertRaises(error):
list(Commit._iter_from_process_or_stream(self.rorepo, source))

@with_rw_directory
def test_ambiguous_arg_iteration(self, rw_dir):
rw_repo = Repo.init(osp.join(rw_dir, "test_ambiguous_arg"))
Expand Down
6 changes: 6 additions & 0 deletions test/test_repo.py
Original file line number Diff line number Diff line change
Expand Up @@ -337,6 +337,12 @@ def test_daemon_export(self):
self.rorepo.daemon_export = orig_val
self.assertEqual(self.rorepo.daemon_export, orig_val)

def test_daemon_export_without_git_dir(self):
repo = Repo.__new__(Repo)
repo.git_dir = None
self.assertFalse(repo._get_daemon_export())
repo._set_daemon_export(True)

def test_alternates(self):
cur_alternates = self.rorepo.alternates
try:
Expand Down
3 changes: 3 additions & 0 deletions test/test_submodule.py
Original file line number Diff line number Diff line change
Expand Up @@ -511,6 +511,9 @@ def test_root_module(self, rwrepo):
# Cannot set the parent commit as root module's path didn't exist.
self.assertRaises(ValueError, rm.set_parent_commit, "HEAD")

with mock.patch.object(RootModule, "list_items", side_effect=ValueError("boom")):
rm.update(keep_going=True)

# TEST UPDATE
#############
# Set up a commit that removes existing, adds new and modifies existing
Expand Down
Loading