Skip to content

Commit 6486b8c

Browse files
committed
config, #525: polish more config-urls
+ FIXED also `TestSubmodule.test_root_module()`!
1 parent 6d441c9 commit 6486b8c

File tree

3 files changed

+46
-46
lines changed

3 files changed

+46
-46
lines changed

git/objects/submodule/base.py

+4
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
from unittest.case import SkipTest
4242
from git.util import HIDE_WINDOWS_KNOWN_ERRORS
4343
from git.objects.base import IndexObject, Object
44+
from git.cmd import Git
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

+4-3
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-
from git import Git, Remote
217+
from git import Git, Remote # To avoid circular deps.
218218

219219
assert isinstance(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
with d_remote.config_writer as cw:
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-
return osp.join(self.rorepo.working_tree_dir, 'git/ext/gitdb/gitdb/ext/smmap')
345+
from git.cmd import Git
346+
return Git.polish_url(osp.join(self.rorepo.working_tree_dir, 'git/ext/gitdb/gitdb/ext/smmap'))
346347

347348
@classmethod
348349
def setUpClass(cls):

git/test/test_submodule.py

+38-43
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22
# the BSD License: http://www.opensource.org/licenses/bsd-license.php
33
import os
44
import sys
5-
from unittest.case import skipIf
65

76
import git
7+
from git.cmd import Git
88
from git.compat import string_types, is_win
99
from git.exc import (
1010
InvalidGitRepositoryError,
@@ -21,8 +21,8 @@
2121
with_rw_repo
2222
)
2323
from git.test.lib import with_rw_directory
24-
from git.util import HIDE_WINDOWS_KNOWN_ERRORS
2524
from git.util import to_native_path_linux, join_path_native
25+
import os.path as osp
2626

2727

2828
# Change the configuration if possible to prevent the underlying memory manager
@@ -111,7 +111,7 @@ def _do_base_tests(self, rwrepo):
111111
else:
112112
with sm.config_writer() as writer:
113113
# 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))
114+
new_smclone_path = Git.polish_url(osp.join(self.rorepo.working_tree_dir, sm.path))
115115
writer.set_value('url', new_smclone_path)
116116
writer.release()
117117
assert sm.config_reader().get_value('url') == new_smclone_path
@@ -168,7 +168,7 @@ def _do_base_tests(self, rwrepo):
168168
#################
169169

170170
# lets update it - its a recursive one too
171-
newdir = os.path.join(sm.abspath, 'dir')
171+
newdir = osp.join(sm.abspath, 'dir')
172172
os.makedirs(newdir)
173173

174174
# update fails if the path already exists non-empty
@@ -213,7 +213,7 @@ def _do_base_tests(self, rwrepo):
213213
csm_repopath = csm.path
214214

215215
# 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))
216+
new_csmclone_path = Git.polish_url(osp.join(self.rorepo.working_tree_dir, sm.path, csm.path))
217217
with csm.config_writer() as writer:
218218
writer.set_value('url', new_csmclone_path)
219219
assert csm.url == new_csmclone_path
@@ -301,7 +301,7 @@ def _do_base_tests(self, rwrepo):
301301
csm.update()
302302
assert csm.module_exists()
303303
assert csm.exists()
304-
assert os.path.isdir(csm.module().working_tree_dir)
304+
assert osp.isdir(csm.module().working_tree_dir)
305305

306306
# this would work
307307
assert sm.remove(force=True, dry_run=True) is sm
@@ -354,15 +354,15 @@ def _do_base_tests(self, rwrepo):
354354
assert nsm.module_exists()
355355
assert nsm.exists()
356356
# its not checked out
357-
assert not os.path.isfile(join_path_native(nsm.module().working_tree_dir, Submodule.k_modules_file))
357+
assert not osp.isfile(join_path_native(nsm.module().working_tree_dir, Submodule.k_modules_file))
358358
assert len(rwrepo.submodules) == 1
359359

360360
# add another submodule, but into the root, not as submodule
361361
osm = Submodule.add(rwrepo, osmid, csm_repopath, new_csmclone_path, Submodule.k_head_default)
362362
assert osm != nsm
363363
assert osm.module_exists()
364364
assert osm.exists()
365-
assert os.path.isfile(join_path_native(osm.module().working_tree_dir, 'setup.py'))
365+
assert osp.isfile(join_path_native(osm.module().working_tree_dir, 'setup.py'))
366366

367367
assert len(rwrepo.submodules) == 2
368368

@@ -430,11 +430,6 @@ def test_base_rw(self, rwrepo):
430430
def test_base_bare(self, rwrepo):
431431
self._do_base_tests(rwrepo)
432432

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\appveyor\AppData\Local\Temp\1\tmplyp6kr_rnon_bare_test_root_module""") # noqa E501
438433
@with_rw_repo(k_subm_current, bare=False)
439434
def test_root_module(self, rwrepo):
440435
# Can query everything without problems
@@ -479,7 +474,7 @@ def test_root_module(self, rwrepo):
479474

480475
# assure we clone from a local source
481476
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)))
477+
writer.set_value('url', Git.polish_url(osp.join(self.rorepo.working_tree_dir, sm.path)))
483478

484479
# dry-run does nothing
485480
sm.update(recursive=False, dry_run=True, progress=prog)
@@ -513,7 +508,7 @@ def test_root_module(self, rwrepo):
513508
#================
514509
nsmn = "newsubmodule"
515510
nsmp = "submrepo"
516-
subrepo_url = to_native_path_linux(join_path_native(self.rorepo.working_tree_dir, rsmsp[0], rsmsp[1]))
511+
subrepo_url = Git.polish_url(osp.join(self.rorepo.working_tree_dir, rsmsp[0], rsmsp[1]))
517512
nsm = Submodule.add(rwrepo, nsmn, nsmp, url=subrepo_url)
518513
csmadded = rwrepo.index.commit("Added submodule").hexsha # make sure we don't keep the repo reference
519514
nsm.set_parent_commit(csmadded)
@@ -535,24 +530,24 @@ def test_root_module(self, rwrepo):
535530
sm.set_parent_commit(csmadded)
536531
smp = sm.abspath
537532
assert not sm.remove(module=False).exists()
538-
assert os.path.isdir(smp) # module still exists
533+
assert osp.isdir(smp) # module still exists
539534
csmremoved = rwrepo.index.commit("Removed submodule")
540535

541536
# an update will remove the module
542537
# not in dry_run
543538
rm.update(recursive=False, dry_run=True, force_remove=True)
544-
assert os.path.isdir(smp)
539+
assert osp.isdir(smp)
545540

546541
# when removing submodules, we may get new commits as nested submodules are auto-committing changes
547542
# to allow deletions without force, as the index would be dirty otherwise.
548543
# QUESTION: Why does this seem to work in test_git_submodule_compatibility() ?
549544
self.failUnlessRaises(InvalidGitRepositoryError, rm.update, recursive=False, force_remove=False)
550545
rm.update(recursive=False, force_remove=True)
551-
assert not os.path.isdir(smp)
546+
assert not osp.isdir(smp)
552547

553548
# 'apply work' to the nested submodule and assure this is not removed/altered during updates
554549
# 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'))
550+
touch(osp.join(nsm.module().working_tree_dir, 'new-file'))
556551
# We cannot expect is_dirty to even run as we wouldn't reset a head to the same location
557552
assert nsm.module().head.commit.hexsha == nsm.hexsha
558553
nsm.module().index.add([nsm])
@@ -574,7 +569,7 @@ def test_root_module(self, rwrepo):
574569
# ... to the first repository, this way we have a fast checkout, and a completely different
575570
# repository at the different url
576571
nsm.set_parent_commit(csmremoved)
577-
nsmurl = to_native_path_linux(join_path_native(self.rorepo.working_tree_dir, rsmsp[0]))
572+
nsmurl = Git.polish_url(osp.join(self.rorepo.working_tree_dir, rsmsp[0]))
578573
with nsm.config_writer() as writer:
579574
writer.set_value('url', nsmurl)
580575
csmpathchange = rwrepo.index.commit("changed url")
@@ -648,21 +643,21 @@ def test_first_submodule(self, rwrepo):
648643
assert len(list(rwrepo.iter_submodules())) == 0
649644

650645
for sm_name, sm_path in (('first', 'submodules/first'),
651-
('second', os.path.join(rwrepo.working_tree_dir, 'submodules/second'))):
646+
('second', osp.join(rwrepo.working_tree_dir, 'submodules/second'))):
652647
sm = rwrepo.create_submodule(sm_name, sm_path, rwrepo.git_dir, no_checkout=True)
653648
assert sm.exists() and sm.module_exists()
654649
rwrepo.index.commit("Added submodule " + sm_name)
655650
# end for each submodule path to add
656651

657-
self.failUnlessRaises(ValueError, rwrepo.create_submodule, 'fail', os.path.expanduser('~'))
652+
self.failUnlessRaises(ValueError, rwrepo.create_submodule, 'fail', osp.expanduser('~'))
658653
self.failUnlessRaises(ValueError, rwrepo.create_submodule, 'fail-too',
659-
rwrepo.working_tree_dir + os.path.sep)
654+
rwrepo.working_tree_dir + osp.sep)
660655

661656
@with_rw_directory
662657
def test_add_empty_repo(self, rwdir):
663-
empty_repo_dir = os.path.join(rwdir, 'empty-repo')
658+
empty_repo_dir = osp.join(rwdir, 'empty-repo')
664659

665-
parent = git.Repo.init(os.path.join(rwdir, 'parent'))
660+
parent = git.Repo.init(osp.join(rwdir, 'parent'))
666661
git.Repo.init(empty_repo_dir)
667662

668663
for checkout_mode in range(2):
@@ -673,7 +668,7 @@ def test_add_empty_repo(self, rwdir):
673668

674669
@with_rw_directory
675670
def test_git_submodules_and_add_sm_with_new_commit(self, rwdir):
676-
parent = git.Repo.init(os.path.join(rwdir, 'parent'))
671+
parent = git.Repo.init(osp.join(rwdir, 'parent'))
677672
parent.git.submodule('add', self._small_repo_url(), 'module')
678673
parent.index.commit("added submodule")
679674

@@ -683,7 +678,7 @@ def test_git_submodules_and_add_sm_with_new_commit(self, rwdir):
683678
assert sm.exists() and sm.module_exists()
684679

685680
clone = git.Repo.clone_from(self._small_repo_url(),
686-
os.path.join(parent.working_tree_dir, 'existing-subrepository'))
681+
osp.join(parent.working_tree_dir, 'existing-subrepository'))
687682
sm2 = parent.create_submodule('nongit-file-submodule', clone.working_tree_dir)
688683
assert len(parent.submodules) == 2
689684

@@ -700,7 +695,7 @@ def test_git_submodules_and_add_sm_with_new_commit(self, rwdir):
700695
parent.index.commit("moved submodules")
701696

702697
smm = sm.module()
703-
fp = os.path.join(smm.working_tree_dir, 'empty-file')
698+
fp = osp.join(smm.working_tree_dir, 'empty-file')
704699
with open(fp, 'w'):
705700
pass
706701
smm.git.add(fp)
@@ -733,7 +728,7 @@ def test_git_submodules_and_add_sm_with_new_commit(self, rwdir):
733728
# "'C:\\Users\\appveyor\\AppData\\Local\\Temp\\1\\test_work_tree_unsupportedryfa60di\\master_repo\\.git\\objects\\pack\\pack-bc9e0787aef9f69e1591ef38ea0a6f566ec66fe3.idx") # noqa E501
734729
@with_rw_directory
735730
def test_git_submodule_compatibility(self, rwdir):
736-
parent = git.Repo.init(os.path.join(rwdir, 'parent'))
731+
parent = git.Repo.init(osp.join(rwdir, 'parent'))
737732
sm_path = join_path_native('submodules', 'intermediate', 'one')
738733
sm = parent.create_submodule('mymodules/myname', sm_path, url=self._small_repo_url())
739734
parent.index.commit("added submodule")
@@ -747,13 +742,13 @@ def assert_exists(sm, value=True):
747742
# muss it up. That's the only reason why the test is still here ... .
748743
assert len(parent.git.submodule().splitlines()) == 1
749744

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))
745+
module_repo_path = osp.join(sm.module().working_tree_dir, '.git')
746+
assert module_repo_path.startswith(osp.join(parent.working_tree_dir, sm_path))
752747
if not sm._need_gitfile_submodules(parent.git):
753-
assert os.path.isdir(module_repo_path)
748+
assert osp.isdir(module_repo_path)
754749
assert not sm.module().has_separate_working_tree()
755750
else:
756-
assert os.path.isfile(module_repo_path)
751+
assert osp.isfile(module_repo_path)
757752
assert sm.module().has_separate_working_tree()
758753
assert find_git_dir(module_repo_path) is not None, "module pointed to by .git file must be valid"
759754
# end verify submodule 'style'
@@ -803,12 +798,12 @@ def assert_exists(sm, value=True):
803798
for dry_run in (True, False):
804799
sm.remove(dry_run=dry_run, force=True)
805800
assert_exists(sm, value=dry_run)
806-
assert os.path.isdir(sm_module_path) == dry_run
801+
assert osp.isdir(sm_module_path) == dry_run
807802
# end for each dry-run mode
808803

809804
@with_rw_directory
810805
def test_remove_norefs(self, rwdir):
811-
parent = git.Repo.init(os.path.join(rwdir, 'parent'))
806+
parent = git.Repo.init(osp.join(rwdir, 'parent'))
812807
sm_name = 'mymodules/myname'
813808
sm = parent.create_submodule(sm_name, sm_name, url=self._small_repo_url())
814809
assert sm.exists()
@@ -817,7 +812,7 @@ def test_remove_norefs(self, rwdir):
817812

818813
assert sm.repo is parent # yoh was surprised since expected sm repo!!
819814
# so created a new instance for submodule
820-
smrepo = git.Repo(os.path.join(rwdir, 'parent', sm.path))
815+
smrepo = git.Repo(osp.join(rwdir, 'parent', sm.path))
821816
# Adding a remote without fetching so would have no references
822817
smrepo.create_remote('special', 'git@server-shouldnotmatter:repo.git')
823818
# And we should be able to remove it just fine
@@ -826,7 +821,7 @@ def test_remove_norefs(self, rwdir):
826821

827822
@with_rw_directory
828823
def test_rename(self, rwdir):
829-
parent = git.Repo.init(os.path.join(rwdir, 'parent'))
824+
parent = git.Repo.init(osp.join(rwdir, 'parent'))
830825
sm_name = 'mymodules/myname'
831826
sm = parent.create_submodule(sm_name, sm_name, url=self._small_repo_url())
832827
parent.index.commit("Added submodule")
@@ -843,7 +838,7 @@ def test_rename(self, rwdir):
843838
assert sm.exists()
844839

845840
sm_mod = sm.module()
846-
if os.path.isfile(os.path.join(sm_mod.working_tree_dir, '.git')) == sm._need_gitfile_submodules(parent.git):
841+
if osp.isfile(osp.join(sm_mod.working_tree_dir, '.git')) == sm._need_gitfile_submodules(parent.git):
847842
assert sm_mod.git_dir.endswith(join_path_native('.git', 'modules', new_sm_name))
848843
# end
849844

@@ -852,8 +847,8 @@ def test_branch_renames(self, rw_dir):
852847
# Setup initial sandbox:
853848
# parent repo has one submodule, which has all the latest changes
854849
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'))
850+
sm_source_repo = git.Repo.clone_from(source_url, osp.join(rw_dir, 'sm-source'), b='master')
851+
parent_repo = git.Repo.init(osp.join(rw_dir, 'parent'))
857852
sm = parent_repo.create_submodule('mysubmodule', 'subdir/submodule',
858853
sm_source_repo.working_tree_dir, branch='master')
859854
parent_repo.index.commit('added submodule')
@@ -862,7 +857,7 @@ def test_branch_renames(self, rw_dir):
862857
# Create feature branch with one new commit in submodule source
863858
sm_fb = sm_source_repo.create_head('feature')
864859
sm_fb.checkout()
865-
new_file = touch(os.path.join(sm_source_repo.working_tree_dir, 'new-file'))
860+
new_file = touch(osp.join(sm_source_repo.working_tree_dir, 'new-file'))
866861
sm_source_repo.index.add([new_file])
867862
sm.repo.index.commit("added new file")
868863

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

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

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

0 commit comments

Comments
 (0)