-
-
Notifications
You must be signed in to change notification settings - Fork 3.6k
More hints for invalid submodules #5012
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
ericholscher
merged 3 commits into
readthedocs:master
from
stsewd:more-hints-invalid-submodules
Dec 26, 2018
Merged
Changes from 2 commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,10 +2,15 @@ | |
"""Utility functions for use in tests.""" | ||
|
||
from __future__ import ( | ||
absolute_import, division, print_function, unicode_literals) | ||
absolute_import, | ||
division, | ||
print_function, | ||
unicode_literals, | ||
) | ||
|
||
import logging | ||
import subprocess | ||
import textwrap | ||
from os import chdir, environ, mkdir | ||
from os.path import abspath | ||
from os.path import join as pjoin | ||
|
@@ -55,34 +60,16 @@ def make_test_git(): | |
# URL are not allowed and using a real URL will require Internet to clone | ||
# the repo | ||
check_output(['git', 'checkout', '-b', 'submodule', 'master'], env=env) | ||
# https://stackoverflow.com/a/37378302/2187091 | ||
mkdir(pjoin(directory, 'foobar')) | ||
gitmodules_path = pjoin(directory, '.gitmodules') | ||
with open(gitmodules_path, 'w') as fh: | ||
fh.write('''[submodule "foobar"]\n\tpath = foobar\n\turl = https://foobar.com/git\n''') | ||
check_output( | ||
[ | ||
'git', 'update-index', '--add', '--cacheinfo', '160000', | ||
'233febf4846d7a0aeb95b6c28962e06e21d13688', 'foobar', | ||
], | ||
env=env, | ||
add_submodule_without_cloning( | ||
directory, 'foobar', 'https://foobar.com/git' | ||
) | ||
check_output(['git', 'add', '.'], env=env) | ||
check_output(['git', 'commit', '-m"Add submodule"'], env=env) | ||
|
||
# Add a relative submodule URL in the relativesubmodule branch | ||
check_output(['git', 'checkout', '-b', 'relativesubmodule', 'master'], env=env) | ||
check_output( | ||
['git', 'submodule', 'add', '-b', 'master', './', 'relativesubmodule'], | ||
env=env | ||
) | ||
check_output(['git', 'add', '.'], env=env) | ||
check_output(['git', 'commit', '-m"Add relative submodule"'], env=env) | ||
# Add an invalid submodule URL in the invalidsubmodule branch | ||
check_output(['git', 'checkout', '-b', 'invalidsubmodule', 'master'], env=env) | ||
check_output( | ||
['git', 'submodule', 'add', '-b', 'master', './', 'invalidsubmodule'], | ||
env=env, | ||
add_submodule_without_cloning( | ||
directory, 'invalid', '[email protected]:rtfd/readthedocs.org.git' | ||
) | ||
check_output(['git', 'add', '.'], env=env) | ||
check_output(['git', 'commit', '-m"Add invalid submodule"'], env=env) | ||
|
@@ -92,6 +79,36 @@ def make_test_git(): | |
return directory | ||
|
||
|
||
@restoring_chdir | ||
def add_submodule_without_cloning(directory, submodule, url): | ||
stsewd marked this conversation as resolved.
Show resolved
Hide resolved
|
||
""" | ||
Add a submodule without cloning it. | ||
|
||
We write directly to the git index, more details in: | ||
https://stackoverflow.com/a/37378302/2187091 | ||
""" | ||
env = environ.copy() | ||
env['GIT_DIR'] = pjoin(directory, '.git') | ||
chdir(directory) | ||
|
||
mkdir(pjoin(directory, submodule)) | ||
gitmodules_path = pjoin(directory, '.gitmodules') | ||
with open(gitmodules_path, 'w+') as fh: | ||
content = textwrap.dedent(''' | ||
[submodule "{submodule}"] | ||
path = {submodule} | ||
url = {url} | ||
''') | ||
fh.write(content.format(submodule=submodule, url=url)) | ||
check_output( | ||
[ | ||
'git', 'update-index', '--add', '--cacheinfo', '160000', | ||
'233febf4846d7a0aeb95b6c28962e06e21d13688', submodule, | ||
], | ||
env=env, | ||
) | ||
|
||
|
||
@restoring_chdir | ||
def make_git_repo(directory, name='sample_repo'): | ||
path = get_readthedocs_app_path() | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This wasn't creating the submodule as expected, and we have
add_submodule_without_cloning
now.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The previous test was passing bc we were creating the branch from one that already had a submodule