Codebase list python-git / 3fe3072c-2a76-4b22-a86f-ee134c8e36f1/upstream
Import upstream version 3.1.27 Debian Janitor 2 years ago
22 changed file(s) with 175 addition(s) and 53 deletion(s). Raw diff Collapse all Expand all
4343 -Ram Rachum <ram _at_ rachum.com>
4444 -Alba Mendez <me _at_ alba.sh>
4545 -Robert Westman <robert _at_ byteflux.io>
46 -Hugo van Kemenade
4647 Portions derived from other open source works and are clearly marked.
00 Metadata-Version: 2.1
11 Name: GitPython
2 Version: 3.1.24
2 Version: 3.1.27
33 Summary: GitPython is a python library used to interact with Git repositories
44 Home-page: https://github.com/gitpython-developers/GitPython
55 Author: Sebastian Thiel, Michael Trier
66 Author-email: byronimo@gmail.com, mtrier@gmail.com
77 License: BSD
8 Description: GitPython is a python library used to interact with Git repositories
98 Platform: UNKNOWN
109 Classifier: Development Status :: 5 - Production/Stable
1110 Classifier: Environment :: Console
2120 Classifier: Programming Language :: Python :: 3.7
2221 Classifier: Programming Language :: Python :: 3.8
2322 Classifier: Programming Language :: Python :: 3.9
23 Classifier: Programming Language :: Python :: 3.10
2424 Requires-Python: >=3.7
2525 Description-Content-Type: text/markdown
26 License-File: LICENSE
27 License-File: AUTHORS
28
29 GitPython is a python library used to interact with Git repositories
30
00 gitdb<5,>=4.0.1
11
2 [:python_version < "3.10"]
2 [:python_version < "3.8"]
33 typing-extensions>=3.7.4.3
00 Metadata-Version: 2.1
11 Name: GitPython
2 Version: 3.1.24
2 Version: 3.1.27
33 Summary: GitPython is a python library used to interact with Git repositories
44 Home-page: https://github.com/gitpython-developers/GitPython
55 Author: Sebastian Thiel, Michael Trier
66 Author-email: byronimo@gmail.com, mtrier@gmail.com
77 License: BSD
8 Description: GitPython is a python library used to interact with Git repositories
98 Platform: UNKNOWN
109 Classifier: Development Status :: 5 - Production/Stable
1110 Classifier: Environment :: Console
2120 Classifier: Programming Language :: Python :: 3.7
2221 Classifier: Programming Language :: Python :: 3.8
2322 Classifier: Programming Language :: Python :: 3.9
23 Classifier: Programming Language :: Python :: 3.10
2424 Requires-Python: >=3.7
2525 Description-Content-Type: text/markdown
26 License-File: LICENSE
27 License-File: AUTHORS
28
29 GitPython is a python library used to interact with Git repositories
30
0 3.1.24
0 3.1.27
0 sphinx==4.1.2
0 sphinx==4.3.0
11 sphinx_rtd_theme
22 sphinx-autodoc-typehints
00 =========
11 Changelog
22 =========
3
4 3.1.28
5 ======
6
7 - Fix a vulenerability that could cause great slowdowns when encountering long remote path names
8 when pulling/fetching.
9
10 See the following for all changes.
11 https://github.com/gitpython-developers/gitpython/milestone/58?closed=1
12
13 3.1.27
14 ======
15
16 - Reduced startup time due to optimized imports.
17
18 See the following for all changes.
19 https://github.com/gitpython-developers/gitpython/milestone/57?closed=1
20
21 3.1.26
22 ======
23
24 - Fixes a leaked file descriptor when reading the index, which would cause make writing a previously
25 read index on windows impossible.
26 See https://github.com/gitpython-developers/GitPython/issues/1395 for details.
27
28 See the following for all changes.
29 https://github.com/gitpython-developers/gitpython/milestone/56?closed=1
30
31
32 3.1.25
33 ======
34
35 See the following for all changes.
36 https://github.com/gitpython-developers/gitpython/milestone/55?closed=1
337
438
539 3.1.24
77 GitPython Tutorial
88 ==================
99
10 GitPython provides object model access to your git repository. This tutorial is composed of multiple sections, most of which explains a real-life usecase.
11
12 All code presented here originated from `test_docs.py <https://github.com/gitpython-developers/GitPython/blob/main/test/test_docs.py>`_ to assure correctness. Knowing this should also allow you to more easily run the code for your own testing purposes, all you need is a developer installation of git-python.
10 GitPython provides object model access to your git repository. This tutorial is composed of multiple sections, most of which explain a real-life use case.
11
12 All code presented here originated from `test_docs.py <https://github.com/gitpython-developers/GitPython/blob/main/test/test_docs.py>`_ to assure correctness. Knowing this should also allow you to more easily run the code for your own testing purposes. All you need is a developer installation of git-python.
1313
1414 Meet the Repo type
1515 ******************
1313 from typing import Optional
1414 from git.types import PathLike
1515
16 __version__ = '3.1.24'
16 __version__ = '3.1.27'
1717
1818
1919 #{ Initialization
2020 def _init_externals() -> None:
2121 """Initialize external projects by putting them into the path"""
22 if __version__ == '3.1.24' and 'PYOXIDIZER' not in os.environ:
22 if __version__ == '3.1.27' and 'PYOXIDIZER' not in os.environ:
2323 sys.path.insert(1, osp.join(osp.dirname(__file__), 'ext', 'gitdb'))
2424
2525 try:
1111 from subprocess import (
1212 call,
1313 Popen,
14 PIPE
14 PIPE,
15 DEVNULL
1516 )
1617 import subprocess
1718 import threading
872873 env=env,
873874 cwd=cwd,
874875 bufsize=-1,
875 stdin=istream,
876 stdin=istream or DEVNULL,
876877 stderr=PIPE,
877878 stdout=stdout_sink,
878879 shell=shell is not None and shell or self.USE_SHELL,
126126
127127 def _set_cache_(self, attr: str) -> None:
128128 if attr == "entries":
129 # read the current index
130 # try memory map for speed
131 lfd = LockedFD(self._file_path)
132 ok = False
133129 try:
134 fd = lfd.open(write=False, stream=False)
135 ok = True
130 fd = os.open(self._file_path, os.O_RDONLY)
136131 except OSError:
137132 # in new repositories, there may be no index, which means we are empty
138133 self.entries: Dict[Tuple[PathLike, StageType], IndexEntry] = {}
139134 return None
135 # END exception handling
136
137 try:
138 stream = file_contents_ro(fd, stream=True, allow_mmap=True)
140139 finally:
141 if not ok:
142 lfd.rollback()
143 # END exception handling
144
145 stream = file_contents_ro(fd, stream=True, allow_mmap=True)
146
147 try:
148 self._deserialize(stream)
149 finally:
150 lfd.rollback()
151 # The handles will be closed on destruction
152 # END read from default index on demand
140 os.close(fd)
141
142 self._deserialize(stream)
153143 else:
154144 super(IndexFile, self)._set_cache_(attr)
155145
983973 commit_date: Union[str, None] = None,
984974 skip_hooks: bool = False) -> Commit:
985975 """Commit the current default index file, creating a commit object.
986 For more information on the arguments, see tree.commit.
976 For more information on the arguments, see Commit.create_from_tree().
987977
988978 :note: If you have manually altered the .entries member of this instance,
989979 don't forget to write() your changes to disk beforehand.
22 # NOTE: Autodoc hates it if this is a docstring
33
44 from io import BytesIO
5 from pathlib import Path
56 import os
67 from stat import (
78 S_IFDIR,
2021 force_text,
2122 force_bytes,
2223 is_posix,
24 is_win,
2325 safe_decode,
2426 )
2527 from git.exc import (
7375 def hook_path(name: str, git_dir: PathLike) -> str:
7476 """:return: path to the given named hook in the given git repository directory"""
7577 return osp.join(git_dir, 'hooks', name)
78
79
80 def _has_file_extension(path):
81 return osp.splitext(path)[1]
7682
7783
7884 def run_commit_hook(name: str, index: 'IndexFile', *args: str) -> None:
8894 env = os.environ.copy()
8995 env['GIT_INDEX_FILE'] = safe_decode(str(index.path))
9096 env['GIT_EDITOR'] = ':'
97 cmd = [hp]
9198 try:
92 cmd = subprocess.Popen([hp] + list(args),
99 if is_win and not _has_file_extension(hp):
100 # Windows only uses extensions to determine how to open files
101 # (doesn't understand shebangs). Try using bash to run the hook.
102 relative_hp = Path(hp).relative_to(index.repo.working_dir).as_posix()
103 cmd = ["bash.exe", relative_hp]
104
105 cmd = subprocess.Popen(cmd + list(args),
93106 env=env,
94107 stdout=subprocess.PIPE,
95108 stderr=subprocess.PIPE,
33 # This module is part of GitPython and is released under
44 # the BSD License: http://www.opensource.org/licenses/bsd-license.php
55 import datetime
6 from subprocess import Popen
6 from subprocess import Popen, PIPE
77 from gitdb import IStream
88 from git.util import (
99 hex_to_bin,
1212 finalize_process
1313 )
1414 from git.diff import Diffable
15 from git.cmd import Git
1516
1617 from .tree import Tree
1718 from . import base
3839
3940 # typing ------------------------------------------------------------------
4041
41 from typing import Any, IO, Iterator, List, Sequence, Tuple, Union, TYPE_CHECKING, cast
42 from typing import Any, IO, Iterator, List, Sequence, Tuple, Union, TYPE_CHECKING, cast, Dict
4243
4344 from git.types import PathLike, Literal
4445
9798 :param binsha: 20 byte sha1
9899 :param parents: tuple( Commit, ... )
99100 is a tuple of commit ids or actual Commits
100 :param tree: Tree
101 Tree object
101 :param tree: Tree object
102102 :param author: Actor
103103 is the author Actor object
104104 :param authored_date: int_seconds_since_epoch
314314 text = self.repo.git.diff(self.parents[0].hexsha, self.hexsha, '--', numstat=True)
315315 return Stats._list_from_string(self.repo, text)
316316
317 @property
318 def trailers(self) -> Dict:
319 """Get the trailers of the message as dictionary
320
321 Git messages can contain trailer information that are similar to RFC 822
322 e-mail headers (see: https://git-scm.com/docs/git-interpret-trailers).
323
324 This funcions calls ``git interpret-trailers --parse`` onto the message
325 to extract the trailer information. The key value pairs are stripped of
326 leading and trailing whitespaces before they get saved into a dictionary.
327
328 Valid message with trailer:
329
330 .. code-block::
331
332 Subject line
333
334 some body information
335
336 another information
337
338 key1: value1
339 key2 : value 2 with inner spaces
340
341 dictionary will look like this:
342
343 .. code-block::
344
345 {
346 "key1": "value1",
347 "key2": "value 2 with inner spaces"
348 }
349
350 :return: Dictionary containing whitespace stripped trailer information
351
352 """
353 d = {}
354 cmd = ['git', 'interpret-trailers', '--parse']
355 proc: Git.AutoInterrupt = self.repo.git.execute(cmd, as_process=True, istream=PIPE) # type: ignore
356 trailer: str = proc.communicate(str(self.message).encode())[0].decode()
357 if trailer.endswith('\n'):
358 trailer = trailer[0:-1]
359 if trailer != '':
360 for line in trailer.split('\n'):
361 key, value = line.split(':', 1)
362 d[key.strip()] = value.strip()
363 return d
364
317365 @ classmethod
318366 def _iter_from_process_or_stream(cls, repo: 'Repo', proc_or_stream: Union[Popen, IO]) -> Iterator['Commit']:
319367 """Parse out commit information into a list of Commit objects
22 import logging
33 import os
44 import stat
5
6 from unittest import SkipTest
75 import uuid
86
97 import git
933931 rmtree(str(wtd))
934932 except Exception as ex:
935933 if HIDE_WINDOWS_KNOWN_ERRORS:
934 from unittest import SkipTest
936935 raise SkipTest("FIXME: fails with: PermissionError\n {}".format(ex)) from ex
937936 raise
938937 # END delete tree if possible
944943 rmtree(git_dir)
945944 except Exception as ex:
946945 if HIDE_WINDOWS_KNOWN_ERRORS:
946 from unittest import SkipTest
947947 raise SkipTest(f"FIXME: fails with: PermissionError\n {ex}") from ex
948948 else:
949949 raise
128128 k_config_remote_ref = "merge" # branch to merge from remote
129129
130130 @classmethod
131 def delete(cls, repo: 'Repo', *heads: 'Head', force: bool = False, **kwargs: Any) -> None:
131 def delete(cls, repo: 'Repo', *heads: 'Union[Head, str]', force: bool = False, **kwargs: Any) -> None:
132132 """Delete the given heads
133133
134134 :param force:
3636 # super is Reference
3737 return super(RemoteReference, cls).iter_items(repo, common_path)
3838
39 # The Head implementation of delete also accepts strs, but this
40 # implementation does not. mypy doesn't have a way of representing
41 # tightening the types of arguments in subclasses and recommends Any or
42 # "type: ignore". (See https://github.com/python/typing/issues/241)
3943 @ classmethod
40 def delete(cls, repo: 'Repo', *refs: 'RemoteReference', **kwargs: Any) -> None:
44 def delete(cls, repo: 'Repo', *refs: 'RemoteReference', # type: ignore
45 **kwargs: Any) -> None:
4146 """Delete the given remote references
4247
4348 :note:
234234 raise NotImplementedError
235235
236236
237 class PushInfoList(IterableList[PushInfo]):
238 def __new__(cls) -> 'PushInfoList':
239 return cast(PushInfoList, IterableList.__new__(cls, 'push_infos'))
240
241 def __init__(self) -> None:
242 super().__init__('push_infos')
243 self.error: Optional[Exception] = None
244
245 def raise_if_error(self) -> None:
246 """
247 Raise an exception if any ref failed to push.
248 """
249 if self.error:
250 raise self.error
251
252
237253 class FetchInfo(IterableObj, object):
238254
239255 """
256272 NEW_TAG, NEW_HEAD, HEAD_UPTODATE, TAG_UPDATE, REJECTED, FORCED_UPDATE, \
257273 FAST_FORWARD, ERROR = [1 << x for x in range(8)]
258274
259 _re_fetch_result = re.compile(r'^\s*(.) (\[?[\w\s\.$@]+\]?)\s+(.+) -> ([^\s]+)( \(.*\)?$)?')
275 _re_fetch_result = re.compile(r'^\s*(.) (\[[\w\s\.$@]+\]|[\w\.$@]+)\s+(.+) -> ([^\s]+)( \(.*\)?$)?')
260276
261277 _flag_map: Dict[flagKeyLiteral, int] = {
262278 '!': ERROR,
664680 return cls(repo, name)
665681
666682 # add is an alias
667 add = create
683 @ classmethod
684 def add(cls, repo: 'Repo', name: str, url: str, **kwargs: Any) -> 'Remote':
685 return cls.create(repo, name, url, **kwargs)
668686
669687 @ classmethod
670688 def remove(cls, repo: 'Repo', name: str) -> str:
771789
772790 def _get_push_info(self, proc: 'Git.AutoInterrupt',
773791 progress: Union[Callable[..., Any], RemoteProgress, None],
774 kill_after_timeout: Union[None, float] = None) -> IterableList[PushInfo]:
792 kill_after_timeout: Union[None, float] = None) -> PushInfoList:
775793 progress = to_progress_instance(progress)
776794
777795 # read progress information from stderr
779797 # read the lines manually as it will use carriage returns between the messages
780798 # to override the previous one. This is why we read the bytes manually
781799 progress_handler = progress.new_message_handler()
782 output: IterableList[PushInfo] = IterableList('push_infos')
800 output: PushInfoList = PushInfoList()
783801
784802 def stdout_handler(line: str) -> None:
785803 try:
793811 stderr_text = progress.error_lines and '\n'.join(progress.error_lines) or ''
794812 try:
795813 proc.wait(stderr=stderr_text)
796 except Exception:
814 except Exception as e:
797815 # This is different than fetch (which fails if there is any std_err
798816 # even if there is an output)
799817 if not output:
800818 raise
801819 elif stderr_text:
802820 log.warning("Error lines received while fetching: %s", stderr_text)
821 output.error = e
803822
804823 return output
805824
428428 :return: newly created Head Reference"""
429429 return Head.create(self, path, commit, logmsg, force)
430430
431 def delete_head(self, *heads: 'Head', **kwargs: Any) -> None:
431 def delete_head(self, *heads: 'Union[str, Head]', **kwargs: Any) -> None:
432432 """Delete the given heads
433433
434434 :param kwargs: Additional keyword arguments to be passed to git-branch"""
1919 import stat
2020 from sys import maxsize
2121 import time
22 from unittest import SkipTest
2322 from urllib.parse import urlsplit, urlunsplit
2423 import warnings
2524
129128 func(path) # Will scream if still not possible to delete.
130129 except Exception as ex:
131130 if HIDE_WINDOWS_KNOWN_ERRORS:
131 from unittest import SkipTest
132132 raise SkipTest("FIXME: fails with: PermissionError\n {}".format(ex)) from ex
133133 raise
134134
00 gitdb>=4.0.1,<5
1 typing-extensions>=3.7.4.3;python_version<"3.10"
1 typing-extensions>=3.7.4.3;python_version<"3.8"
121121 "Programming Language :: Python :: 3.7",
122122 "Programming Language :: Python :: 3.8",
123123 "Programming Language :: Python :: 3.9",
124 # "Programming Language :: Python :: 3.10"
124 "Programming Language :: Python :: 3.10",
125125 ]
126126 )
0 ddt>=1.1.1
0 ddt>=1.1.1, !=1.4.3
11 mypy
22
33 flake8
99
1010 pytest
1111 pytest-cov
12 pytest-sugar
12 coverage[toml]
13 pytest-sugar