3
3
# This module is part of GitPython and is released under the
4
4
# 3-Clause BSD License: https://opensource.org/license/bsd-3-clause/
5
5
6
- """Module containing IndexFile, an Index implementation facilitating all kinds of index
7
- manipulations such as querying and merging."""
6
+ """Module containing :class:` IndexFile` , an Index implementation facilitating all kinds
7
+ of index manipulations such as querying and merging."""
8
8
9
9
import contextlib
10
10
import datetime
@@ -125,9 +125,9 @@ class IndexFile(LazyMixin, git_diff.Diffable, Serializable):
125
125
git command function calls wherever possible.
126
126
127
127
This provides custom merging facilities allowing to merge without actually changing
128
- your index or your working tree. This way you can perform own test- merges based on
129
- the index only without having to deal with the working copy. This is useful in case
130
- of partial working trees.
128
+ your index or your working tree. This way you can perform your own test merges based
129
+ on the index only without having to deal with the working copy. This is useful in
130
+ case of partial working trees.
131
131
132
132
Entries:
133
133
@@ -211,7 +211,7 @@ def _deserialize(self, stream: IO) -> "IndexFile":
211
211
return self
212
212
213
213
def _entries_sorted (self ) -> List [IndexEntry ]:
214
- """:return: list of entries, in a sorted fashion, first by path, then by stage"""
214
+ """:return: List of entries, in a sorted fashion, first by path, then by stage"""
215
215
return sorted (self .entries .values (), key = lambda e : (e .path , e .stage ))
216
216
217
217
def _serialize (self , stream : IO , ignore_extension_data : bool = False ) -> "IndexFile" :
@@ -232,17 +232,17 @@ def write(
232
232
"""Write the current state to our file path or to the given one.
233
233
234
234
:param file_path:
235
- If None, we will write to our stored file path from which we have been
235
+ If `` None`` , we will write to our stored file path from which we have been
236
236
initialized. Otherwise we write to the given file path. Please note that
237
- this will change the file_path of this index to the one you gave.
237
+ this will change the ` file_path` of this index to the one you gave.
238
238
239
239
:param ignore_extension_data:
240
- If True, the TREE type extension data read in the index will not be written
241
- to disk. NOTE that no extension data is actually written.
242
- Use this if you have altered the index and would like to use git-write-tree
243
- afterwards to create a tree representing your written changes.
244
- If this data is present in the written index, git- write-tree will instead
245
- write the stored/cached tree.
240
+ If `` True`` , the TREE type extension data read in the index will not be
241
+ written to disk. NOTE that no extension data is actually written.
242
+ Use this if you have altered the index and would like to use
243
+ ``git write-tree`` afterwards to create a tree representing your written
244
+ changes. If this data is present in the written index, `` git write-tree``
245
+ will instead write the stored/cached tree.
246
246
Alternatively, use :meth:`write_tree` to handle this case automatically.
247
247
"""
248
248
# Make sure we have our entries read before getting a write lock.
@@ -479,8 +479,8 @@ def _write_path_to_stdin(
479
479
stdout string
480
480
481
481
:param read_from_stdout:
482
- If True, proc.stdout will be read after the item was sent to stdin. In that
483
- case, it will return None.
482
+ If `` True``, `` proc.stdout`` will be read after the item was sent to stdin.
483
+ In that case, it will return `` None`` .
484
484
485
485
:note:
486
486
There is a bug in git-update-index that prevents it from sending reports
@@ -516,12 +516,13 @@ def iter_blobs(
516
516
) -> Iterator [Tuple [StageType , Blob ]]:
517
517
"""
518
518
:return:
519
- Iterator yielding tuples of Blob objects and stages, tuple(stage, Blob).
519
+ Iterator yielding tuples of :class:`~git.objects.blob.Blob` objects and
520
+ stages, tuple(stage, Blob).
520
521
521
522
:param predicate:
522
- Function(t) returning True if tuple(stage, Blob) should be yielded by the
523
- iterator. A default filter, the `~git.index.typ.BlobFilter`, allows you to
524
- yield blobs only if they match a given list of paths.
523
+ Function(t) returning `` True`` if tuple(stage, Blob) should be yielded by
524
+ the iterator. A default filter, the `~git.index.typ.BlobFilter`, allows you
525
+ to yield blobs only if they match a given list of paths.
525
526
"""
526
527
for entry in self .entries .values ():
527
528
blob = entry .to_blob (self .repo )
@@ -534,8 +535,8 @@ def iter_blobs(
534
535
def unmerged_blobs (self ) -> Dict [PathLike , List [Tuple [StageType , Blob ]]]:
535
536
"""
536
537
:return:
537
- Dict(path : list( tuple( stage, Blob, ...))), being a dictionary associating
538
- a path in the index with a list containing sorted stage/blob pairs.
538
+ Dict(path : list(tuple(stage, Blob, ...))), being a dictionary associating a
539
+ path in the index with a list containing sorted stage/blob pairs.
539
540
540
541
:note:
541
542
Blobs that have been removed in one side simply do not exist in the given
@@ -562,8 +563,8 @@ def resolve_blobs(self, iter_blobs: Iterator[Blob]) -> "IndexFile":
562
563
This will effectively remove the index entries of the respective path at all
563
564
non-null stages and add the given blob as new stage null blob.
564
565
565
- For each path there may only be one blob, otherwise a ValueError will be raised
566
- claiming the path is already at stage 0.
566
+ For each path there may only be one blob, otherwise a :class:` ValueError` will
567
+ be raised claiming the path is already at stage 0.
567
568
568
569
:raise ValueError:
569
570
If one of the blobs already existed at stage 0.
@@ -603,7 +604,8 @@ def update(self) -> "IndexFile":
603
604
This is a possibly dangerous operations as it will discard your changes to
604
605
:attr:`index.entries <entries>`.
605
606
606
- :return: self
607
+ :return:
608
+ self
607
609
"""
608
610
self ._delete_entries_cache ()
609
611
# Allows to lazily reread on demand.
@@ -654,8 +656,9 @@ def _process_diff_args(
654
656
655
657
def _to_relative_path (self , path : PathLike ) -> PathLike :
656
658
"""
657
- :return: Version of path relative to our git directory or raise
658
- :class:`ValueError` if it is not within our git directory.
659
+ :return:
660
+ Version of path relative to our git directory or raise :class:`ValueError`
661
+ if it is not within our git directory.
659
662
660
663
:raise ValueError:
661
664
"""
@@ -693,7 +696,7 @@ def _store_path(self, filepath: PathLike, fprogress: Callable) -> BaseIndexEntry
693
696
"""Store file at filepath in the database and return the base index entry.
694
697
695
698
:note:
696
- This needs the git_working_dir decorator active!
699
+ This needs the :func:`~git.index.util. git_working_dir` decorator active!
697
700
This must be ensured in the calling code.
698
701
"""
699
702
st = os .lstat (filepath ) # Handles non-symlinks as well.
@@ -810,33 +813,36 @@ def add(
810
813
The handling now very much equals the way string paths are processed,
811
814
except that the mode you have set will be kept. This allows you to
812
815
create symlinks by settings the mode respectively and writing the target
813
- of the symlink directly into the file. This equals a default
814
- Linux symlink which is not dereferenced automatically, except that it
815
- can be created on filesystems not supporting it as well.
816
+ of the symlink directly into the file. This equals a default Linux
817
+ symlink which is not dereferenced automatically, except that it can be
818
+ created on filesystems not supporting it as well.
816
819
817
820
Please note that globs or directories are not allowed in
818
- :class:~` git.objects.blob.Blob` objects.
821
+ :class:`~ git.objects.blob.Blob` objects.
819
822
820
823
They are added at stage 0.
821
824
822
825
- :class:`~git.index.typ.BaseIndexEntry` or type
823
826
824
- Handling equals the one of Blob objects, but the stage may be explicitly
825
- set. Please note that Index Entries require binary sha's.
827
+ Handling equals the one of :class:~`git.objects.blob.Blob` objects, but
828
+ the stage may be explicitly set. Please note that Index Entries require
829
+ binary sha's.
826
830
827
831
:param force:
828
832
**CURRENTLY INEFFECTIVE**
829
- If True, otherwise ignored or excluded files will be added anyway.
830
- As opposed to the ``git add`` command, we enable this flag by default as the
833
+ If `` True`` , otherwise ignored or excluded files will be added anyway. As
834
+ opposed to the ``git add`` command, we enable this flag by default as the
831
835
API user usually wants the item to be added even though they might be
832
836
excluded.
833
837
834
838
:param fprogress:
835
839
Function with signature ``f(path, done=False, item=item)`` called for each
836
840
path to be added, one time once it is about to be added where ``done=False``
837
841
and once after it was added where ``done=True``.
838
- ``item`` is set to the actual item we handle, either a Path or a
842
+
843
+ ``item`` is set to the actual item we handle, either a path or a
839
844
:class:`~git.index.typ.BaseIndexEntry`.
845
+
840
846
Please note that the processed path is not guaranteed to be present in the
841
847
index already as the index is currently being processed.
842
848
@@ -845,24 +851,24 @@ def add(
845
851
for each passed entry which is the path to be actually recorded for the
846
852
object created from :attr:`entry.path <git.index.typ.BaseIndexEntry.path>`.
847
853
This allows you to write an index which is not identical to the layout of
848
- the actual files on your hard-disk. If not None and `items` contain plain
849
- paths, these paths will be converted to Entries beforehand and passed to the
850
- path_rewriter. Please note that ``entry.path`` is relative to the git
854
+ the actual files on your hard-disk. If not `` None`` and `items` contain
855
+ plain paths, these paths will be converted to Entries beforehand and passed
856
+ to the path_rewriter. Please note that ``entry.path`` is relative to the git
851
857
repository.
852
858
853
859
:param write:
854
- If True, the index will be written once it was altered. Otherwise the
860
+ If `` True`` , the index will be written once it was altered. Otherwise the
855
861
changes only exist in memory and are not available to git commands.
856
862
857
863
:param write_extension_data:
858
- If True, extension data will be written back to the index. This can lead to
859
- issues in case it is containing the 'TREE' extension, which will cause the
860
- ``git commit`` command to write an old tree, instead of a new one
864
+ If `` True`` , extension data will be written back to the index. This can lead
865
+ to issues in case it is containing the 'TREE' extension, which will cause
866
+ the ``git commit`` command to write an old tree, instead of a new one
861
867
representing the now changed index.
862
868
863
869
This doesn't matter if you use :meth:`IndexFile.commit`, which ignores the
864
- 'TREE' extension altogether. You should set it to True if you intend to use
865
- :meth:`IndexFile.commit` exclusively while maintaining support for
870
+ 'TREE' extension altogether. You should set it to `` True`` if you intend to
871
+ use :meth:`IndexFile.commit` exclusively while maintaining support for
866
872
third-party extensions. Besides that, you can usually safely ignore the
867
873
built-in extensions when using GitPython on repositories that are not
868
874
handled manually at all.
@@ -875,7 +881,7 @@ def add(
875
881
just actually added.
876
882
877
883
:raise OSError:
878
- If a supplied Path did not exist. Please note that
884
+ If a supplied path did not exist. Please note that
879
885
:class:`~git.index.typ.BaseIndexEntry` objects that do not have a null sha
880
886
will be added even if their paths do not exist.
881
887
"""
@@ -999,7 +1005,7 @@ def remove(
999
1005
it. If absolute paths are given, they will be converted to a path
1000
1006
relative to the git repository directory containing the working tree
1001
1007
1002
- The path string may include globs, such as \ *.c.
1008
+ The path string may include globs, such as `` *.c`` .
1003
1009
1004
1010
- :class:~`git.objects.blob.Blob` object
1005
1011
@@ -1010,9 +1016,9 @@ def remove(
1010
1016
The only relevant information here is the path. The stage is ignored.
1011
1017
1012
1018
:param working_tree:
1013
- If True, the entry will also be removed from the working tree, physically
1014
- removing the respective file. This may fail if there are uncommitted changes
1015
- in it.
1019
+ If `` True`` , the entry will also be removed from the working tree,
1020
+ physically removing the respective file. This may fail if there are
1021
+ uncommitted changes in it.
1016
1022
1017
1023
:param kwargs:
1018
1024
Additional keyword arguments to be passed to ``git rm``, such as ``r`` to
@@ -1061,7 +1067,7 @@ def move(
1061
1067
for reference.
1062
1068
1063
1069
:param skip_errors:
1064
- If True, errors such as ones resulting from missing source files will be
1070
+ If `` True`` , errors such as ones resulting from missing source files will be
1065
1071
skipped.
1066
1072
1067
1073
:param kwargs:
@@ -1214,21 +1220,21 @@ def checkout(
1214
1220
case you have altered the entries dictionary directly.
1215
1221
1216
1222
:param paths:
1217
- If None, all paths in the index will be checked out. Otherwise an iterable
1218
- of relative or absolute paths or a single path pointing to files or
1219
- directories in the index is expected.
1223
+ If `` None`` , all paths in the index will be checked out.
1224
+ Otherwise an iterable of relative or absolute paths or a single path
1225
+ pointing to files or directories in the index is expected.
1220
1226
1221
1227
:param force:
1222
- If True, existing files will be overwritten even if they contain local
1228
+ If `` True`` , existing files will be overwritten even if they contain local
1223
1229
modifications.
1224
- If False, these will trigger a :class:`~git.exc.CheckoutError`.
1230
+ If `` False`` , these will trigger a :class:`~git.exc.CheckoutError`.
1225
1231
1226
1232
:param fprogress:
1227
1233
See :meth:`IndexFile.add` for signature and explanation.
1228
1234
1229
- The provided progress information will contain None as path and item if no
1230
- explicit paths are given. Otherwise progress information will be send prior
1231
- and after a file has been checked out.
1235
+ The provided progress information will contain `` None`` as path and item if
1236
+ no explicit paths are given. Otherwise progress information will be send
1237
+ prior and after a file has been checked out.
1232
1238
1233
1239
:param kwargs:
1234
1240
Additional arguments to be passed to ``git checkout-index``.
@@ -1238,10 +1244,10 @@ def checkout(
1238
1244
guaranteed to match the version stored in the index.
1239
1245
1240
1246
:raise git.exc.CheckoutError:
1241
- If at least one file failed to be checked out. This is a summary, hence it
1242
- will checkout as many files as it can anyway.
1243
- If one of files or directories do not exist in the index (as opposed to the
1244
- original git command, which ignores them).
1247
+ * If at least one file failed to be checked out. This is a summary, hence it
1248
+ will checkout as many files as it can anyway.
1249
+ * If one of files or directories do not exist in the index (as opposed to
1250
+ the original git command, which ignores them).
1245
1251
1246
1252
:raise git.exc.GitCommandError:
1247
1253
If error lines could not be parsed - this truly is an exceptional state.
@@ -1394,7 +1400,7 @@ def reset(
1394
1400
** kwargs : Any ,
1395
1401
) -> "IndexFile" :
1396
1402
"""Reset the index to reflect the tree at the given commit. This will not adjust
1397
- our `` HEAD`` reference by default, as opposed to
1403
+ our HEAD reference by default, as opposed to
1398
1404
:meth:`HEAD.reset <git.refs.head.HEAD.reset>`.
1399
1405
1400
1406
:param commit:
@@ -1406,14 +1412,14 @@ def reset(
1406
1412
overwrite the default index.
1407
1413
1408
1414
:param working_tree:
1409
- If True, the files in the working tree will reflect the changed index.
1410
- If False, the working tree will not be touched.
1415
+ If `` True`` , the files in the working tree will reflect the changed index.
1416
+ If `` False`` , the working tree will not be touched.
1411
1417
Please note that changes to the working copy will be discarded without
1412
1418
warning!
1413
1419
1414
1420
:param head:
1415
- If True, the head will be set to the given commit. This is False by default,
1416
- but if True, this method behaves like
1421
+ If `` True`` , the head will be set to the given commit. This is `` False`` by
1422
+ default, but if `` True`` , this method behaves like
1417
1423
:meth:`HEAD.reset <git.refs.head.HEAD.reset>`.
1418
1424
1419
1425
:param paths:
@@ -1433,7 +1439,8 @@ def reset(
1433
1439
If you want ``git reset``-like behaviour, use
1434
1440
:meth:`HEAD.reset <git.refs.head.HEAD.reset>` instead.
1435
1441
1436
- :return: self
1442
+ :return:
1443
+ self
1437
1444
"""
1438
1445
# What we actually want to do is to merge the tree into our existing index,
1439
1446
# which is what git-read-tree does.
0 commit comments