-
-
Notifications
You must be signed in to change notification settings - Fork 3.6k
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
Use gitpython for tags #4052
Merged
ericholscher
merged 14 commits into
readthedocs:master
from
stsewd:use-git-python-for-tags
May 29, 2018
+69
−96
Merged
Use gitpython for tags #4052
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
02b447f
Use gitpython for tags
stsewd a096a03
Move log to check_output
stsewd ef619e7
Add tests
stsewd 5f5b51a
Remove unicode test
stsewd d050221
Unicode test for python3 only
stsewd b659748
Refactor
stsewd e3e5f87
Trying to fix test on travis
stsewd 851d2b8
Fix unicode tests
stsewd a6a60d5
Try to fix travis... Again
stsewd 65409a8
Literal unicode
stsewd 472eadf
Use str from builtins
stsewd d3e3b5b
Remove universal_newlines
stsewd f4c53c8
Set magic environment variable
stsewd fdba591
Better comment
stsewd 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 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 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 |
---|---|---|
@@ -1,6 +1,6 @@ | ||
"""Utility functions for use in tests.""" | ||
|
||
from __future__ import absolute_import | ||
from __future__ import absolute_import, unicode_literals | ||
|
||
import logging | ||
import subprocess | ||
|
@@ -16,12 +16,12 @@ | |
log = logging.getLogger(__name__) | ||
|
||
|
||
def check_output(l, env=()): | ||
if env == (): | ||
output = subprocess.Popen(l, stdout=subprocess.PIPE).communicate()[0] | ||
else: | ||
output = subprocess.Popen(l, stdout=subprocess.PIPE, | ||
env=env).communicate()[0] | ||
def check_output(command, env=None): | ||
output = subprocess.Popen( | ||
command, stdout=subprocess.PIPE, stderr=subprocess.PIPE, | ||
env=env | ||
).communicate()[0] | ||
log.info(output) | ||
return output | ||
|
||
|
||
|
@@ -36,63 +36,76 @@ def make_test_git(): | |
chdir(directory) | ||
|
||
# Initialize and configure | ||
# TODO: move the ``log.info`` call inside the ``check_output``` | ||
log.info(check_output(['git', 'init'] + [directory], env=env)) | ||
log.info(check_output( | ||
check_output(['git', 'init'] + [directory], env=env) | ||
check_output( | ||
['git', 'config', 'user.email', '[email protected]'], | ||
env=env | ||
)) | ||
log.info(check_output( | ||
) | ||
check_output( | ||
['git', 'config', 'user.name', 'Read the Docs'], | ||
env=env | ||
)) | ||
) | ||
|
||
# Set up the actual repository | ||
log.info(check_output(['git', 'add', '.'], env=env)) | ||
log.info(check_output(['git', 'commit', '-m"init"'], env=env)) | ||
check_output(['git', 'add', '.'], env=env) | ||
check_output(['git', 'commit', '-m"init"'], env=env) | ||
|
||
# Add fake repo as submodule. We need to fake this here because local path | ||
# URL are not allowed and using a real URL will require Internet to clone | ||
# the repo | ||
log.info(check_output(['git', 'checkout', '-b', 'submodule', 'master'], env=env)) | ||
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''') | ||
log.info(check_output( | ||
check_output( | ||
[ | ||
'git', 'update-index', '--add', '--cacheinfo', '160000', | ||
'233febf4846d7a0aeb95b6c28962e06e21d13688', 'foobar', | ||
], | ||
env=env, | ||
)) | ||
log.info(check_output(['git', 'add', '.'], env=env)) | ||
log.info(check_output(['git', 'commit', '-m"Add submodule"'], env=env)) | ||
) | ||
check_output(['git', 'add', '.'], env=env) | ||
check_output(['git', 'commit', '-m"Add submodule"'], env=env) | ||
|
||
# Add a relative submodule URL in the relativesubmodule branch | ||
log.info(check_output(['git', 'checkout', '-b', 'relativesubmodule', 'master'], env=env)) | ||
log.info(check_output( | ||
check_output(['git', 'checkout', '-b', 'relativesubmodule', 'master'], env=env) | ||
check_output( | ||
['git', 'submodule', 'add', '-b', 'master', './', 'relativesubmodule'], | ||
env=env | ||
)) | ||
log.info(check_output(['git', 'add', '.'], env=env)) | ||
log.info(check_output(['git', 'commit', '-m"Add relative submodule"'], 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 | ||
log.info(check_output(['git', 'checkout', '-b', 'invalidsubmodule', 'master'], env=env)) | ||
log.info(check_output( | ||
check_output(['git', 'checkout', '-b', 'invalidsubmodule', 'master'], env=env) | ||
check_output( | ||
['git', 'submodule', 'add', '-b', 'master', './', 'invalidsubmodule'], | ||
env=env, | ||
)) | ||
log.info(check_output(['git', 'add', '.'], env=env)) | ||
log.info(check_output(['git', 'commit', '-m"Add invalid submodule"'], env=env)) | ||
) | ||
check_output(['git', 'add', '.'], env=env) | ||
check_output(['git', 'commit', '-m"Add invalid submodule"'], env=env) | ||
|
||
# Checkout to master branch again | ||
log.info(check_output(['git', 'checkout', 'master'], env=env)) | ||
check_output(['git', 'checkout', 'master'], env=env) | ||
chdir(path) | ||
return directory | ||
|
||
|
||
def create_git_tag(directory, tag, annotated=False): | ||
env = environ.copy() | ||
env['GIT_DIR'] = pjoin(directory, '.git') | ||
path = getcwd() | ||
chdir(directory) | ||
|
||
command = ['git', 'tag'] | ||
if annotated: | ||
command.extend(['-a', '-m', 'Some tag']) | ||
command.append(tag) | ||
check_output(command, env=env) | ||
chdir(path) | ||
|
||
|
||
def make_test_hg(): | ||
directory = mkdtemp() | ||
path = getcwd() | ||
|
This file contains 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 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.
❤️ so much cleaner and no csv parsing hacks!
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.
But no tests.