11import pytest
22
3- import git
3+
44from test .lib import TestBase
55from test .lib .helper import with_rw_directory
66
@@ -18,16 +18,46 @@ def test_init_repo_object(self, rw_dir):
1818 # [1-test_init_repo_object]
1919 from git import Repo
2020
21- repo = Repo .init (path_to_dir )
22- assert repo .__class__ is Repo # Test to confirm repo was initialized
21+ repo = Repo .init (path_to_dir ) # git init path/to/dir
22+ assert repo .__class__ is Repo # Test to confirm repo was initialized
2323 # ![1-test_init_repo_object]
2424
2525 # [2-test_init_repo_object]
26+ import git
27+
2628 try :
2729 repo = Repo (path_to_dir )
2830 except git .NoSuchPathError :
2931 assert False , f"No such path { path_to_dir } "
30- # ! [2-test_init_repo_object]
32+ # ![2-test_init_repo_object]
33+
34+ @with_rw_directory
35+ def test_cloned_repo_object (self , rw_dir ):
36+ local_dir = rw_dir
3137
32- # [3 - test_init_repo_object]
38+ from git import Repo
39+ import git
40+ # code to clone from url
41+ # [1-test_cloned_repo_object]
42+ repo_url = "https://github.com/LeoDaCoda/GitPython-TestFileSys.git"
43+
44+ try :
45+ repo = Repo .clone_from (repo_url , local_dir )
46+ except git .CommandError :
47+ assert False , f"Invalid address { repo_url } "
48+ # ![1-test_cloned_repo_object]
49+
50+ # code to add files
51+ # [2-test_cloned_repo_object]
52+ # We must make a change to a file so that we can add the update to git
53+
54+ update_file = 'dir1/file2.txt' # we'll use /dir1/file2.txt
55+ with open (f"{ local_dir } /{ update_file } " , 'a' ) as f :
56+ f .write ('\n Update version 2' )
57+ # ![2-test_cloned_repo_object]
58+
59+ # [3-test_cloned_repo_object]
60+ add_file = [f"{ local_dir } /{ update_file } " ]
61+ repo .index .add (add_file ) # notice the add function requires a list of paths
62+ # [3-test_cloned_repo_object]
3363
0 commit comments