@@ -51,13 +51,78 @@ def test_cloned_repo_object(self, rw_dir):
51
51
# [2-test_cloned_repo_object]
52
52
# We must make a change to a file so that we can add the update to git
53
53
54
- update_file = 'dir1/file2.txt' # we'll use /dir1/file2.txt
54
+ update_file = 'dir1/file2.txt' # we'll use . /dir1/file2.txt
55
55
with open (f"{ local_dir } /{ update_file } " , 'a' ) as f :
56
56
f .write ('\n Update version 2' )
57
57
# ![2-test_cloned_repo_object]
58
58
59
59
# [3-test_cloned_repo_object]
60
- add_file = [f"{ local_dir } / { update_file } " ]
60
+ add_file = [f"{ update_file } " ] # relative path from git root
61
61
repo .index .add (add_file ) # notice the add function requires a list of paths
62
- # [3-test_cloned_repo_object]
62
+ # ![3-test_cloned_repo_object]
63
+
64
+ # code to commit - not sure how to test this
65
+ # [4-test_cloned_repo_object]
66
+ repo .index .commit ("Update to file2" )
67
+ # ![4-test_cloned_repo_object]
68
+
69
+ # [5-test_cloned_repo_object]
70
+ file = 'dir1/file2.txt' # relative path from git root
71
+ repo .iter_commits ('--all' , max_count = 100 , paths = file )
72
+
73
+ # Outputs: <generator object Commit._iter_from_process_or_stream at 0x7fb66c186cf0>
74
+
75
+ # ![5-test_cloned_repo_object]
76
+
77
+ # [6-test_cloned_repo_object]
78
+ commits_for_file_generator = repo .iter_commits ('--all' , max_count = 100 , paths = file )
79
+ commits_for_file = [c for c in commits_for_file_generator ]
80
+ commits_for_file
81
+
82
+ # Outputs: [<git.Commit "5076b368c97b01d83406ca095a301303da7f6fd4">,
83
+ # <git.Commit "d8dcd544e6fc5c00f6984424fc0cb4568abe518e">]
84
+ # ![6-test_cloned_repo_object]
85
+
86
+ # Untracked files - create new file
87
+ # [7-test_cloned_repo_object]
88
+ # We'll create a file5.txt
89
+
90
+ file5 = f'{ local_dir } /file5.txt'
91
+ with open (file5 , 'w' ) as f :
92
+ f .write ('file5 version 1' )
93
+ # ![7-test_cloned_repo_object]
94
+
95
+ # [8-test_cloned_repo_object]
96
+ repo .untracked_files
97
+ # Output: ['file5.txt']
98
+ # ![8-test_cloned_repo_object]
99
+
100
+ # Modified files
101
+ # [9-test_cloned_repo_object]
102
+ # Lets modify one of our tracked files
103
+ file3 = f'{ local_dir } /Downloads/file3.txt'
104
+ with open (file3 , 'w' ) as f :
105
+ f .write ('file3 version 2' ) # overwrite file 3
106
+ # ![9-test_cloned_repo_object]
107
+
108
+ # [10-test_cloned_repo_object]
109
+ repo .index .diff (None )
110
+ # Output: [<git.diff.Diff object at 0x7fb66c076e50>,
111
+ # <git.diff.Diff object at 0x7fb66c076ca0>]
112
+ # ![10-test_cloned_repo_object]
113
+
114
+ # [11-test_cloned_repo_object]
115
+ diffs = repo .index .diff (None )
116
+ for d in diffs :
117
+ print (d .a_path )
118
+
119
+ # Downloads/file3.txt
120
+ # file4.txt
121
+ # ![11-test_cloned_repo_object]
122
+
123
+
124
+
125
+
126
+
127
+
63
128
0 commit comments