@@ -120,7 +120,53 @@ def test_cloned_repo_object(self, rw_dir):
120120 # file4.txt
121121 # ![11-test_cloned_repo_object]
122122
123+ '''Trees and Blobs'''
123124
125+ # Latest commit tree
126+ # [12-test_cloned_repo_object]
127+ tree = repo .tree ()
128+ # ![12-test_cloned_repo_object]
129+
130+ # Previous commit tree
131+ # [13-test_cloned_repo_object]
132+ prev_commits = [c for c in repo .iter_commits ('--all' , max_count = 10 )]
133+ tree = prev_commits [0 ].tree
134+ # ![13-test_cloned_repo_object]
135+
136+ # Iterating through tree
137+ # [14-test_cloned_repo_object]
138+ tree = repo .tree ()
139+ files_dirs = [fd for fd in tree ]
140+ files_dirs
141+
142+ # Output
143+ # [<git.Tree "1d1cbc95a765e42bd46561f197eef01281a97ac0">,
144+ # <git.Tree "4ca53fd68b9a0eafd463c9681f1a26183a40779b">,
145+ # <git.Blob "9d384f1b6903ad992a97f91f720d8709b2b71f84">]
146+
147+ # ![14-test_cloned_repo_object]
148+
149+ # [15-test_cloned_repo_object]
150+ def print_files_from_git (tree , delim = '-' , i = 0 ):
151+ files_dirs = [fd for fd in tree ]
152+ for fd in files_dirs :
153+ print (f'{ delim if i != 0 else "" } | { fd .path } , { fd .type } ' )
154+ if fd .type == "tree" :
155+ print_files_from_git (fd , delim * 4 , i + 1 )
156+
157+ # ![15-test_cloned_repo_object]
158+
159+ # Printing text files
160+ # [16-test_cloned_repo_object]
161+ print_file = 'dir1/file2.txt'
162+ tree [print_file ]
163+
164+ # Output <git.Blob "3fab4a2e97ee374d0eccd854f298eee0b06a62fb">
165+ # ![16-test_cloned_repo_object]
166+
167+ # [17-test_cloned_repo_object]
168+
169+ # ![17-test_cloned_repo_object]
124170
125171
126172
0 commit comments