Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit9ca25d7

Browse files
committed
WIP major changes to structure to improve readability
1 parentf3968f2 commit9ca25d7

File tree

2 files changed

+87
-62
lines changed

2 files changed

+87
-62
lines changed

‎doc/source/quickstart.rst

Lines changed: 63 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,41 @@ GitPython Quick Start Tutorial
1010
Welcome to the GitPython Quickstart Guide! Designed for developers seeking a practical and interactive learning experience, this concise resource offers step-by-step code snippets to swiftly initialize/clone repositories, perform essential Git operations, and explore GitPython's capabilities. Get ready to dive in, experiment, and unleash the power of GitPython in your projects!
1111

1212

13+
git.Repo
14+
********
15+
16+
There are a few ways to create a:class:`git.Repo <git.repo.base.Repo>` object
17+
18+
Initialize a new git Repo
19+
#########################
20+
21+
..literalinclude::../../test/test_quick_doc.py
22+
:language: python
23+
:dedent: 8
24+
:start-after: # [1-test_init_repo_object]
25+
:end-before: # ![1-test_init_repo_object]
26+
27+
Existing local git Repo
28+
#######################
29+
30+
..literalinclude::../../test/test_quick_doc.py
31+
:language: python
32+
:dedent: 8
33+
:start-after: # [2-test_init_repo_object]
34+
:end-before: # ![2-test_init_repo_object]
35+
36+
Clone from URL
37+
##############
38+
39+
For the rest of this tutorial we will use a clone from https://github.com/gitpython-developers/QuickStartTutorialFiles.git
40+
41+
..literalinclude::../../test/test_quick_doc.py
42+
:language: python
43+
:dedent: 8
44+
:start-after: # [1-test_cloned_repo_object]
45+
:end-before: # ![1-test_cloned_repo_object]
46+
47+
1348
Trees & Blobs
1449
**************
1550

@@ -40,6 +75,12 @@ Display level 1 Contents
4075
:start-after: # [14-test_cloned_repo_object]
4176
:end-before: # ![14-test_cloned_repo_object]
4277

78+
..literalinclude::../../test/test_quick_doc.py
79+
:language: python
80+
:dedent: 8
81+
:start-after: # [14.1-test_cloned_repo_object]
82+
:end-before: # ![14.1-test_cloned_repo_object]
83+
4384
Recurse through the Tree
4485
########################
4586

@@ -58,67 +99,10 @@ Recurse through the Tree
5899

59100

60101

61-
Printing text files
62-
####################
63-
64-
..literalinclude::../../test/test_quick_doc.py
65-
:language: python
66-
:dedent: 8
67-
:start-after: # [17-test_cloned_repo_object]
68-
:end-before: # ![17-test_cloned_repo_object]
69-
70-
..literalinclude::../../test/test_quick_doc.py
71-
:language: python
72-
:dedent: 8
73-
:start-after: # [18-test_cloned_repo_object]
74-
:end-before: # ![18-test_cloned_repo_object]
75-
76-
77-
78-
79-
80-
git.Repo
81-
********
82-
83-
There are a few ways to create a:class:`git.Repo <git.repo.base.Repo>` object
84-
85-
An existing local path
86-
######################
87-
88-
$ git init path/to/dir
89-
90-
..literalinclude::../../test/test_quick_doc.py
91-
:language: python
92-
:dedent: 8
93-
:start-after: # [1-test_init_repo_object]
94-
:end-before: # ![1-test_init_repo_object]
95-
96-
Existing local git Repo
97-
#######################
98-
99-
..literalinclude::../../test/test_quick_doc.py
100-
:language: python
101-
:dedent: 8
102-
:start-after: # [2-test_init_repo_object]
103-
:end-before: # ![2-test_init_repo_object]
104-
105-
Clone from URL
106-
##############
107-
108-
For the rest of this tutorial we will use a clone from https://github.com/gitpython-developers/QuickStartTutorialFiles.git
109-
110-
$ git clone https://github.com/gitpython-developers/QuickStartTutorialFiles.git
111-
112-
..literalinclude::../../test/test_quick_doc.py
113-
:language: python
114-
:dedent: 8
115-
:start-after: # [1-test_cloned_repo_object]
116-
:end-before: # ![1-test_cloned_repo_object]
117-
118102
Usage
119103
****************
120104

121-
* $ git add filepath
105+
* $ git add<filepath>
122106

123107
..literalinclude::../../test/test_quick_doc.py
124108
:language: python
@@ -146,7 +130,7 @@ Warning: If you experience any trouble with this, try to invoke :class:`git <git
146130
:start-after: # [4-test_cloned_repo_object]
147131
:end-before: # ![4-test_cloned_repo_object]
148132

149-
* $ git log file
133+
* $ git log<file>
150134

151135
A list of commits associated with a file
152136

@@ -166,6 +150,24 @@ Notice this returns a generator object
166150

167151
returns list of:class:`Commit <git.objects.commit.Commit>` objects
168152

153+
Printing text files
154+
####################
155+
Lets print the latest version of `<local_dir> dir1/file2.txt`
156+
157+
..literalinclude::../../test/test_quick_doc.py
158+
:language: python
159+
:dedent: 8
160+
:start-after: # [17-test_cloned_repo_object]
161+
:end-before: # ![17-test_cloned_repo_object]
162+
163+
..literalinclude::../../test/test_quick_doc.py
164+
:language: python
165+
:dedent: 8
166+
:start-after: # [18-test_cloned_repo_object]
167+
:end-before: # ![18-test_cloned_repo_object]
168+
169+
Previous version of `<local_dir>/dir1/file2.txt`
170+
169171
* $ git status
170172

171173
* Untracked files
@@ -207,3 +209,5 @@ returns list of :class:`Commit <git.objects.commit.Commit>` objects
207209
:end-before: # ![11-test_cloned_repo_object]
208210

209211

212+
213+

‎test/test_quick_doc.py

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ def tearDown(self):
1515
deftest_init_repo_object(self,path_to_dir):
1616

1717
# [1-test_init_repo_object]
18+
# $ git init <path/to/dir>
19+
1820
fromgitimportRepo
1921

2022
repo=Repo.init(path_to_dir)# git init path/to/dir
@@ -31,6 +33,8 @@ def test_cloned_repo_object(self, local_dir):
3133
importgit
3234
# code to clone from url
3335
# [1-test_cloned_repo_object]
36+
# $ git clone <url> <local_dir>
37+
3438
repo_url="https://github.com/gitpython-developers/QuickStartTutorialFiles.git"
3539

3640
repo=Repo.clone_from(repo_url,local_dir)
@@ -128,12 +132,22 @@ def test_cloned_repo_object(self, local_dir):
128132
files_and_dirs
129133

130134
# Output
131-
# [<git.Commit "SHA1-HEX_HASH-2">,
132-
# <git.Commit "SHA1-HEX_HASH-2">,
133-
# <git.Commit "SHA1-HEX_HASH-2">]
135+
# [<git.Commit "SHA1-HEX_HASH">,
136+
# <git.Commit "SHA1-HEX_HASH">,
137+
# <git.Commit "SHA1-HEX_HASH">]
134138

135139
# ![14-test_cloned_repo_object]
136140

141+
# [14.1-test_cloned_repo_object]
142+
files_and_dirs= [(entry,entry.name)forentryintree]
143+
files_and_dirs
144+
145+
# Output
146+
# [(< git.Tree "SHA1-HEX_HASH" >, 'Downloads', 'tree'),
147+
# (< git.Tree "SHA1-HEX_HASH" >, 'dir1', 'tree'),
148+
# (< git.Blob "SHA1-HEX_HASH" >, 'file4.txt', 'blob')]
149+
# ![14.1-test_cloned_repo_object]
150+
137151
# [15-test_cloned_repo_object]
138152
defprint_files_from_git(root,level=0):
139153
forentryinroot:
@@ -163,6 +177,13 @@ def print_files_from_git(root, level=0):
163177
# Output <git.Blob "SHA1-HEX-HASH-1">
164178
# ![17-test_cloned_repo_object]
165179

180+
# print pre
181+
# [17.1-test_cloned_repo_object]
182+
commits_for_file= [cforcinrepo.iter_commits(all=True,paths=print_file)]
183+
blob=tree[print_file]
184+
185+
# ![17.1-test_cloned_repo_object]
186+
166187
# [18-test_cloned_repo_object]
167188
blob=tree[print_file]
168189
print(blob.data_stream.read().decode())

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp