9
9
from git .test .lib import TestBase
10
10
from git .test .lib .helper import with_rw_directory
11
11
12
- import os .path as osp
12
+ import os .path
13
13
14
14
15
15
class Tutorials (TestBase ):
@@ -25,7 +25,7 @@ def tearDown(self):
25
25
def test_init_repo_object (self , rw_dir ):
26
26
# [1-test_init_repo_object]
27
27
from git import Repo
28
- join = osp . join
28
+
29
29
30
30
# rorepo is a Repo instance pointing to the git-python repository.
31
31
# For all you know, the first argument to Repo is a path to the repository
@@ -35,7 +35,7 @@ def test_init_repo_object(self, rw_dir):
35
35
# ![1-test_init_repo_object]
36
36
37
37
# [2-test_init_repo_object]
38
- bare_repo = Repo .init (join (rw_dir , 'bare-repo' ), bare = True )
38
+ bare_repo = Repo .init (os . path . join (rw_dir , 'bare-repo' ), bare = True )
39
39
assert bare_repo .bare
40
40
# ![2-test_init_repo_object]
41
41
@@ -52,19 +52,19 @@ def test_init_repo_object(self, rw_dir):
52
52
# ![4-test_init_repo_object]
53
53
54
54
# [5-test_init_repo_object]
55
- cloned_repo = repo .clone (join (rw_dir , 'to/this/path' ))
55
+ cloned_repo = repo .clone (os . path . join (rw_dir , 'to/this/path' ))
56
56
assert cloned_repo .__class__ is Repo # clone an existing repository
57
- assert Repo .init (join (rw_dir , 'path/for/new/repo' )).__class__ is Repo
57
+ assert Repo .init (os . path . join (rw_dir , 'path/for/new/repo' )).__class__ is Repo
58
58
# ![5-test_init_repo_object]
59
59
60
60
# [6-test_init_repo_object]
61
- with open (join (rw_dir , 'repo.tar' ), 'wb' ) as fp :
61
+ with open (os . path . join (rw_dir , 'repo.tar' ), 'wb' ) as fp :
62
62
repo .archive (fp )
63
63
# ![6-test_init_repo_object]
64
64
65
65
# repository paths
66
66
# [7-test_init_repo_object]
67
- assert osp .isdir (cloned_repo .working_tree_dir ) # directory with your work files
67
+ assert os . path .isdir (cloned_repo .working_tree_dir ) # directory with your work files
68
68
assert cloned_repo .git_dir .startswith (cloned_repo .working_tree_dir ) # directory containing the git repository
69
69
assert bare_repo .working_tree_dir is None # bare repositories have no working tree
70
70
# ![7-test_init_repo_object]
@@ -148,7 +148,7 @@ def update(self, op_code, cur_count, max_count=None, message=''):
148
148
self .assertEqual (new_branch .checkout (), cloned_repo .active_branch ) # checking out branch adjusts the wtree
149
149
self .assertEqual (new_branch .commit , past .commit ) # Now the past is checked out
150
150
151
- new_file_path = osp .join (cloned_repo .working_tree_dir , 'my-new-file' )
151
+ new_file_path = os . path .join (cloned_repo .working_tree_dir , 'my-new-file' )
152
152
open (new_file_path , 'wb' ).close () # create new file in working tree
153
153
cloned_repo .index .add ([new_file_path ]) # add it to the index
154
154
# Commit the changes to deviate masters history
@@ -164,7 +164,7 @@ def update(self, op_code, cur_count, max_count=None, message=''):
164
164
# now new_branch is ahead of master, which probably should be checked out and reset softly.
165
165
# note that all these operations didn't touch the working tree, as we managed it ourselves.
166
166
# This definitely requires you to know what you are doing :) !
167
- assert osp .basename (new_file_path ) in new_branch .commit .tree # new file is now in tree
167
+ assert os . path .basename (new_file_path ) in new_branch .commit .tree # new file is now in tree
168
168
master .commit = new_branch .commit # let master point to most recent commit
169
169
cloned_repo .head .reference = master # we adjusted just the reference, not the working tree or index
170
170
# ![13-test_init_repo_object]
@@ -194,7 +194,7 @@ def update(self, op_code, cur_count, max_count=None, message=''):
194
194
def test_references_and_objects (self , rw_dir ):
195
195
# [1-test_references_and_objects]
196
196
import git
197
- repo = git .Repo .clone_from (self ._small_repo_url (), osp .join (rw_dir , 'repo' ), branch = 'master' )
197
+ repo = git .Repo .clone_from (self ._small_repo_url (), os . path .join (rw_dir , 'repo' ), branch = 'master' )
198
198
199
199
heads = repo .heads
200
200
master = heads .master # lists can be accessed by name for convenience
@@ -266,7 +266,7 @@ def test_references_and_objects(self, rw_dir):
266
266
267
267
# [11-test_references_and_objects]
268
268
hct .blobs [0 ].data_stream .read () # stream object to read data from
269
- hct .blobs [0 ].stream_data (open (osp .join (rw_dir , 'blob_data' ), 'wb' )) # write data to given stream
269
+ hct .blobs [0 ].stream_data (open (os . path .join (rw_dir , 'blob_data' ), 'wb' )) # write data to given stream
270
270
# ![11-test_references_and_objects]
271
271
272
272
# [12-test_references_and_objects]
@@ -352,11 +352,11 @@ def test_references_and_objects(self, rw_dir):
352
352
# Access blob objects
353
353
for (path , stage ), entry in index .entries .items (): # @UnusedVariable
354
354
pass
355
- new_file_path = osp .join (repo .working_tree_dir , 'new-file-name' )
355
+ new_file_path = os . path .join (repo .working_tree_dir , 'new-file-name' )
356
356
open (new_file_path , 'w' ).close ()
357
357
index .add ([new_file_path ]) # add a new file to the index
358
358
index .remove (['LICENSE' ]) # remove an existing one
359
- assert osp . isfile (osp .join (repo .working_tree_dir , 'LICENSE' )) # working tree is untouched
359
+ assert os . path . isfile (os . path .join (repo .working_tree_dir , 'LICENSE' )) # working tree is untouched
360
360
361
361
self .assertEqual (index .commit ("my commit message" ).type , 'commit' ) # commit changed index
362
362
repo .active_branch .commit = repo .commit ('HEAD~1' ) # forget last commit
@@ -375,11 +375,11 @@ def test_references_and_objects(self, rw_dir):
375
375
# merge two trees three-way into memory
376
376
merge_index = IndexFile .from_tree (repo , 'HEAD~10' , 'HEAD' , repo .merge_base ('HEAD~10' , 'HEAD' ))
377
377
# and persist it
378
- merge_index .write (osp .join (rw_dir , 'merged_index' ))
378
+ merge_index .write (os . path .join (rw_dir , 'merged_index' ))
379
379
# ![24-test_references_and_objects]
380
380
381
381
# [25-test_references_and_objects]
382
- empty_repo = git .Repo .init (osp .join (rw_dir , 'empty' ))
382
+ empty_repo = git .Repo .init (os . path .join (rw_dir , 'empty' ))
383
383
origin = empty_repo .create_remote ('origin' , repo .remotes .origin .url )
384
384
assert origin .exists ()
385
385
assert origin == empty_repo .remotes .origin == empty_repo .remotes ['origin' ]
@@ -482,8 +482,8 @@ def test_submodules(self):
482
482
def test_add_file_and_commit (self , rw_dir ):
483
483
import git
484
484
485
- repo_dir = osp .join (rw_dir , 'my-new-repo' )
486
- file_name = osp .join (repo_dir , 'new-file' )
485
+ repo_dir = os . path .join (rw_dir , 'my-new-repo' )
486
+ file_name = os . path .join (repo_dir , 'new-file' )
487
487
488
488
r = git .Repo .init (repo_dir )
489
489
# This function just creates an empty file ...
0 commit comments