GitPython 3.1.47__py3-none-any.whl → 3.1.48__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
git/__init__.py CHANGED
@@ -86,7 +86,7 @@ __all__ = [
86
86
  "to_hex_sha",
87
87
  ]
88
88
 
89
- __version__ = '3.1.47'
89
+ __version__ = '3.1.48'
90
90
 
91
91
  from typing import Any, List, Optional, Sequence, TYPE_CHECKING, Tuple, Union
92
92
 
git/refs/log.py CHANGED
@@ -4,7 +4,6 @@
4
4
  __all__ = ["RefLog", "RefLogEntry"]
5
5
 
6
6
  from mmap import mmap
7
- import os.path as osp
8
7
  import re
9
8
  import time as _time
10
9
 
@@ -212,8 +211,11 @@ class RefLog(List[RefLogEntry], Serializable):
212
211
 
213
212
  :param ref:
214
213
  :class:`~git.refs.symbolic.SymbolicReference` instance
214
+
215
+ :raise ValueError:
216
+ If `ref.path` is invalid or escapes the repository's reflog directory.
215
217
  """
216
- return osp.join(ref.repo.git_dir, "logs", to_native_path(ref.path))
218
+ return to_native_path(ref._get_validated_reflog_path(ref.repo, ref.path))
217
219
 
218
220
  @classmethod
219
221
  def iter_entries(cls, stream: Union[str, "BytesIO", mmap]) -> Iterator[RefLogEntry]:
git/refs/remote.py CHANGED
@@ -58,17 +58,20 @@ class RemoteReference(Head):
58
58
  `kwargs` are given for comparability with the base class method as we
59
59
  should not narrow the signature.
60
60
  """
61
+ for ref in refs:
62
+ cls._check_ref_name_valid(ref.path)
63
+
61
64
  repo.git.branch("-d", "-r", *refs)
62
65
  # The official deletion method will ignore remote symbolic refs - these are
63
66
  # generally ignored in the refs/ folder. We don't though and delete remainders
64
67
  # manually.
65
68
  for ref in refs:
66
69
  try:
67
- os.remove(os.path.join(repo.common_dir, ref.path))
70
+ os.remove(cls._get_validated_path(repo.common_dir, ref.path))
68
71
  except OSError:
69
72
  pass
70
73
  try:
71
- os.remove(os.path.join(repo.git_dir, ref.path))
74
+ os.remove(cls._get_validated_path(repo.git_dir, ref.path))
72
75
  except OSError:
73
76
  pass
74
77
  # END for each ref
git/refs/symbolic.py CHANGED
@@ -110,6 +110,32 @@ class SymbolicReference:
110
110
  def abspath(self) -> PathLike:
111
111
  return join_path_native(_git_dir(self.repo, self.path), self.path)
112
112
 
113
+ @staticmethod
114
+ def _get_validated_path(base: PathLike, path: PathLike) -> str:
115
+ path = os.fspath(path)
116
+ base_path = os.path.realpath(os.fspath(base))
117
+ abs_path = os.path.realpath(os.path.join(base_path, path))
118
+ try:
119
+ common_path = os.path.commonpath([base_path, abs_path])
120
+ except ValueError as e:
121
+ raise ValueError("Reference path %r escapes the repository" % path) from e
122
+ if os.path.normcase(common_path) != os.path.normcase(base_path):
123
+ raise ValueError("Reference path %r escapes the repository" % path)
124
+ return abs_path
125
+
126
+ @classmethod
127
+ def _get_validated_ref_path(cls, repo: "Repo", path: PathLike) -> str:
128
+ """Return the absolute filesystem path for a ref after validating it."""
129
+ cls._check_ref_name_valid(path)
130
+ ref_path = os.fspath(path)
131
+ return cls._get_validated_path(_git_dir(repo, ref_path), ref_path)
132
+
133
+ @classmethod
134
+ def _get_validated_reflog_path(cls, repo: "Repo", path: PathLike) -> str:
135
+ """Return the absolute filesystem path for a reflog after validating it."""
136
+ cls._check_ref_name_valid(path)
137
+ return cls._get_validated_path(os.path.join(repo.git_dir, "logs"), path)
138
+
113
139
  @classmethod
114
140
  def _get_packed_refs_path(cls, repo: "Repo") -> str:
115
141
  return os.path.join(repo.common_dir, "packed-refs")
@@ -485,7 +511,7 @@ class SymbolicReference:
485
511
  # END handle non-existing
486
512
  # END retrieve old hexsha
487
513
 
488
- fpath = self.abspath
514
+ fpath = self._get_validated_ref_path(self.repo, self.path)
489
515
  assure_directory_exists(fpath, is_file=True)
490
516
 
491
517
  lfd = LockedFD(fpath)
@@ -632,7 +658,7 @@ class SymbolicReference:
632
658
  Alternatively the symbolic reference to be deleted.
633
659
  """
634
660
  full_ref_path = cls.to_full_path(path)
635
- abs_path = os.path.join(repo.common_dir, full_ref_path)
661
+ abs_path = cls._get_validated_ref_path(repo, full_ref_path)
636
662
  if os.path.exists(abs_path):
637
663
  os.remove(abs_path)
638
664
  else:
@@ -695,9 +721,8 @@ class SymbolicReference:
695
721
  symbolic reference. Otherwise it will be resolved to the corresponding object
696
722
  and a detached symbolic reference will be created instead.
697
723
  """
698
- git_dir = _git_dir(repo, path)
699
724
  full_ref_path = cls.to_full_path(path)
700
- abs_ref_path = os.path.join(git_dir, full_ref_path)
725
+ abs_ref_path = cls._get_validated_ref_path(repo, full_ref_path)
701
726
 
702
727
  # Figure out target data.
703
728
  target = reference
@@ -789,8 +814,8 @@ class SymbolicReference:
789
814
  if self.path == new_path:
790
815
  return self
791
816
 
792
- new_abs_path = os.path.join(_git_dir(self.repo, new_path), new_path)
793
- cur_abs_path = os.path.join(_git_dir(self.repo, self.path), self.path)
817
+ new_abs_path = self._get_validated_ref_path(self.repo, new_path)
818
+ cur_abs_path = self._get_validated_ref_path(self.repo, self.path)
794
819
  if os.path.isfile(new_abs_path):
795
820
  if not force:
796
821
  # If they point to the same file, it's not an error.
git/util.py CHANGED
@@ -289,7 +289,7 @@ def join_path(a: PathLike, *p: PathLike) -> PathLike:
289
289
 
290
290
  if sys.platform == "win32":
291
291
 
292
- def to_native_path_windows(path: PathLike) -> PathLike:
292
+ def to_native_path_windows(path: PathLike) -> str:
293
293
  path = os.fspath(path)
294
294
  return path.replace("/", "\\")
295
295
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: GitPython
3
- Version: 3.1.47
3
+ Version: 3.1.48
4
4
  Summary: GitPython is a Python library used to interact with Git repositories
5
5
  Home-page: https://github.com/gitpython-developers/GitPython
6
6
  Author: Sebastian Thiel, Michael Trier
@@ -1,4 +1,4 @@
1
- git/__init__.py,sha256=49UjU1OnoLWwxOzoGLfyGbV0zNwKjN47YU5i4u3ku48,8899
1
+ git/__init__.py,sha256=n7ZUyB_I0GQubucxnwYUAvFnLL3hiIF-G36z4clqUL4,8899
2
2
  git/cmd.py,sha256=4Ly0NF9kt1JarTD0zpPv7a0Al5I2PaohRMIG0UGKLCw,68559
3
3
  git/compat.py,sha256=y1E6y6O2q5r8clSlr8ZNmuIWG9nmHuehQEsVsmBffs8,4526
4
4
  git/config.py,sha256=vH4cb4n4HR_691Tex-ac3z-nLJpQqWxUsff1vqWZ-D8,35867
@@ -8,7 +8,7 @@ git/exc.py,sha256=Gc7g1pHpn8OmTse30NHmJVsBJ2CYH8LxaR8y8UA3lIM,7119
8
8
  git/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
9
9
  git/remote.py,sha256=pYn9dAlz-QwvNMWXD1M57pMPQitthOM86qTRK_cpTqU,46786
10
10
  git/types.py,sha256=d3oDduUGjfoqffcUL_GOD-3qroF8m3r9ai6Xi9_FraM,10279
11
- git/util.py,sha256=T1M3Nv-AbKSeZ3if33bpJFX450EeoGK67tr3SrEkjlU,44057
11
+ git/util.py,sha256=cCbGpBpnQq1MtW_REe8ApsAGTzp9JgVCMUN8KFgnx14,44052
12
12
  git/index/__init__.py,sha256=i-Nqb8Lufp9aFbmxpQBORmmQnjEVVM1Pn58fsQkyGgQ,406
13
13
  git/index/base.py,sha256=PdOmwjSjVXdYJF31y1853QdYTV8qUVAgAK0YZw3eyEI,61233
14
14
  git/index/fun.py,sha256=v0WnKQxaAffMZxXXC7pQOiMvRRJfODhUNKDMruxKrN4,17110
@@ -28,17 +28,17 @@ git/objects/submodule/root.py,sha256=5eTtYNHasqdPq6q0oDCPr7IaO6uAHL3b4DxMoiO2LhE
28
28
  git/objects/submodule/util.py,sha256=sQqAYaiSJdFkZa9NlAuK_wTsMNiS-kkQnQjvIoJtc_o,3509
29
29
  git/refs/__init__.py,sha256=DWlJNnsx-4jM_E-VycbP-FZUdn6iWhjnH_uZ_pZXBro,509
30
30
  git/refs/head.py,sha256=59MUMVu9phmE_ImkmNw0sDDSCc75s7TxkQj_cKzRhbo,10397
31
- git/refs/log.py,sha256=ooqlw_mn14FSQGvZXDC0Tt4MQG-4Hob8T92SDH9ZzfY,12517
31
+ git/refs/log.py,sha256=X88JTqjwX1ShvHr-NHNAZj0qLiHbVoF-0v3VymZDwoM,12612
32
32
  git/refs/reference.py,sha256=uzrvNTZ5fg7A0Aq4VC3KLSMbksgYUf4KvmHau0tFYIM,5646
33
- git/refs/remote.py,sha256=WwqV9T7BbYf3F_WZNUQivu9xktIIKGklCjDpwQrhD-A,2806
34
- git/refs/symbolic.py,sha256=seRKwWw7eegQyGoObE-PuuVpSvNyQRUAXqFRq0wI6yA,34892
33
+ git/refs/remote.py,sha256=WTlkJtpu895jJxbknDNOwL31tivQY_AHQrvroUoFBX4,2902
34
+ git/refs/symbolic.py,sha256=7ScmZHwlqPDKX9bxVC5queSZXUgqEY7_J_Si6gDBSLw,36139
35
35
  git/refs/tag.py,sha256=AKrFrMhkNzX8e9x5WmDRtHovbN9zYQghuKoneVW-TJg,5002
36
36
  git/repo/__init__.py,sha256=CILSVH36fX_WxVFSjD9o1WF5LgsNedPiJvSngKZqfVU,210
37
37
  git/repo/base.py,sha256=XI6FNYbd2HwrayazVPprFEHTMS6CHkzRZPjkYhw_elM,60220
38
38
  git/repo/fun.py,sha256=sjzJH8jy18nacsJjKKIqRBKadhhhxiyjmZKWXDErNnw,13787
39
- gitpython-3.1.47.dist-info/licenses/AUTHORS,sha256=uyjC8YZ5vcAlx2nSJ44J8gE7wjA8nc69_zWYo_HKtVc,2360
40
- gitpython-3.1.47.dist-info/licenses/LICENSE,sha256=hvyUwyGpr7wRUUcTURuv3tIl8lEA3MD3NQ6CvCMbi-s,1503
41
- gitpython-3.1.47.dist-info/METADATA,sha256=nopkhZXhd8oDQNXp-Ebzxz86dwqi15j1suk3BH8IoRc,14187
42
- gitpython-3.1.47.dist-info/WHEEL,sha256=aeYiig01lYGDzBgS8HxWXOg3uV61G9ijOsup-k9o1sk,91
43
- gitpython-3.1.47.dist-info/top_level.txt,sha256=0hzDuIp8obv624V3GmbqsagBWkk8ohtGU-Bc1PmTT0o,4
44
- gitpython-3.1.47.dist-info/RECORD,,
39
+ gitpython-3.1.48.dist-info/licenses/AUTHORS,sha256=uyjC8YZ5vcAlx2nSJ44J8gE7wjA8nc69_zWYo_HKtVc,2360
40
+ gitpython-3.1.48.dist-info/licenses/LICENSE,sha256=hvyUwyGpr7wRUUcTURuv3tIl8lEA3MD3NQ6CvCMbi-s,1503
41
+ gitpython-3.1.48.dist-info/METADATA,sha256=qvywsw3FCGzL89bcxLt68LzVTKZRbiWdgdqbIpsPttM,14187
42
+ gitpython-3.1.48.dist-info/WHEEL,sha256=aeYiig01lYGDzBgS8HxWXOg3uV61G9ijOsup-k9o1sk,91
43
+ gitpython-3.1.48.dist-info/top_level.txt,sha256=0hzDuIp8obv624V3GmbqsagBWkk8ohtGU-Bc1PmTT0o,4
44
+ gitpython-3.1.48.dist-info/RECORD,,