Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit49a8cdd

Browse files
committed
config,#525: polish more config-urls
1 parent6e56b3c commit49a8cdd

File tree

3 files changed

+46
-39
lines changed

3 files changed

+46
-39
lines changed

‎git/objects/submodule/base.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
fromunittest.caseimportSkipTest
4242
fromgit.utilimportHIDE_WINDOWS_KNOWN_ERRORS
4343
fromgit.objects.baseimportIndexObject,Object
44+
fromgit.cmdimportGit
4445

4546
__all__= ["Submodule","UpdateProgress"]
4647

@@ -394,6 +395,9 @@ def add(cls, repo, name, path, url=None, branch=None, no_checkout=False):
394395
mrepo=cls._clone_repo(repo,url,path,name,**kwargs)
395396
# END verify url
396397

398+
## See #525 for ensuring git urls in config-files valid under Windows.
399+
url=Git.polish_url(url)
400+
397401
# It's important to add the URL to the parent config, to let `git submodule` know.
398402
# otherwise there is a '-' character in front of the submodule listing
399403
# a38efa84daef914e4de58d1905a500d8d14aaf45 mymodule (v0.9.0-1-ga38efa8)

‎git/test/lib/helper.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ def case(self, rw_repo, rw_remote_repo)
214214
See working dir info in with_rw_repo
215215
:note: We attempt to launch our own invocation of git-daemon, which will be shutdown at the end of the test.
216216
"""
217-
fromgitimportGit,Remote
217+
fromgitimportGit,Remote# To avoid circular deps.
218218

219219
assertisinstance(working_tree_ref,string_types),"Decorator requires ref name for working tree checkout"
220220

@@ -250,7 +250,7 @@ def remote_repo_creator(self):
250250

251251
base_path,rel_repo_dir=osp.split(remote_repo_dir)
252252

253-
remote_repo_url="git://localhost:%s/%s"% (GIT_DAEMON_PORT,rel_repo_dir)
253+
remote_repo_url=Git.polish_url("git://localhost:%s/%s"% (GIT_DAEMON_PORT,rel_repo_dir))
254254
withd_remote.config_writerascw:
255255
cw.set('url',remote_repo_url)
256256

@@ -342,7 +342,8 @@ class TestBase(TestCase):
342342

343343
def_small_repo_url(self):
344344
""":return" a path to a small, clonable repository"""
345-
returnosp.join(self.rorepo.working_tree_dir,'git/ext/gitdb/gitdb/ext/smmap')
345+
fromgit.cmdimportGit
346+
returnGit.polish_url(osp.join(self.rorepo.working_tree_dir,'git/ext/gitdb/gitdb/ext/smmap'))
346347

347348
@classmethod
348349
defsetUpClass(cls):

‎git/test/test_submodule.py

Lines changed: 38 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
fromunittest.caseimportskipIf
66

77
importgit
8+
fromgit.cmdimportGit
89
fromgit.compatimportstring_types,is_win
910
fromgit.excimport (
1011
InvalidGitRepositoryError,
@@ -23,6 +24,7 @@
2324
fromgit.test.libimportwith_rw_directory
2425
fromgit.utilimportHIDE_WINDOWS_KNOWN_ERRORS
2526
fromgit.utilimportto_native_path_linux,join_path_native
27+
importos.pathasosp
2628

2729

2830
# Change the configuration if possible to prevent the underlying memory manager
@@ -111,7 +113,7 @@ def _do_base_tests(self, rwrepo):
111113
else:
112114
withsm.config_writer()aswriter:
113115
# 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))
115117
writer.set_value('url',new_smclone_path)
116118
writer.release()
117119
assertsm.config_reader().get_value('url')==new_smclone_path
@@ -168,7 +170,7 @@ def _do_base_tests(self, rwrepo):
168170
#################
169171

170172
# lets update it - its a recursive one too
171-
newdir=os.path.join(sm.abspath,'dir')
173+
newdir=osp.join(sm.abspath,'dir')
172174
os.makedirs(newdir)
173175

174176
# update fails if the path already exists non-empty
@@ -213,7 +215,7 @@ def _do_base_tests(self, rwrepo):
213215
csm_repopath=csm.path
214216

215217
# 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))
217219
withcsm.config_writer()aswriter:
218220
writer.set_value('url',new_csmclone_path)
219221
assertcsm.url==new_csmclone_path
@@ -301,7 +303,7 @@ def _do_base_tests(self, rwrepo):
301303
csm.update()
302304
assertcsm.module_exists()
303305
assertcsm.exists()
304-
assertos.path.isdir(csm.module().working_tree_dir)
306+
assertosp.isdir(csm.module().working_tree_dir)
305307

306308
# this would work
307309
assertsm.remove(force=True,dry_run=True)issm
@@ -354,15 +356,15 @@ def _do_base_tests(self, rwrepo):
354356
assertnsm.module_exists()
355357
assertnsm.exists()
356358
# its not checked out
357-
assertnotos.path.isfile(join_path_native(nsm.module().working_tree_dir,Submodule.k_modules_file))
359+
assertnotosp.isfile(join_path_native(nsm.module().working_tree_dir,Submodule.k_modules_file))
358360
assertlen(rwrepo.submodules)==1
359361

360362
# add another submodule, but into the root, not as submodule
361363
osm=Submodule.add(rwrepo,osmid,csm_repopath,new_csmclone_path,Submodule.k_head_default)
362364
assertosm!=nsm
363365
assertosm.module_exists()
364366
assertosm.exists()
365-
assertos.path.isfile(join_path_native(osm.module().working_tree_dir,'setup.py'))
367+
assertosp.isfile(join_path_native(osm.module().working_tree_dir,'setup.py'))
366368

367369
assertlen(rwrepo.submodules)==2
368370

@@ -479,7 +481,7 @@ def test_root_module(self, rwrepo):
479481

480482
# assure we clone from a local source
481483
withsm.config_writer()aswriter:
482-
writer.set_value('url',to_native_path_linux(join_path_native(self.rorepo.working_tree_dir,sm.path)))
484+
writer.set_value('url',Git.polish_url(osp.join(self.rorepo.working_tree_dir,sm.path)))
483485

484486
# dry-run does nothing
485487
sm.update(recursive=False,dry_run=True,progress=prog)
@@ -513,7 +515,7 @@ def test_root_module(self, rwrepo):
513515
#================
514516
nsmn="newsubmodule"
515517
nsmp="submrepo"
516-
subrepo_url=to_native_path_linux(join_path_native(self.rorepo.working_tree_dir,rsmsp[0],rsmsp[1]))
518+
subrepo_url=Git.polish_url(osp.join(self.rorepo.working_tree_dir,rsmsp[0],rsmsp[1]))
517519
nsm=Submodule.add(rwrepo,nsmn,nsmp,url=subrepo_url)
518520
csmadded=rwrepo.index.commit("Added submodule").hexsha# make sure we don't keep the repo reference
519521
nsm.set_parent_commit(csmadded)
@@ -535,24 +537,24 @@ def test_root_module(self, rwrepo):
535537
sm.set_parent_commit(csmadded)
536538
smp=sm.abspath
537539
assertnotsm.remove(module=False).exists()
538-
assertos.path.isdir(smp)# module still exists
540+
assertosp.isdir(smp)# module still exists
539541
csmremoved=rwrepo.index.commit("Removed submodule")
540542

541543
# an update will remove the module
542544
# not in dry_run
543545
rm.update(recursive=False,dry_run=True,force_remove=True)
544-
assertos.path.isdir(smp)
546+
assertosp.isdir(smp)
545547

546548
# when removing submodules, we may get new commits as nested submodules are auto-committing changes
547549
# to allow deletions without force, as the index would be dirty otherwise.
548550
# QUESTION: Why does this seem to work in test_git_submodule_compatibility() ?
549551
self.failUnlessRaises(InvalidGitRepositoryError,rm.update,recursive=False,force_remove=False)
550552
rm.update(recursive=False,force_remove=True)
551-
assertnotos.path.isdir(smp)
553+
assertnotosp.isdir(smp)
552554

553555
# 'apply work' to the nested submodule and assure this is not removed/altered during updates
554556
# 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'))
557+
touch(osp.join(nsm.module().working_tree_dir,'new-file'))
556558
# We cannot expect is_dirty to even run as we wouldn't reset a head to the same location
557559
assertnsm.module().head.commit.hexsha==nsm.hexsha
558560
nsm.module().index.add([nsm])
@@ -574,7 +576,7 @@ def test_root_module(self, rwrepo):
574576
# ... to the first repository, this way we have a fast checkout, and a completely different
575577
# repository at the different url
576578
nsm.set_parent_commit(csmremoved)
577-
nsmurl=to_native_path_linux(join_path_native(self.rorepo.working_tree_dir,rsmsp[0]))
579+
nsmurl=Git.polish_url(osp.join(self.rorepo.working_tree_dir,rsmsp[0]))
578580
withnsm.config_writer()aswriter:
579581
writer.set_value('url',nsmurl)
580582
csmpathchange=rwrepo.index.commit("changed url")
@@ -648,21 +650,21 @@ def test_first_submodule(self, rwrepo):
648650
assertlen(list(rwrepo.iter_submodules()))==0
649651

650652
forsm_name,sm_pathin (('first','submodules/first'),
651-
('second',os.path.join(rwrepo.working_tree_dir,'submodules/second'))):
653+
('second',osp.join(rwrepo.working_tree_dir,'submodules/second'))):
652654
sm=rwrepo.create_submodule(sm_name,sm_path,rwrepo.git_dir,no_checkout=True)
653655
assertsm.exists()andsm.module_exists()
654656
rwrepo.index.commit("Added submodule "+sm_name)
655657
# end for each submodule path to add
656658

657-
self.failUnlessRaises(ValueError,rwrepo.create_submodule,'fail',os.path.expanduser('~'))
659+
self.failUnlessRaises(ValueError,rwrepo.create_submodule,'fail',osp.expanduser('~'))
658660
self.failUnlessRaises(ValueError,rwrepo.create_submodule,'fail-too',
659-
rwrepo.working_tree_dir+os.path.sep)
661+
rwrepo.working_tree_dir+osp.sep)
660662

661663
@with_rw_directory
662664
deftest_add_empty_repo(self,rwdir):
663-
empty_repo_dir=os.path.join(rwdir,'empty-repo')
665+
empty_repo_dir=osp.join(rwdir,'empty-repo')
664666

665-
parent=git.Repo.init(os.path.join(rwdir,'parent'))
667+
parent=git.Repo.init(osp.join(rwdir,'parent'))
666668
git.Repo.init(empty_repo_dir)
667669

668670
forcheckout_modeinrange(2):
@@ -673,7 +675,7 @@ def test_add_empty_repo(self, rwdir):
673675

674676
@with_rw_directory
675677
deftest_git_submodules_and_add_sm_with_new_commit(self,rwdir):
676-
parent=git.Repo.init(os.path.join(rwdir,'parent'))
678+
parent=git.Repo.init(osp.join(rwdir,'parent'))
677679
parent.git.submodule('add',self._small_repo_url(),'module')
678680
parent.index.commit("added submodule")
679681

@@ -683,7 +685,7 @@ def test_git_submodules_and_add_sm_with_new_commit(self, rwdir):
683685
assertsm.exists()andsm.module_exists()
684686

685687
clone=git.Repo.clone_from(self._small_repo_url(),
686-
os.path.join(parent.working_tree_dir,'existing-subrepository'))
688+
osp.join(parent.working_tree_dir,'existing-subrepository'))
687689
sm2=parent.create_submodule('nongit-file-submodule',clone.working_tree_dir)
688690
assertlen(parent.submodules)==2
689691

@@ -700,7 +702,7 @@ def test_git_submodules_and_add_sm_with_new_commit(self, rwdir):
700702
parent.index.commit("moved submodules")
701703

702704
smm=sm.module()
703-
fp=os.path.join(smm.working_tree_dir,'empty-file')
705+
fp=osp.join(smm.working_tree_dir,'empty-file')
704706
withopen(fp,'w'):
705707
pass
706708
smm.git.add(fp)
@@ -733,7 +735,7 @@ def test_git_submodules_and_add_sm_with_new_commit(self, rwdir):
733735
# "'C:\\Users\\appveyor\\AppData\\Local\\Temp\\1\\test_work_tree_unsupportedryfa60di\\master_repo\\.git\\objects\\pack\\pack-bc9e0787aef9f69e1591ef38ea0a6f566ec66fe3.idx") # noqa E501
734736
@with_rw_directory
735737
deftest_git_submodule_compatibility(self,rwdir):
736-
parent=git.Repo.init(os.path.join(rwdir,'parent'))
738+
parent=git.Repo.init(osp.join(rwdir,'parent'))
737739
sm_path=join_path_native('submodules','intermediate','one')
738740
sm=parent.create_submodule('mymodules/myname',sm_path,url=self._small_repo_url())
739741
parent.index.commit("added submodule")
@@ -747,13 +749,13 @@ def assert_exists(sm, value=True):
747749
# muss it up. That's the only reason why the test is still here ... .
748750
assertlen(parent.git.submodule().splitlines())==1
749751

750-
module_repo_path=os.path.join(sm.module().working_tree_dir,'.git')
751-
assertmodule_repo_path.startswith(os.path.join(parent.working_tree_dir,sm_path))
752+
module_repo_path=osp.join(sm.module().working_tree_dir,'.git')
753+
assertmodule_repo_path.startswith(osp.join(parent.working_tree_dir,sm_path))
752754
ifnotsm._need_gitfile_submodules(parent.git):
753-
assertos.path.isdir(module_repo_path)
755+
assertosp.isdir(module_repo_path)
754756
assertnotsm.module().has_separate_working_tree()
755757
else:
756-
assertos.path.isfile(module_repo_path)
758+
assertosp.isfile(module_repo_path)
757759
assertsm.module().has_separate_working_tree()
758760
assertfind_git_dir(module_repo_path)isnotNone,"module pointed to by .git file must be valid"
759761
# end verify submodule 'style'
@@ -803,12 +805,12 @@ def assert_exists(sm, value=True):
803805
fordry_runin (True,False):
804806
sm.remove(dry_run=dry_run,force=True)
805807
assert_exists(sm,value=dry_run)
806-
assertos.path.isdir(sm_module_path)==dry_run
808+
assertosp.isdir(sm_module_path)==dry_run
807809
# end for each dry-run mode
808810

809811
@with_rw_directory
810812
deftest_remove_norefs(self,rwdir):
811-
parent=git.Repo.init(os.path.join(rwdir,'parent'))
813+
parent=git.Repo.init(osp.join(rwdir,'parent'))
812814
sm_name='mymodules/myname'
813815
sm=parent.create_submodule(sm_name,sm_name,url=self._small_repo_url())
814816
assertsm.exists()
@@ -817,7 +819,7 @@ def test_remove_norefs(self, rwdir):
817819

818820
assertsm.repoisparent# yoh was surprised since expected sm repo!!
819821
# so created a new instance for submodule
820-
smrepo=git.Repo(os.path.join(rwdir,'parent',sm.path))
822+
smrepo=git.Repo(osp.join(rwdir,'parent',sm.path))
821823
# Adding a remote without fetching so would have no references
822824
smrepo.create_remote('special','git@server-shouldnotmatter:repo.git')
823825
# And we should be able to remove it just fine
@@ -826,7 +828,7 @@ def test_remove_norefs(self, rwdir):
826828

827829
@with_rw_directory
828830
deftest_rename(self,rwdir):
829-
parent=git.Repo.init(os.path.join(rwdir,'parent'))
831+
parent=git.Repo.init(osp.join(rwdir,'parent'))
830832
sm_name='mymodules/myname'
831833
sm=parent.create_submodule(sm_name,sm_name,url=self._small_repo_url())
832834
parent.index.commit("Added submodule")
@@ -843,7 +845,7 @@ def test_rename(self, rwdir):
843845
assertsm.exists()
844846

845847
sm_mod=sm.module()
846-
ifos.path.isfile(os.path.join(sm_mod.working_tree_dir,'.git'))==sm._need_gitfile_submodules(parent.git):
848+
ifosp.isfile(osp.join(sm_mod.working_tree_dir,'.git'))==sm._need_gitfile_submodules(parent.git):
847849
assertsm_mod.git_dir.endswith(join_path_native('.git','modules',new_sm_name))
848850
# end
849851

@@ -852,8 +854,8 @@ def test_branch_renames(self, rw_dir):
852854
# Setup initial sandbox:
853855
# parent repo has one submodule, which has all the latest changes
854856
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'))
857+
sm_source_repo=git.Repo.clone_from(source_url,osp.join(rw_dir,'sm-source'),b='master')
858+
parent_repo=git.Repo.init(osp.join(rw_dir,'parent'))
857859
sm=parent_repo.create_submodule('mysubmodule','subdir/submodule',
858860
sm_source_repo.working_tree_dir,branch='master')
859861
parent_repo.index.commit('added submodule')
@@ -862,7 +864,7 @@ def test_branch_renames(self, rw_dir):
862864
# Create feature branch with one new commit in submodule source
863865
sm_fb=sm_source_repo.create_head('feature')
864866
sm_fb.checkout()
865-
new_file=touch(os.path.join(sm_source_repo.working_tree_dir,'new-file'))
867+
new_file=touch(osp.join(sm_source_repo.working_tree_dir,'new-file'))
866868
sm_source_repo.index.add([new_file])
867869
sm.repo.index.commit("added new file")
868870

@@ -888,7 +890,7 @@ def test_branch_renames(self, rw_dir):
888890
# To make it even 'harder', we shall fork and create a new commit
889891
sm_pfb=sm_source_repo.create_head('past-feature',commit='HEAD~20')
890892
sm_pfb.checkout()
891-
sm_source_repo.index.add([touch(os.path.join(sm_source_repo.working_tree_dir,'new-file'))])
893+
sm_source_repo.index.add([touch(osp.join(sm_source_repo.working_tree_dir,'new-file'))])
892894
sm_source_repo.index.commit("new file added, to past of '%r'"%sm_fb)
893895

894896
# Change designated submodule checkout branch to a new commit in its own past
@@ -897,7 +899,7 @@ def test_branch_renames(self, rw_dir):
897899
sm.repo.index.commit("changed submodule branch to '%s'"%sm_pfb)
898900

899901
# Test submodule updates - must fail if submodule is dirty
900-
touch(os.path.join(sm_mod.working_tree_dir,'unstaged file'))
902+
touch(osp.join(sm_mod.working_tree_dir,'unstaged file'))
901903
# This doesn't fail as our own submodule binsha didn't change, and the reset is only triggered if
902904
# to latest revision is True.
903905
parent_repo.submodule_update(to_latest_revision=False)

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp