5
5
from unittest .case import skipIf
6
6
7
7
import git
8
+ from git .cmd import Git
8
9
from git .compat import string_types , is_win
9
10
from git .exc import (
10
11
InvalidGitRepositoryError ,
23
24
from git .test .lib import with_rw_directory
24
25
from git .util import HIDE_WINDOWS_KNOWN_ERRORS
25
26
from git .util import to_native_path_linux , join_path_native
27
+ import os .path as osp
26
28
27
29
28
30
# Change the configuration if possible to prevent the underlying memory manager
@@ -111,7 +113,7 @@ def _do_base_tests(self, rwrepo):
111
113
else :
112
114
with sm .config_writer () as writer :
113
115
# for faster checkout, set the url to the local path
114
- new_smclone_path = to_native_path_linux ( join_path_native (self .rorepo .working_tree_dir , sm .path ))
116
+ new_smclone_path = Git . polish_url ( osp . join (self .rorepo .working_tree_dir , sm .path ))
115
117
writer .set_value ('url' , new_smclone_path )
116
118
writer .release ()
117
119
assert sm .config_reader ().get_value ('url' ) == new_smclone_path
@@ -168,7 +170,7 @@ def _do_base_tests(self, rwrepo):
168
170
#################
169
171
170
172
# lets update it - its a recursive one too
171
- newdir = os . path .join (sm .abspath , 'dir' )
173
+ newdir = osp .join (sm .abspath , 'dir' )
172
174
os .makedirs (newdir )
173
175
174
176
# update fails if the path already exists non-empty
@@ -213,7 +215,7 @@ def _do_base_tests(self, rwrepo):
213
215
csm_repopath = csm .path
214
216
215
217
# adjust the path of the submodules module to point to the local destination
216
- new_csmclone_path = to_native_path_linux ( join_path_native (self .rorepo .working_tree_dir , sm .path , csm .path ))
218
+ new_csmclone_path = Git . polish_url ( osp . join (self .rorepo .working_tree_dir , sm .path , csm .path ))
217
219
with csm .config_writer () as writer :
218
220
writer .set_value ('url' , new_csmclone_path )
219
221
assert csm .url == new_csmclone_path
@@ -301,7 +303,7 @@ def _do_base_tests(self, rwrepo):
301
303
csm .update ()
302
304
assert csm .module_exists ()
303
305
assert csm .exists ()
304
- assert os . path .isdir (csm .module ().working_tree_dir )
306
+ assert osp .isdir (csm .module ().working_tree_dir )
305
307
306
308
# this would work
307
309
assert sm .remove (force = True , dry_run = True ) is sm
@@ -354,15 +356,15 @@ def _do_base_tests(self, rwrepo):
354
356
assert nsm .module_exists ()
355
357
assert nsm .exists ()
356
358
# its not checked out
357
- assert not os . path .isfile (join_path_native (nsm .module ().working_tree_dir , Submodule .k_modules_file ))
359
+ assert not osp .isfile (join_path_native (nsm .module ().working_tree_dir , Submodule .k_modules_file ))
358
360
assert len (rwrepo .submodules ) == 1
359
361
360
362
# add another submodule, but into the root, not as submodule
361
363
osm = Submodule .add (rwrepo , osmid , csm_repopath , new_csmclone_path , Submodule .k_head_default )
362
364
assert osm != nsm
363
365
assert osm .module_exists ()
364
366
assert osm .exists ()
365
- assert os . path .isfile (join_path_native (osm .module ().working_tree_dir , 'setup.py' ))
367
+ assert osp .isfile (join_path_native (osm .module ().working_tree_dir , 'setup.py' ))
366
368
367
369
assert len (rwrepo .submodules ) == 2
368
370
@@ -430,11 +432,6 @@ def test_base_rw(self, rwrepo):
430
432
def test_base_bare (self , rwrepo ):
431
433
self ._do_base_tests (rwrepo )
432
434
433
- @skipIf (HIDE_WINDOWS_KNOWN_ERRORS and sys .version_info [:2 ] == (3 , 5 ), """
434
- File "C:\projects\gitpython\git\cmd.py", line 559, in execute
435
- raise GitCommandNotFound(command, err)
436
- git.exc.GitCommandNotFound: Cmd('git') not found due to: OSError('[WinError 6] The handle is invalid')
437
- cmdline: git clone -n --shared -v C:\projects\gitpython\.git Users\a ppveyor\AppData\Local\Temp\1 \t mplyp6kr_rnon_bare_test_root_module""" ) # noqa E501
438
435
@with_rw_repo (k_subm_current , bare = False )
439
436
def test_root_module (self , rwrepo ):
440
437
# Can query everything without problems
@@ -479,7 +476,7 @@ def test_root_module(self, rwrepo):
479
476
480
477
# assure we clone from a local source
481
478
with sm .config_writer () as writer :
482
- writer .set_value ('url' , to_native_path_linux ( join_path_native (self .rorepo .working_tree_dir , sm .path )))
479
+ writer .set_value ('url' , Git . polish_url ( osp . join (self .rorepo .working_tree_dir , sm .path )))
483
480
484
481
# dry-run does nothing
485
482
sm .update (recursive = False , dry_run = True , progress = prog )
@@ -513,7 +510,7 @@ def test_root_module(self, rwrepo):
513
510
#================
514
511
nsmn = "newsubmodule"
515
512
nsmp = "submrepo"
516
- subrepo_url = to_native_path_linux ( join_path_native (self .rorepo .working_tree_dir , rsmsp [0 ], rsmsp [1 ]))
513
+ subrepo_url = Git . polish_url ( osp . join (self .rorepo .working_tree_dir , rsmsp [0 ], rsmsp [1 ]))
517
514
nsm = Submodule .add (rwrepo , nsmn , nsmp , url = subrepo_url )
518
515
csmadded = rwrepo .index .commit ("Added submodule" ).hexsha # make sure we don't keep the repo reference
519
516
nsm .set_parent_commit (csmadded )
@@ -535,24 +532,24 @@ def test_root_module(self, rwrepo):
535
532
sm .set_parent_commit (csmadded )
536
533
smp = sm .abspath
537
534
assert not sm .remove (module = False ).exists ()
538
- assert os . path .isdir (smp ) # module still exists
535
+ assert osp .isdir (smp ) # module still exists
539
536
csmremoved = rwrepo .index .commit ("Removed submodule" )
540
537
541
538
# an update will remove the module
542
539
# not in dry_run
543
540
rm .update (recursive = False , dry_run = True , force_remove = True )
544
- assert os . path .isdir (smp )
541
+ assert osp .isdir (smp )
545
542
546
543
# when removing submodules, we may get new commits as nested submodules are auto-committing changes
547
544
# to allow deletions without force, as the index would be dirty otherwise.
548
545
# QUESTION: Why does this seem to work in test_git_submodule_compatibility() ?
549
546
self .failUnlessRaises (InvalidGitRepositoryError , rm .update , recursive = False , force_remove = False )
550
547
rm .update (recursive = False , force_remove = True )
551
- assert not os . path .isdir (smp )
548
+ assert not osp .isdir (smp )
552
549
553
550
# 'apply work' to the nested submodule and assure this is not removed/altered during updates
554
551
# Need to commit first, otherwise submodule.update wouldn't have a reason to change the head
555
- touch (os . path .join (nsm .module ().working_tree_dir , 'new-file' ))
552
+ touch (osp .join (nsm .module ().working_tree_dir , 'new-file' ))
556
553
# We cannot expect is_dirty to even run as we wouldn't reset a head to the same location
557
554
assert nsm .module ().head .commit .hexsha == nsm .hexsha
558
555
nsm .module ().index .add ([nsm ])
@@ -574,7 +571,7 @@ def test_root_module(self, rwrepo):
574
571
# ... to the first repository, this way we have a fast checkout, and a completely different
575
572
# repository at the different url
576
573
nsm .set_parent_commit (csmremoved )
577
- nsmurl = to_native_path_linux ( join_path_native (self .rorepo .working_tree_dir , rsmsp [0 ]))
574
+ nsmurl = Git . polish_url ( osp . join (self .rorepo .working_tree_dir , rsmsp [0 ]))
578
575
with nsm .config_writer () as writer :
579
576
writer .set_value ('url' , nsmurl )
580
577
csmpathchange = rwrepo .index .commit ("changed url" )
@@ -648,21 +645,21 @@ def test_first_submodule(self, rwrepo):
648
645
assert len (list (rwrepo .iter_submodules ())) == 0
649
646
650
647
for sm_name , sm_path in (('first' , 'submodules/first' ),
651
- ('second' , os . path .join (rwrepo .working_tree_dir , 'submodules/second' ))):
648
+ ('second' , osp .join (rwrepo .working_tree_dir , 'submodules/second' ))):
652
649
sm = rwrepo .create_submodule (sm_name , sm_path , rwrepo .git_dir , no_checkout = True )
653
650
assert sm .exists () and sm .module_exists ()
654
651
rwrepo .index .commit ("Added submodule " + sm_name )
655
652
# end for each submodule path to add
656
653
657
- self .failUnlessRaises (ValueError , rwrepo .create_submodule , 'fail' , os . path .expanduser ('~' ))
654
+ self .failUnlessRaises (ValueError , rwrepo .create_submodule , 'fail' , osp .expanduser ('~' ))
658
655
self .failUnlessRaises (ValueError , rwrepo .create_submodule , 'fail-too' ,
659
- rwrepo .working_tree_dir + os . path .sep )
656
+ rwrepo .working_tree_dir + osp .sep )
660
657
661
658
@with_rw_directory
662
659
def test_add_empty_repo (self , rwdir ):
663
- empty_repo_dir = os . path .join (rwdir , 'empty-repo' )
660
+ empty_repo_dir = osp .join (rwdir , 'empty-repo' )
664
661
665
- parent = git .Repo .init (os . path .join (rwdir , 'parent' ))
662
+ parent = git .Repo .init (osp .join (rwdir , 'parent' ))
666
663
git .Repo .init (empty_repo_dir )
667
664
668
665
for checkout_mode in range (2 ):
@@ -673,7 +670,7 @@ def test_add_empty_repo(self, rwdir):
673
670
674
671
@with_rw_directory
675
672
def test_git_submodules_and_add_sm_with_new_commit (self , rwdir ):
676
- parent = git .Repo .init (os . path .join (rwdir , 'parent' ))
673
+ parent = git .Repo .init (osp .join (rwdir , 'parent' ))
677
674
parent .git .submodule ('add' , self ._small_repo_url (), 'module' )
678
675
parent .index .commit ("added submodule" )
679
676
@@ -683,7 +680,7 @@ def test_git_submodules_and_add_sm_with_new_commit(self, rwdir):
683
680
assert sm .exists () and sm .module_exists ()
684
681
685
682
clone = git .Repo .clone_from (self ._small_repo_url (),
686
- os . path .join (parent .working_tree_dir , 'existing-subrepository' ))
683
+ osp .join (parent .working_tree_dir , 'existing-subrepository' ))
687
684
sm2 = parent .create_submodule ('nongit-file-submodule' , clone .working_tree_dir )
688
685
assert len (parent .submodules ) == 2
689
686
@@ -700,7 +697,7 @@ def test_git_submodules_and_add_sm_with_new_commit(self, rwdir):
700
697
parent .index .commit ("moved submodules" )
701
698
702
699
smm = sm .module ()
703
- fp = os . path .join (smm .working_tree_dir , 'empty-file' )
700
+ fp = osp .join (smm .working_tree_dir , 'empty-file' )
704
701
with open (fp , 'w' ):
705
702
pass
706
703
smm .git .add (fp )
@@ -733,7 +730,7 @@ def test_git_submodules_and_add_sm_with_new_commit(self, rwdir):
733
730
# "'C:\\Users\\appveyor\\AppData\\Local\\Temp\\1\\test_work_tree_unsupportedryfa60di\\master_repo\\.git\\objects\\pack\\pack-bc9e0787aef9f69e1591ef38ea0a6f566ec66fe3.idx") # noqa E501
734
731
@with_rw_directory
735
732
def test_git_submodule_compatibility (self , rwdir ):
736
- parent = git .Repo .init (os . path .join (rwdir , 'parent' ))
733
+ parent = git .Repo .init (osp .join (rwdir , 'parent' ))
737
734
sm_path = join_path_native ('submodules' , 'intermediate' , 'one' )
738
735
sm = parent .create_submodule ('mymodules/myname' , sm_path , url = self ._small_repo_url ())
739
736
parent .index .commit ("added submodule" )
@@ -747,13 +744,13 @@ def assert_exists(sm, value=True):
747
744
# muss it up. That's the only reason why the test is still here ... .
748
745
assert len (parent .git .submodule ().splitlines ()) == 1
749
746
750
- module_repo_path = os . path .join (sm .module ().working_tree_dir , '.git' )
751
- assert module_repo_path .startswith (os . path .join (parent .working_tree_dir , sm_path ))
747
+ module_repo_path = osp .join (sm .module ().working_tree_dir , '.git' )
748
+ assert module_repo_path .startswith (osp .join (parent .working_tree_dir , sm_path ))
752
749
if not sm ._need_gitfile_submodules (parent .git ):
753
- assert os . path .isdir (module_repo_path )
750
+ assert osp .isdir (module_repo_path )
754
751
assert not sm .module ().has_separate_working_tree ()
755
752
else :
756
- assert os . path .isfile (module_repo_path )
753
+ assert osp .isfile (module_repo_path )
757
754
assert sm .module ().has_separate_working_tree ()
758
755
assert find_git_dir (module_repo_path ) is not None , "module pointed to by .git file must be valid"
759
756
# end verify submodule 'style'
@@ -803,12 +800,12 @@ def assert_exists(sm, value=True):
803
800
for dry_run in (True , False ):
804
801
sm .remove (dry_run = dry_run , force = True )
805
802
assert_exists (sm , value = dry_run )
806
- assert os . path .isdir (sm_module_path ) == dry_run
803
+ assert osp .isdir (sm_module_path ) == dry_run
807
804
# end for each dry-run mode
808
805
809
806
@with_rw_directory
810
807
def test_remove_norefs (self , rwdir ):
811
- parent = git .Repo .init (os . path .join (rwdir , 'parent' ))
808
+ parent = git .Repo .init (osp .join (rwdir , 'parent' ))
812
809
sm_name = 'mymodules/myname'
813
810
sm = parent .create_submodule (sm_name , sm_name , url = self ._small_repo_url ())
814
811
assert sm .exists ()
@@ -817,7 +814,7 @@ def test_remove_norefs(self, rwdir):
817
814
818
815
assert sm .repo is parent # yoh was surprised since expected sm repo!!
819
816
# so created a new instance for submodule
820
- smrepo = git .Repo (os . path .join (rwdir , 'parent' , sm .path ))
817
+ smrepo = git .Repo (osp .join (rwdir , 'parent' , sm .path ))
821
818
# Adding a remote without fetching so would have no references
822
819
smrepo .create_remote ('special' , 'git@server-shouldnotmatter:repo.git' )
823
820
# And we should be able to remove it just fine
@@ -826,7 +823,7 @@ def test_remove_norefs(self, rwdir):
826
823
827
824
@with_rw_directory
828
825
def test_rename (self , rwdir ):
829
- parent = git .Repo .init (os . path .join (rwdir , 'parent' ))
826
+ parent = git .Repo .init (osp .join (rwdir , 'parent' ))
830
827
sm_name = 'mymodules/myname'
831
828
sm = parent .create_submodule (sm_name , sm_name , url = self ._small_repo_url ())
832
829
parent .index .commit ("Added submodule" )
@@ -843,7 +840,7 @@ def test_rename(self, rwdir):
843
840
assert sm .exists ()
844
841
845
842
sm_mod = sm .module ()
846
- if os . path . isfile (os . path .join (sm_mod .working_tree_dir , '.git' )) == sm ._need_gitfile_submodules (parent .git ):
843
+ if osp . isfile (osp .join (sm_mod .working_tree_dir , '.git' )) == sm ._need_gitfile_submodules (parent .git ):
847
844
assert sm_mod .git_dir .endswith (join_path_native ('.git' , 'modules' , new_sm_name ))
848
845
# end
849
846
@@ -852,8 +849,8 @@ def test_branch_renames(self, rw_dir):
852
849
# Setup initial sandbox:
853
850
# parent repo has one submodule, which has all the latest changes
854
851
source_url = self ._small_repo_url ()
855
- sm_source_repo = git .Repo .clone_from (source_url , os . path .join (rw_dir , 'sm-source' ), b = 'master' )
856
- parent_repo = git .Repo .init (os . path .join (rw_dir , 'parent' ))
852
+ sm_source_repo = git .Repo .clone_from (source_url , osp .join (rw_dir , 'sm-source' ), b = 'master' )
853
+ parent_repo = git .Repo .init (osp .join (rw_dir , 'parent' ))
857
854
sm = parent_repo .create_submodule ('mysubmodule' , 'subdir/submodule' ,
858
855
sm_source_repo .working_tree_dir , branch = 'master' )
859
856
parent_repo .index .commit ('added submodule' )
@@ -862,7 +859,7 @@ def test_branch_renames(self, rw_dir):
862
859
# Create feature branch with one new commit in submodule source
863
860
sm_fb = sm_source_repo .create_head ('feature' )
864
861
sm_fb .checkout ()
865
- new_file = touch (os . path .join (sm_source_repo .working_tree_dir , 'new-file' ))
862
+ new_file = touch (osp .join (sm_source_repo .working_tree_dir , 'new-file' ))
866
863
sm_source_repo .index .add ([new_file ])
867
864
sm .repo .index .commit ("added new file" )
868
865
@@ -888,7 +885,7 @@ def test_branch_renames(self, rw_dir):
888
885
# To make it even 'harder', we shall fork and create a new commit
889
886
sm_pfb = sm_source_repo .create_head ('past-feature' , commit = 'HEAD~20' )
890
887
sm_pfb .checkout ()
891
- sm_source_repo .index .add ([touch (os . path .join (sm_source_repo .working_tree_dir , 'new-file' ))])
888
+ sm_source_repo .index .add ([touch (osp .join (sm_source_repo .working_tree_dir , 'new-file' ))])
892
889
sm_source_repo .index .commit ("new file added, to past of '%r'" % sm_fb )
893
890
894
891
# Change designated submodule checkout branch to a new commit in its own past
@@ -897,7 +894,7 @@ def test_branch_renames(self, rw_dir):
897
894
sm .repo .index .commit ("changed submodule branch to '%s'" % sm_pfb )
898
895
899
896
# Test submodule updates - must fail if submodule is dirty
900
- touch (os . path .join (sm_mod .working_tree_dir , 'unstaged file' ))
897
+ touch (osp .join (sm_mod .working_tree_dir , 'unstaged file' ))
901
898
# This doesn't fail as our own submodule binsha didn't change, and the reset is only triggered if
902
899
# to latest revision is True.
903
900
parent_repo .submodule_update (to_latest_revision = False )
0 commit comments