-
-
Notifications
You must be signed in to change notification settings - Fork 3.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4052 from stsewd/use-git-python-for-tags
Use gitpython for tags
- Loading branch information
Showing
4 changed files
with
69 additions
and
96 deletions.
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