Skip to content

Report actual attempted Git command when Git.refresh fails #1812

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

Merged
merged 10 commits into from
Jan 26, 2024
Prev Previous commit
Next Next commit
Condense FetchInfo.refresh using contextlib.suppress
I think this refactoring slightly improves readability.

+ Condense/sort/group imports (while adding contextlib import).

+ Minor style tweaks in FetchInfo.refresh comments.

+ Make a comment in Git.refresh clearer, building on revisions in:
  #1810 (comment)
  • Loading branch information
EliahKagan committed Jan 25, 2024
commit 3bb63f3766605a597fa1dbca2367cb6ffda4a3ba
2 changes: 1 addition & 1 deletion git/cmd.py
Original file line number Diff line number Diff line change
Expand Up @@ -478,7 +478,7 @@ def refresh(cls, path: Union[None, PathLike] = None) -> bool:
# We get here if this was the initial refresh and the refresh mode was
# not error. Go ahead and set the GIT_PYTHON_GIT_EXECUTABLE such that we
# discern the difference between the first refresh at import time
# and subsequent calls to refresh().
# and subsequent calls to git.refresh or this refresh method.
cls.GIT_PYTHON_GIT_EXECUTABLE = cls.git_exec_name
else:
# After the first refresh (when GIT_PYTHON_GIT_EXECUTABLE is no longer
Expand Down
33 changes: 11 additions & 22 deletions git/remote.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,30 +5,24 @@

"""Module implementing a remote object allowing easy access to git remotes."""

import contextlib
import logging
import re

from git.cmd import handle_process_output, Git
from git.cmd import Git, handle_process_output
from git.compat import defenc, force_text
from git.config import GitConfigParser, SectionConstraint, cp
from git.exc import GitCommandError
from git.refs import Head, Reference, RemoteReference, SymbolicReference, TagReference
from git.util import (
LazyMixin,
IterableObj,
CallableRemoteProgress,
IterableList,
IterableObj,
LazyMixin,
RemoteProgress,
CallableRemoteProgress,
)
from git.util import (
join_path,
)

from git.config import (
GitConfigParser,
SectionConstraint,
cp,
)
from git.refs import Head, Reference, RemoteReference, SymbolicReference, TagReference

# typing-------------------------------------------------------

from typing import (
Expand Down Expand Up @@ -345,18 +339,13 @@ class FetchInfo(IterableObj):
@classmethod
def refresh(cls) -> Literal[True]:
"""This gets called by the refresh function (see the top level __init__)."""
# clear the old values in _flag_map
try:
# Clear the old values in _flag_map.
with contextlib.suppress(KeyError):
del cls._flag_map["t"]
except KeyError:
pass

try:
with contextlib.suppress(KeyError):
del cls._flag_map["-"]
except KeyError:
pass

# set the value given the git version
# Set the value given the git version.
if Git().version_info[:2] >= (2, 10):
cls._flag_map["t"] = cls.TAG_UPDATE
else:
Expand Down