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

Commit508807e

Browse files
committed
Submodule.add() can now handle absolute module paths in agreement to the doc string.
Previously, it would say it can handle absolute module paths, but didn'tactually do so.A test-case was improved to check for this case.Fixesgitpython-developers#161
1 parentb259098 commit508807e

File tree

2 files changed

+22
-3
lines changed

2 files changed

+22
-3
lines changed

‎git/objects/submodule/base.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,17 @@ def add(cls, repo, name, path, url=None, branch=None, no_checkout=False):
238238
path=path[:-1]
239239
# END handle trailing slash
240240

241+
ifos.path.isabs(path):
242+
working_tree_linux=to_native_path_linux(repo.working_tree_dir)
243+
ifnotpath.startswith(working_tree_linux):
244+
raiseValueError("Submodule checkout path '%s' needs to be within the parents repository at '%s'"
245+
% (working_tree_linux,path))
246+
path=path[len(working_tree_linux)+1:]
247+
ifnotpath:
248+
raiseValueError("Absolute submodule path '%s' didn't yield a valid relative path"%path)
249+
# end verify converted relative path makes sense
250+
# end convert to a relative path
251+
241252
# assure we never put backslashes into the url, as some operating systems
242253
# like it ...
243254
ifurlisnotNone:

‎git/test/test_submodule.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -586,6 +586,14 @@ def test_root_module(self, rwrepo):
586586
@with_rw_repo(k_no_subm_tag,bare=False)
587587
deftest_first_submodule(self,rwrepo):
588588
assertlen(list(rwrepo.iter_submodules()))==0
589-
sm=rwrepo.create_submodule('first','submodules/first',rwrepo.git_dir,no_checkout=True)
590-
assertsm.exists()andsm.module_exists()
591-
rwrepo.index.commit("Added submodule")
589+
590+
forsm_name,sm_pathin (('first','submodules/first'),
591+
('second',os.path.join(rwrepo.working_tree_dir,'submodules/second'))):
592+
sm=rwrepo.create_submodule(sm_name,sm_path,rwrepo.git_dir,no_checkout=True)
593+
assertsm.exists()andsm.module_exists()
594+
rwrepo.index.commit("Added submodule "+sm_name)
595+
# end for each submodule path to add
596+
597+
self.failUnlessRaises(ValueError,rwrepo.create_submodule,'fail',os.path.expanduser('~'))
598+
self.failUnlessRaises(ValueError,rwrepo.create_submodule,'fail-too',
599+
rwrepo.working_tree_dir+os.path.sep)

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp