File: index_file.rst

package info (click to toggle)
python-pygit2 1.18.1-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 2,720 kB
  • sloc: ansic: 12,584; python: 9,337; sh: 205; makefile: 26
file content (121 lines) | stat: -rw-r--r-- 3,428 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
**********************************************************************
Index file & Working copy
**********************************************************************

.. autoattribute:: pygit2.Repository.index

Index read::

    >>> index = repo.index
    >>> index.read()
    >>> id = index['path/to/file'].id    # from path to object id
    >>> blob = repo[id]                  # from object id to object

Iterate over all entries of the index::

    >>> for entry in index:
    ...     print(entry.path, entry.id)

Index write::

    >>> index.add('path/to/file')                    # git add
    >>> index.remove('path/to/file')                 # git rm
    >>> index.remove_directory('path/to/directory/') # git rm -r
    >>> index.write()                                # don't forget to save the changes

Custom entries::
   >>> entry = pygit2.IndexEntry('README.md', blob_id, blob_filemode)
   >>> repo.index.add(entry)

The index fulfills a dual role as the in-memory representation of the
index file and data structure which represents a flat list of a
tree. You can use it independently of the index file, e.g.

  >>> index = pygit2.Index()
  >>> entry = pygit2.IndexEntry('README.md', blob_id, blob_filemode)
  >>> index.add(entry)

The Index type
====================

.. autoclass:: pygit2.Index
   :members:

The IndexEntry type
====================

.. autoclass:: pygit2.IndexEntry
   :members:

   .. automethod:: __eq__
   .. automethod:: __ne__
   .. automethod:: __repr__
   .. automethod:: __str__

The Stash type
====================

.. autoclass:: pygit2.Stash
   :members: commit_id, message

Status
====================

.. autoclass:: pygit2.Repository
   :members: status_file
   :noindex:

   .. automethod:: Repository.status

      Example, inspect the status of the repository::

        from pygit2.enums import FileStatus
        status = repo.status()
        for filepath, flags in status.items():
            if flags != FileStatus.CURRENT:
                print(f"Filepath {filepath} isn't clean")

This is the list of status flags for a single file::

    enums.FileStatus.CURRENT
    enums.FileStatus.INDEX_NEW
    enums.FileStatus.INDEX_MODIFIED
    enums.FileStatus.INDEX_DELETED
    enums.FileStatus.INDEX_RENAMED
    enums.FileStatus.INDEX_TYPECHANGE
    enums.FileStatus.WT_NEW
    enums.FileStatus.WT_MODIFIED
    enums.FileStatus.WT_DELETED
    enums.FileStatus.WT_TYPECHANGE
    enums.FileStatus.WT_RENAMED
    enums.FileStatus.WT_UNREADABLE
    enums.FileStatus.IGNORED
    enums.FileStatus.CONFLICTED

A combination of these values will be returned to indicate the status of a
file.  Status compares the working directory, the index, and the current HEAD
of the repository.  The `INDEX_...` set of flags represents the status
of file in the index relative to the HEAD, and the `WT_...` set of flags
represents the status of the file in the working directory relative to the
index.


Checkout
====================

.. automethod:: pygit2.Repository.checkout

Lower level API:

.. automethod:: pygit2.Repository.checkout_head
.. automethod:: pygit2.Repository.checkout_tree
.. automethod:: pygit2.Repository.checkout_index

Stash
====================

.. automethod:: pygit2.Repository.stash
.. automethod:: pygit2.Repository.stash_apply
.. automethod:: pygit2.Repository.stash_drop
.. automethod:: pygit2.Repository.stash_pop
.. automethod:: pygit2.Repository.listall_stashes