File tree Expand file tree Collapse file tree 2 files changed +70
-0
lines changed Expand file tree Collapse file tree 2 files changed +70
-0
lines changed Original file line number Diff line number Diff line change 1+ .. _quickdoc_toplevel :
2+
3+ .. highlight :: python
4+
5+ .. _quickdoc-label :
6+
7+ ==============================
8+ GitPython Quick Start Tutorial
9+ ==============================
10+
11+ git.Repo
12+ ********
13+
14+ There are a few ways to create a :class: `git.Repo <git.repo.base.Repo> ` object
15+
16+ An existing local path
17+ ######################
18+
19+ .. literalinclude :: ../../test/test_quick_doc.py
20+ :language: python
21+ :dedent: 8
22+ :start-after: # [1-test_init_repo_object]
23+ :end-before: # ![1-test_init_repo_object]
24+
25+ Existing local git Repo
26+ #######################
27+
28+ .. literalinclude :: ../../test/test_quick_doc.py
29+ :language: python
30+ :dedent: 8
31+ :start-after: # [2-test_init_repo_object]
32+ :end-before: # ![2-test_init_repo_object]
33+
34+ Clone from URL
35+ ##############
36+
37+ For the rest of this tutorial we will use a clone from https://github.com
Original file line number Diff line number Diff line change 1+ import pytest
2+
3+ import git
4+ from test .lib import TestBase
5+ from test .lib .helper import with_rw_directory
6+
7+
8+ class QuickDoc (TestBase ):
9+ def tearDown (self ):
10+ import gc
11+
12+ gc .collect ()
13+
14+ @with_rw_directory
15+ def test_init_repo_object (self , rw_dir ):
16+ path_to_dir = rw_dir
17+
18+ # [1-test_init_repo_object]
19+ from git import Repo
20+
21+ repo = Repo .init (path_to_dir )
22+ assert repo .__class__ is Repo # Test to confirm repo was initialized
23+ # ![1-test_init_repo_object]
24+
25+ # [2-test_init_repo_object]
26+ try :
27+ repo = Repo (path_to_dir )
28+ except git .NoSuchPathError :
29+ assert False , f"No such path { path_to_dir } "
30+ # ! [2-test_init_repo_object]
31+
32+ # [3 - test_init_repo_object]
33+
You can’t perform that action at this time.
0 commit comments