Skip to content

Git.refresh warns to stdout and does not log #1808

Closed
@EliahKagan

Description

@EliahKagan

Warning messages are most often written to standard error. Furthermore, warnings from GitPython, when they are displayed, are in most cases displayed that way unless the caller arranges otherwise, because they are displayed by calling loggers' warning methods or, for DeprecationWarnings, by calling warnings.warn.

However, the warning Git.refresh displays when running a test command like git --version (with the command being tested used for git) fails, and GIT_PYTHON_REFRESH is set to 1, w, warn, or warning, is different. It is printed to standard output. It also does not use any logging facility, so attempts to capture it by configuring Python logging will not succeed.

GitPython/git/cmd.py

Lines 453 to 454 in d28c20b

if mode in warn:
print("WARNING: %s" % err)

If there is a reason for this behavior, then I think it should be commented or otherwise stated. Otherwise, I am not sure what to do. It may still not be feasible to change, because programs that use GitPython may be relying on the warning being printed to standard output, or on it not being printed to standard error. But if he behavior is going to change in the next major version, then that could be commented and/or this issue could be kept open until then. If the reason is unknown and it is undecided whether the behavior should be changed in the next major release, then a comment could be added just saying that it prints to standard output for backward compatibility.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions