1
1
import pytest
2
2
3
- import git
3
+
4
4
from test .lib import TestBase
5
5
from test .lib .helper import with_rw_directory
6
6
@@ -18,16 +18,46 @@ def test_init_repo_object(self, rw_dir):
18
18
# [1-test_init_repo_object]
19
19
from git import Repo
20
20
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
23
23
# ![1-test_init_repo_object]
24
24
25
25
# [2-test_init_repo_object]
26
+ import git
27
+
26
28
try :
27
29
repo = Repo (path_to_dir )
28
30
except git .NoSuchPathError :
29
31
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
31
37
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]
33
63
0 commit comments