@@ -172,23 +172,37 @@ def print_commit(commit):
172172
173173```
174174
175+ The ` print_commit ` function takes in a GitPython commit object and
176+ prints the 40-character SHA-1 hash for the commit followed by:
175177
178+ 1 . the commit summary
179+ 1 . author name
180+ 1 . author email
181+ 1 . commit date and time
182+ 1 . count and update size
183+
184+ Below the ` print_commit ` function, create another function named
185+ ` print_repository ` to print details of the ` Repo ` object:
176186
177187``` python
178188def print_repository (repo ):
179- print (' Repo active branch is {} ' .format(repo.active_branch))
180189 print (' Repo description: {} ' .format(repo.description))
181190 print (' Repo active branch is {} ' .format(repo.active_branch))
182191 for remote in repo.remotes:
183192 print (' Remote named "{} " with URL "{} "' .format(remote, remote.url))
184193 print (' Last commit for repo is {} .' .format(str (repo.head.commit.hexsha)))
194+
195+
185196```
186197
198+ ` print_repository ` is similar to ` print_commit ` but instead prints the
199+ repository description, active branch, all remote Git URLs configured
200+ for this repository and the latest commit.
201+
187202Finally, we need a "main" function for when we invoke the script from the
188203terminal using the ` python ` command. Round out our
189204
190205``` python
191-
192206if __name__ == " __main__" :
193207 repo_path = os.getenv(' GIT_REPO_PATH' )
194208 # Repo object used to programmatically interact with Git repositories
@@ -206,7 +220,12 @@ if __name__ == "__main__":
206220 print (' Could not load repository at {} :(' .format(repo_path))
207221```
208222
223+ The main function handles grabbing the ` GIT_REPO_PATH ` environment variable
224+ and creates a Repo object based on the path if possible.
209225
226+ If the repository is not empty, which indicates a failure to find the
227+ repository, then the ` print_repository ` and ` print_commit ` functions are
228+ called to show the repository data.
210229
211230If you want to copy and paste all of the code found above at once, take a
212231look at the
@@ -223,13 +242,16 @@ If the virtualenv is activated and the `GIT_REPO_PATH` environment variable
223242is set properly, we should see output similar to the following.
224243
225244``` bash
226- (gitpy) $ python read_repo.py
227245Repo at ~ /devel/py/fsp/ successfully loaded.
228- Repo active branch is master
229246Repo description: Unnamed repository; edit this file ' description' to name the repository.
230247Repo active branch is master
231248Remote named " origin" with URL " git@github.com:mattmakai/fullstackpython.com"
232- Last commit for repo is 1b026e4268d3ee1bd55f1979e9c397ca99bb5864.
249+ Last commit for repo is 1fa2de70aeb2ea64315f69991ccada51afac1ced.
250+ ----
251+ 1fa2de70aeb2ea64315f69991ccada51afac1ced
252+ " update latest blog post with code" by Matt Makai (matthew.makai@gmail.com)
253+ 2017-11-30 17:15:14-05:00
254+ count: 2256 and size: 254
233255----
2342561b026e4268d3ee1bd55f1979e9c397ca99bb5864
235257" new blog post, just needs completed code section" by Matt Makai (matthew.makai@gmail.com)
@@ -250,11 +272,6 @@ count: 2253 and size: 256
250272" add databases logos to relational databases pagem" by Matt Makai (matthew.makai@gmail.com)
2512732017-11-14 13:28:02-05:00
252274count: 2252 and size: 270
253- ----
254- c76810c85387d2d63edd83ea715d8d46f294c63b
255- " fix broken changelog link" by Matt Makai (matthew.makai@gmail.com)
256- 2017-11-14 13:17:45-05:00
257- count: 2251 and size: 246
258275```
259276
260277The specific commits you see will vary based on the last 5 commits I've
0 commit comments