GitPython 3.1.47__tar.gz → 3.1.49__tar.gz

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.
Files changed (70) hide show
  1. {gitpython-3.1.47 → gitpython-3.1.49/GitPython.egg-info}/PKG-INFO +1 -1
  2. {gitpython-3.1.47/GitPython.egg-info → gitpython-3.1.49}/PKG-INFO +1 -1
  3. gitpython-3.1.49/VERSION +1 -0
  4. {gitpython-3.1.47 → gitpython-3.1.49}/doc/source/changes.rst +20 -0
  5. {gitpython-3.1.47 → gitpython-3.1.49}/git/__init__.py +1 -1
  6. {gitpython-3.1.47 → gitpython-3.1.49}/git/config.py +22 -2
  7. {gitpython-3.1.47 → gitpython-3.1.49}/git/refs/log.py +4 -2
  8. {gitpython-3.1.47 → gitpython-3.1.49}/git/refs/remote.py +5 -2
  9. {gitpython-3.1.47 → gitpython-3.1.49}/git/refs/symbolic.py +31 -6
  10. gitpython-3.1.49/git/repo/fun.py +736 -0
  11. {gitpython-3.1.47 → gitpython-3.1.49}/git/util.py +1 -1
  12. gitpython-3.1.47/VERSION +0 -1
  13. gitpython-3.1.47/git/repo/fun.py +0 -425
  14. {gitpython-3.1.47 → gitpython-3.1.49}/AUTHORS +0 -0
  15. {gitpython-3.1.47 → gitpython-3.1.49}/CHANGES +0 -0
  16. {gitpython-3.1.47 → gitpython-3.1.49}/CONTRIBUTING.md +0 -0
  17. {gitpython-3.1.47 → gitpython-3.1.49}/GitPython.egg-info/SOURCES.txt +0 -0
  18. {gitpython-3.1.47 → gitpython-3.1.49}/GitPython.egg-info/dependency_links.txt +0 -0
  19. {gitpython-3.1.47 → gitpython-3.1.49}/GitPython.egg-info/not-zip-safe +0 -0
  20. {gitpython-3.1.47 → gitpython-3.1.49}/GitPython.egg-info/requires.txt +0 -0
  21. {gitpython-3.1.47 → gitpython-3.1.49}/GitPython.egg-info/top_level.txt +0 -0
  22. {gitpython-3.1.47 → gitpython-3.1.49}/LICENSE +0 -0
  23. {gitpython-3.1.47 → gitpython-3.1.49}/MANIFEST.in +0 -0
  24. {gitpython-3.1.47 → gitpython-3.1.49}/README.md +0 -0
  25. {gitpython-3.1.47 → gitpython-3.1.49}/doc/.gitignore +0 -0
  26. {gitpython-3.1.47 → gitpython-3.1.49}/doc/Makefile +0 -0
  27. {gitpython-3.1.47 → gitpython-3.1.49}/doc/requirements.txt +0 -0
  28. {gitpython-3.1.47 → gitpython-3.1.49}/doc/source/conf.py +0 -0
  29. {gitpython-3.1.47 → gitpython-3.1.49}/doc/source/index.rst +0 -0
  30. {gitpython-3.1.47 → gitpython-3.1.49}/doc/source/intro.rst +0 -0
  31. {gitpython-3.1.47 → gitpython-3.1.49}/doc/source/quickstart.rst +0 -0
  32. {gitpython-3.1.47 → gitpython-3.1.49}/doc/source/reference.rst +0 -0
  33. {gitpython-3.1.47 → gitpython-3.1.49}/doc/source/roadmap.rst +0 -0
  34. {gitpython-3.1.47 → gitpython-3.1.49}/doc/source/tutorial.rst +0 -0
  35. {gitpython-3.1.47 → gitpython-3.1.49}/git/cmd.py +0 -0
  36. {gitpython-3.1.47 → gitpython-3.1.49}/git/compat.py +0 -0
  37. {gitpython-3.1.47 → gitpython-3.1.49}/git/db.py +0 -0
  38. {gitpython-3.1.47 → gitpython-3.1.49}/git/diff.py +0 -0
  39. {gitpython-3.1.47 → gitpython-3.1.49}/git/exc.py +0 -0
  40. {gitpython-3.1.47 → gitpython-3.1.49}/git/index/__init__.py +0 -0
  41. {gitpython-3.1.47 → gitpython-3.1.49}/git/index/base.py +0 -0
  42. {gitpython-3.1.47 → gitpython-3.1.49}/git/index/fun.py +0 -0
  43. {gitpython-3.1.47 → gitpython-3.1.49}/git/index/typ.py +0 -0
  44. {gitpython-3.1.47 → gitpython-3.1.49}/git/index/util.py +0 -0
  45. {gitpython-3.1.47 → gitpython-3.1.49}/git/objects/__init__.py +0 -0
  46. {gitpython-3.1.47 → gitpython-3.1.49}/git/objects/base.py +0 -0
  47. {gitpython-3.1.47 → gitpython-3.1.49}/git/objects/blob.py +0 -0
  48. {gitpython-3.1.47 → gitpython-3.1.49}/git/objects/commit.py +0 -0
  49. {gitpython-3.1.47 → gitpython-3.1.49}/git/objects/fun.py +0 -0
  50. {gitpython-3.1.47 → gitpython-3.1.49}/git/objects/submodule/__init__.py +0 -0
  51. {gitpython-3.1.47 → gitpython-3.1.49}/git/objects/submodule/base.py +0 -0
  52. {gitpython-3.1.47 → gitpython-3.1.49}/git/objects/submodule/root.py +0 -0
  53. {gitpython-3.1.47 → gitpython-3.1.49}/git/objects/submodule/util.py +0 -0
  54. {gitpython-3.1.47 → gitpython-3.1.49}/git/objects/tag.py +0 -0
  55. {gitpython-3.1.47 → gitpython-3.1.49}/git/objects/tree.py +0 -0
  56. {gitpython-3.1.47 → gitpython-3.1.49}/git/objects/util.py +0 -0
  57. {gitpython-3.1.47 → gitpython-3.1.49}/git/py.typed +0 -0
  58. {gitpython-3.1.47 → gitpython-3.1.49}/git/refs/__init__.py +0 -0
  59. {gitpython-3.1.47 → gitpython-3.1.49}/git/refs/head.py +0 -0
  60. {gitpython-3.1.47 → gitpython-3.1.49}/git/refs/reference.py +0 -0
  61. {gitpython-3.1.47 → gitpython-3.1.49}/git/refs/tag.py +0 -0
  62. {gitpython-3.1.47 → gitpython-3.1.49}/git/remote.py +0 -0
  63. {gitpython-3.1.47 → gitpython-3.1.49}/git/repo/__init__.py +0 -0
  64. {gitpython-3.1.47 → gitpython-3.1.49}/git/repo/base.py +0 -0
  65. {gitpython-3.1.47 → gitpython-3.1.49}/git/types.py +0 -0
  66. {gitpython-3.1.47 → gitpython-3.1.49}/pyproject.toml +0 -0
  67. {gitpython-3.1.47 → gitpython-3.1.49}/requirements.txt +0 -0
  68. {gitpython-3.1.47 → gitpython-3.1.49}/setup.cfg +0 -0
  69. {gitpython-3.1.47 → gitpython-3.1.49}/setup.py +0 -0
  70. {gitpython-3.1.47 → gitpython-3.1.49}/test-requirements.txt +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: GitPython
3
- Version: 3.1.47
3
+ Version: 3.1.49
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,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: GitPython
3
- Version: 3.1.47
3
+ Version: 3.1.49
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
@@ -0,0 +1 @@
1
+ 3.1.49
@@ -2,6 +2,26 @@
2
2
  Changelog
3
3
  =========
4
4
 
5
+ 3.1.49
6
+ ======
7
+
8
+ Save setting of configuration values,
9
+ which cuold be used to inject other more configuration.
10
+
11
+ Also more conforming `rev-parse` implementation.
12
+
13
+ See the following for all changes.
14
+ https://github.com/gitpython-developers/GitPython/releases/tag/3.1.49
15
+
16
+ 3.1.48
17
+ ======
18
+
19
+ Safe reference creation in the face of untrusted input.
20
+
21
+ See the following for all changes.
22
+ https://github.com/gitpython-developers/GitPython/releases/tag/3.1.48
23
+
24
+
5
25
  3.1.47
6
26
  ======
7
27
 
@@ -86,7 +86,7 @@ __all__ = [
86
86
  "to_hex_sha",
87
87
  ]
88
88
 
89
- __version__ = '3.1.47'
89
+ __version__ = '3.1.49'
90
90
 
91
91
  from typing import Any, List, Optional, Sequence, TYPE_CHECKING, Tuple, Union
92
92
 
@@ -882,6 +882,24 @@ class GitConfigParser(cp.RawConfigParser, metaclass=MetaParserBuilder):
882
882
  return str(value)
883
883
  return force_text(value)
884
884
 
885
+ def _value_to_string_safe(self, value: Union[str, bytes, int, float, bool]) -> str:
886
+ value_str = self._value_to_string(value)
887
+ if re.search(r"[\r\n\x00]", value_str):
888
+ raise ValueError("Git config values must not contain CR, LF, or NUL")
889
+ return value_str
890
+
891
+ @needs_values
892
+ @set_dirty_and_flush_changes
893
+ def set(
894
+ self,
895
+ section: str,
896
+ option: str,
897
+ value: Union[str, bytes, int, float, bool, None] = None,
898
+ ) -> None:
899
+ if value is not None:
900
+ value = self._value_to_string_safe(value)
901
+ return super().set(section, option, value)
902
+
885
903
  @needs_values
886
904
  @set_dirty_and_flush_changes
887
905
  def set_value(self, section: str, option: str, value: Union[str, bytes, int, float, bool]) -> "GitConfigParser":
@@ -902,9 +920,10 @@ class GitConfigParser(cp.RawConfigParser, metaclass=MetaParserBuilder):
902
920
  :return:
903
921
  This instance
904
922
  """
923
+ value_str = self._value_to_string_safe(value)
905
924
  if not self.has_section(section):
906
925
  self.add_section(section)
907
- self.set(section, option, self._value_to_string(value))
926
+ super().set(section, option, value_str)
908
927
  return self
909
928
 
910
929
  @needs_values
@@ -929,9 +948,10 @@ class GitConfigParser(cp.RawConfigParser, metaclass=MetaParserBuilder):
929
948
  :return:
930
949
  This instance
931
950
  """
951
+ value_str = self._value_to_string_safe(value)
932
952
  if not self.has_section(section):
933
953
  self.add_section(section)
934
- self._sections[section].add(option, self._value_to_string(value))
954
+ self._sections[section].add(option, value_str)
935
955
  return self
936
956
 
937
957
  def rename_section(self, section: str, new_name: str) -> "GitConfigParser":
@@ -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]:
@@ -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
@@ -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.