Skip to content

Commit 4f99fb4

Browse files
tswastByron
authored andcommitted
Dedent code blocks in tutorial.
I found the extra 8 spaces at the start of the examples in the tutorial to be distracting. The Sphinx dedent option removes these extra spaces from the rendered code blocks. I also got a warning about the shell code example not being lexed as Python, so I converted this to an explicit shell code block.
1 parent 7f08b77 commit 4f99fb4

File tree

2 files changed

+51
-1
lines changed

2 files changed

+51
-1
lines changed

‎AUTHORS

+1
Original file line numberDiff line numberDiff line change
@@ -26,5 +26,6 @@ Contributors are:
2626
-Mikuláš Poul <mikulaspoul _at_ gmail.com>
2727
-Charles Bouchard-Légaré <cblegare.atl _at_ ntis.ca>
2828
-Yaroslav Halchenko <debian _at_ onerussian.com>
29+
-Tim Swast <swast _at_ google.com>
2930

3031
Portions derived from other open source works and are clearly marked.

‎doc/source/tutorial.rst

+50-1
Original file line numberDiff line numberDiff line change
@@ -19,41 +19,47 @@ The first step is to create a :class:`git.Repo <git.repo.base.Repo>` object to r
1919

2020
.. literalinclude:: ../../git/test/test_docs.py
2121
:language: python
22+
:dedent: 8
2223
:start-after: # [1-test_init_repo_object]
2324
:end-before: # ![1-test_init_repo_object]
2425

2526
In the above example, the directory ``self.rorepo.working_tree_dir`` equals ``/Users/mtrier/Development/git-python`` and is my working repository which contains the ``.git`` directory. You can also initialize GitPython with a *bare* repository.
2627

2728
.. literalinclude:: ../../git/test/test_docs.py
2829
:language: python
30+
:dedent: 8
2931
:start-after: # [2-test_init_repo_object]
3032
:end-before: # ![2-test_init_repo_object]
3133

3234
A repo object provides high-level access to your data, it allows you to create and delete heads, tags and remotes and access the configuration of the repository.
3335

3436
.. literalinclude:: ../../git/test/test_docs.py
3537
:language: python
38+
:dedent: 8
3639
:start-after: # [3-test_init_repo_object]
3740
:end-before: # ![3-test_init_repo_object]
3841

3942
Query the active branch, query untracked files or whether the repository data has been modified.
4043

4144
.. literalinclude:: ../../git/test/test_docs.py
4245
:language: python
46+
:dedent: 8
4347
:start-after: # [4-test_init_repo_object]
4448
:end-before: # ![4-test_init_repo_object]
4549

4650
Clone from existing repositories or initialize new empty ones.
4751

4852
.. literalinclude:: ../../git/test/test_docs.py
4953
:language: python
54+
:dedent: 8
5055
:start-after: # [5-test_init_repo_object]
5156
:end-before: # ![5-test_init_repo_object]
5257

5358
Archive the repository contents to a tar file.
5459

5560
.. literalinclude:: ../../git/test/test_docs.py
5661
:language: python
62+
:dedent: 8
5763
:start-after: # [6-test_init_repo_object]
5864
:end-before: # ![6-test_init_repo_object]
5965

@@ -66,55 +72,63 @@ Query relevant repository paths ...
6672

6773
.. literalinclude:: ../../git/test/test_docs.py
6874
:language: python
75+
:dedent: 8
6976
:start-after: # [7-test_init_repo_object]
7077
:end-before: # ![7-test_init_repo_object]
7178

7279
:class:`Heads <git.refs.head.Head>` Heads are branches in git-speak. :class:`References <git.refs.reference.Reference>` are pointers to a specific commit or to other references. Heads and :class:`Tags <git.refs.tag.TagReference>` are a kind of references. GitPython allows you to query them rather intuitively.
7380

7481
.. literalinclude:: ../../git/test/test_docs.py
7582
:language: python
83+
:dedent: 8
7684
:start-after: # [8-test_init_repo_object]
7785
:end-before: # ![8-test_init_repo_object]
7886

7987
You can also create new heads ...
8088

8189
.. literalinclude:: ../../git/test/test_docs.py
8290
:language: python
91+
:dedent: 8
8392
:start-after: # [9-test_init_repo_object]
8493
:end-before: # ![9-test_init_repo_object]
8594

8695
... and tags ...
8796

8897
.. literalinclude:: ../../git/test/test_docs.py
8998
:language: python
99+
:dedent: 8
90100
:start-after: # [10-test_init_repo_object]
91101
:end-before: # ![10-test_init_repo_object]
92102

93103
You can traverse down to :class:`git objects <git.objects.base.Object>` through references and other objects. Some objects like :class:`commits <git.objects.commit.Commit>` have additional meta-data to query.
94104

95105
.. literalinclude:: ../../git/test/test_docs.py
96106
:language: python
107+
:dedent: 8
97108
:start-after: # [11-test_init_repo_object]
98109
:end-before: # ![11-test_init_repo_object]
99110

100111
:class:`Remotes <git.remote.Remote>` allow to handle fetch, pull and push operations, while providing optional real-time progress information to :class:`progress delegates <git.util.RemoteProgress>`.
101112

102113
.. literalinclude:: ../../git/test/test_docs.py
103114
:language: python
115+
:dedent: 8
104116
:start-after: # [12-test_init_repo_object]
105117
:end-before: # ![12-test_init_repo_object]
106118

107119
The :class:`index <git.index.base.IndexFile>` is also called stage in git-speak. It is used to prepare new commits, and can be used to keep results of merge operations. Our index implementation allows to stream date into the index, which is useful for bare repositories that do not have a working tree.
108120

109121
.. literalinclude:: ../../git/test/test_docs.py
110122
:language: python
123+
:dedent: 8
111124
:start-after: # [13-test_init_repo_object]
112125
:end-before: # ![13-test_init_repo_object]
113126

114127
:class:`Submodules <git.objects.submodule.Submodule>` represent all aspects of git submodules, which allows you query all of their related information, and manipulate in various ways.
115128

116129
.. literalinclude:: ../../git/test/test_docs.py
117130
:language: python
131+
:dedent: 8
118132
:start-after: # [14-test_init_repo_object]
119133
:end-before: # ![14-test_init_repo_object]
120134

@@ -126,27 +140,31 @@ Examining References
126140

127141
.. literalinclude:: ../../git/test/test_docs.py
128142
:language: python
143+
:dedent: 8
129144
:start-after: # [1-test_references_and_objects]
130145
:end-before: # ![1-test_references_and_objects]
131146

132147
:class:`Tags <git.refs.tag.TagReference>` are (usually immutable) references to a commit and/or a tag object.
133148

134149
.. literalinclude:: ../../git/test/test_docs.py
135150
:language: python
151+
:dedent: 8
136152
:start-after: # [2-test_references_and_objects]
137153
:end-before: # ![2-test_references_and_objects]
138154

139155
A :class:`symbolic reference <git.refs.symbolic.SymbolicReference>` is a special case of a reference as it points to another reference instead of a commit.
140156

141157
.. literalinclude:: ../../git/test/test_docs.py
142158
:language: python
159+
:dedent: 8
143160
:start-after: # [3-test_references_and_objects]
144161
:end-before: # ![3-test_references_and_objects]
145162

146163
Access the :class:`reflog <git.refs.log.RefLog>` easily.
147164

148165
.. literalinclude:: ../../git/test/test_docs.py
149166
:language: python
167+
:dedent: 8
150168
:start-after: # [4-test_references_and_objects]
151169
:end-before: # ![4-test_references_and_objects]
152170

@@ -156,20 +174,23 @@ You can easily create and delete :class:`reference types <git.refs.reference.Ref
156174

157175
.. literalinclude:: ../../git/test/test_docs.py
158176
:language: python
177+
:dedent: 8
159178
:start-after: # [5-test_references_and_objects]
160179
:end-before: # ![5-test_references_and_objects]
161180

162181
Create or delete :class:`tags <git.refs.tag.TagReference>` the same way except you may not change them afterwards.
163182

164183
.. literalinclude:: ../../git/test/test_docs.py
165184
:language: python
185+
:dedent: 8
166186
:start-after: # [6-test_references_and_objects]
167187
:end-before: # ![6-test_references_and_objects]
168188

169189
Change the :class:`symbolic reference <git.refs.symbolic.SymbolicReference>` to switch branches cheaply (without adjusting the index or the working tree).
170190

171191
.. literalinclude:: ../../git/test/test_docs.py
172192
:language: python
193+
:dedent: 8
173194
:start-after: # [7-test_references_and_objects]
174195
:end-before: # ![7-test_references_and_objects]
175196

@@ -183,27 +204,31 @@ In GitPython, all objects can be accessed through their common base, can be comp
183204

184205
.. literalinclude:: ../../git/test/test_docs.py
185206
:language: python
207+
:dedent: 8
186208
:start-after: # [8-test_references_and_objects]
187209
:end-before: # ![8-test_references_and_objects]
188210

189211
Common fields are ...
190212

191213
.. literalinclude:: ../../git/test/test_docs.py
192214
:language: python
215+
:dedent: 8
193216
:start-after: # [9-test_references_and_objects]
194217
:end-before: # ![9-test_references_and_objects]
195218

196219
:class:`Index objects <git.objects.base.IndexObject>` are objects that can be put into git's index. These objects are trees, blobs and submodules which additionally know about their path in the file system as well as their mode.
197220

198221
.. literalinclude:: ../../git/test/test_docs.py
199222
:language: python
223+
:dedent: 8
200224
:start-after: # [10-test_references_and_objects]
201225
:end-before: # ![10-test_references_and_objects]
202226

203227
Access :class:`blob <git.objects.blob.Blob>` data (or any object data) using streams.
204228

205229
.. literalinclude:: ../../git/test/test_docs.py
206230
:language: python
231+
:dedent: 8
207232
:start-after: # [11-test_references_and_objects]
208233
:end-before: # ![11-test_references_and_objects]
209234

@@ -217,34 +242,39 @@ Obtain commits at the specified revision
217242

218243
.. literalinclude:: ../../git/test/test_docs.py
219244
:language: python
245+
:dedent: 8
220246
:start-after: # [12-test_references_and_objects]
221247
:end-before: # ![12-test_references_and_objects]
222248

223249
Iterate 50 commits, and if you need paging, you can specify a number of commits to skip.
224250

225251
.. literalinclude:: ../../git/test/test_docs.py
226252
:language: python
253+
:dedent: 8
227254
:start-after: # [13-test_references_and_objects]
228255
:end-before: # ![13-test_references_and_objects]
229256

230257
A commit object carries all sorts of meta-data
231258

232259
.. literalinclude:: ../../git/test/test_docs.py
233260
:language: python
261+
:dedent: 8
234262
:start-after: # [14-test_references_and_objects]
235263
:end-before: # ![14-test_references_and_objects]
236264

237265
Note: date time is represented in a ``seconds since epoch`` format. Conversion to human readable form can be accomplished with the various `time module <http://docs.python.org/library/time.html>`_ methods.
238266

239267
.. literalinclude:: ../../git/test/test_docs.py
240268
:language: python
269+
:dedent: 8
241270
:start-after: # [15-test_references_and_objects]
242271
:end-before: # ![15-test_references_and_objects]
243272

244273
You can traverse a commit's ancestry by chaining calls to ``parents``
245274

246275
.. literalinclude:: ../../git/test/test_docs.py
247276
:language: python
277+
:dedent: 8
248278
:start-after: # [16-test_references_and_objects]
249279
:end-before: # ![16-test_references_and_objects]
250280

@@ -257,41 +287,47 @@ A :class:`tree <git.objects.tree.Tree>` records pointers to the contents of a di
257287

258288
.. literalinclude:: ../../git/test/test_docs.py
259289
:language: python
290+
:dedent: 8
260291
:start-after: # [17-test_references_and_objects]
261292
:end-before: # ![17-test_references_and_objects]
262293

263294
Once you have a tree, you can get its contents
264295

265296
.. literalinclude:: ../../git/test/test_docs.py
266297
:language: python
298+
:dedent: 8
267299
:start-after: # [18-test_references_and_objects]
268300
:end-before: # ![18-test_references_and_objects]
269301

270302
It is useful to know that a tree behaves like a list with the ability to query entries by name
271303

272304
.. literalinclude:: ../../git/test/test_docs.py
273305
:language: python
306+
:dedent: 8
274307
:start-after: # [19-test_references_and_objects]
275308
:end-before: # ![19-test_references_and_objects]
276309

277310
There is a convenience method that allows you to get a named sub-object from a tree with a syntax similar to how paths are written in a posix system
278311

279312
.. literalinclude:: ../../git/test/test_docs.py
280313
:language: python
314+
:dedent: 8
281315
:start-after: # [20-test_references_and_objects]
282316
:end-before: # ![20-test_references_and_objects]
283317

284318
You can also get a commit's root tree directly from the repository
285319

286320
.. literalinclude:: ../../git/test/test_docs.py
287321
:language: python
322+
:dedent: 8
288323
:start-after: # [21-test_references_and_objects]
289324
:end-before: # ![21-test_references_and_objects]
290325

291326
As trees allow direct access to their intermediate child entries only, use the traverse method to obtain an iterator to retrieve entries recursively
292327

293328
.. literalinclude:: ../../git/test/test_docs.py
294329
:language: python
330+
:dedent: 8
295331
:start-after: # [22-test_references_and_objects]
296332
:end-before: # ![22-test_references_and_objects]
297333

@@ -304,13 +340,15 @@ Modify the index with ease
304340

305341
.. literalinclude:: ../../git/test/test_docs.py
306342
:language: python
343+
:dedent: 8
307344
:start-after: # [23-test_references_and_objects]
308345
:end-before: # ![23-test_references_and_objects]
309346

310347
Create new indices from other trees or as result of a merge. Write that result to a new index file for later inspection.
311348

312349
.. literalinclude:: ../../git/test/test_docs.py
313350
:language: python
351+
:dedent: 8
314352
:start-after: # [24-test_references_and_objects]
315353
:end-before: # ![24-test_references_and_objects]
316354

@@ -321,13 +359,15 @@ Handling Remotes
321359

322360
.. literalinclude:: ../../git/test/test_docs.py
323361
:language: python
362+
:dedent: 8
324363
:start-after: # [25-test_references_and_objects]
325364
:end-before: # ![25-test_references_and_objects]
326365

327366
You can easily access configuration information for a remote by accessing options as if they where attributes. The modification of remote configuration is more explicit though.
328367

329368
.. literalinclude:: ../../git/test/test_docs.py
330369
:language: python
370+
:dedent: 8
331371
:start-after: # [26-test_references_and_objects]
332372
:end-before: # ![26-test_references_and_objects]
333373

@@ -343,7 +383,9 @@ This one sets a custom script to be executed in place of `ssh`, and can be used
343383
with repo.git.custom_environment(GIT_SSH=ssh_executable):
344384
repo.remotes.origin.fetch()
345385

346-
Here's an example executable that can be used in place of the `ssh_executable` above::
386+
Here's an example executable that can be used in place of the `ssh_executable` above:
387+
388+
.. code-block:: shell
347389
348390
#!/bin/sh
349391
ID_RSA=/var/lib/openshift/5562b947ecdd5ce939000038/app-deployments/id_rsa
@@ -359,6 +401,7 @@ Submodule Handling
359401

360402
.. literalinclude:: ../../git/test/test_docs.py
361403
:language: python
404+
:dedent: 8
362405
:start-after: # [1-test_submodules]
363406
:end-before: # ![1-test_submodules]
364407

@@ -383,13 +426,15 @@ Diffs can be made between the Index and Trees, Index and the working tree, trees
383426

384427
.. literalinclude:: ../../git/test/test_docs.py
385428
:language: python
429+
:dedent: 8
386430
:start-after: # [27-test_references_and_objects]
387431
:end-before: # ![27-test_references_and_objects]
388432

389433
The item returned is a DiffIndex which is essentially a list of Diff objects. It provides additional filtering to ease finding what you might be looking for.
390434

391435
.. literalinclude:: ../../git/test/test_docs.py
392436
:language: python
437+
:dedent: 8
393438
:start-after: # [28-test_references_and_objects]
394439
:end-before: # ![28-test_references_and_objects]
395440

@@ -413,13 +458,15 @@ To switch between branches similar to ``git checkout``, you effectively need to
413458

414459
.. literalinclude:: ../../git/test/test_docs.py
415460
:language: python
461+
:dedent: 8
416462
:start-after: # [29-test_references_and_objects]
417463
:end-before: # ![29-test_references_and_objects]
418464

419465
The previous approach would brutally overwrite the user's changes in the working copy and index though and is less sophisticated than a ``git-checkout``. The latter will generally prevent you from destroying your work. Use the safer approach as follows.
420466

421467
.. literalinclude:: ../../git/test/test_docs.py
422468
:language: python
469+
:dedent: 8
423470
:start-after: # [30-test_references_and_objects]
424471
:end-before: # ![30-test_references_and_objects]
425472

@@ -430,6 +477,7 @@ In this example, we will initialize an empty repository, add an empty file to th
430477

431478
.. literalinclude:: ../../git/test/test_docs.py
432479
:language: python
480+
:dedent: 8
433481
:start-after: def test_add_file_and_commit
434482
:end-before: # ![test_add_file_and_commit]
435483

@@ -441,6 +489,7 @@ In case you are missing functionality as it has not been wrapped, you may conven
441489

442490
.. literalinclude:: ../../git/test/test_docs.py
443491
:language: python
492+
:dedent: 8
444493
:start-after: # [31-test_references_and_objects]
445494
:end-before: # ![31-test_references_and_objects]
446495

0 commit comments

Comments
 (0)