Skip to content

Commit bccf8bc

Browse files
committed
added new section for diffs and formatting
1 parent 315405d commit bccf8bc

File tree

2 files changed

+60
-3
lines changed

2 files changed

+60
-3
lines changed

doc/source/quickstart.rst

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,30 @@ Status
216216
:start-after: # [11-test_cloned_repo_object]
217217
:end-before: # ![11-test_cloned_repo_object]
218218

219+
Diffs
220+
######
221+
222+
Compare staging area to head commit
223+
224+
.. literalinclude:: ../../test/test_quick_doc.py
225+
:language: python
226+
:dedent: 8
227+
:start-after: # [11.1-test_cloned_repo_object]
228+
:end-before: # ![11.1-test_cloned_repo_object]
229+
230+
.. literalinclude:: ../../test/test_quick_doc.py
231+
:language: python
232+
:dedent: 8
233+
:start-after: # [11.2-test_cloned_repo_object]
234+
:end-before: # ![11.2-test_cloned_repo_object]
235+
236+
Compare commit to commit
237+
238+
.. literalinclude:: ../../test/test_quick_doc.py
239+
:language: python
240+
:dedent: 8
241+
:start-after: # [11.3-test_cloned_repo_object]
242+
:end-before: # ![11.3-test_cloned_repo_object]
219243

220244

221245

test/test_quick_doc.py

Lines changed: 36 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ def test_init_repo_object(self, path_to_dir):
1919

2020
from git import Repo
2121

22-
repo = Repo.init(path_to_dir) # git init path/to/dir
22+
repo = Repo.init(path_to_dir)
2323
# ![1-test_init_repo_object]
2424

2525
# [2-test_init_repo_object]
@@ -111,10 +111,43 @@ def test_cloned_repo_object(self, local_dir):
111111
for d in diffs:
112112
print(d.a_path)
113113

114+
# Output
114115
# Downloads/file3.txt
115-
# file4.txt
116116
# ![11-test_cloned_repo_object]
117117

118+
# compares staging area to head commit
119+
# [11.1-test_cloned_repo_object]
120+
diffs = repo.index.diff(repo.head.commit)
121+
for d in diffs:
122+
print(d.a_path)
123+
124+
# Output
125+
126+
# ![11.1-test_cloned_repo_object]
127+
# [11.2-test_cloned_repo_object]
128+
# lets add untracked.txt
129+
repo.index.add(['untracked.txt'])
130+
diffs = repo.index.diff(repo.head.commit)
131+
for d in diffs:
132+
print(d.a_path)
133+
134+
# Output
135+
# untracked.txt
136+
# ![11.2-test_cloned_repo_object]
137+
138+
# Compare commit to commit
139+
# [11.3-test_cloned_repo_object]
140+
first_commit = [c for c in repo.iter_commits(all=True)][-1]
141+
diffs = repo.head.commit.diff(first_commit)
142+
for d in diffs:
143+
print(d.a_path)
144+
145+
# Output
146+
# dir1/file2.txt
147+
# ![11.3-test_cloned_repo_object]
148+
149+
150+
118151
'''Trees and Blobs'''
119152

120153
# Latest commit tree
@@ -141,7 +174,7 @@ def test_cloned_repo_object(self, local_dir):
141174
# ![14-test_cloned_repo_object]
142175

143176
# [14.1-test_cloned_repo_object]
144-
files_and_dirs = [(entry, entry.name) for entry in tree]
177+
files_and_dirs = [(entry, entry.name, entry.type) for entry in tree]
145178
files_and_dirs
146179

147180
# Output

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy