-
-
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
Use gitpython for tags #4052
Changes from 3 commits
02b447f
a096a03
ef619e7
5f5b51a
d050221
b659748
e3e5f87
851d2b8
a6a60d5
65409a8
472eadf
d3e3b5b
f4c53c8
fdba591
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,6 +22,7 @@ def check_output(l, env=()): | |
else: | ||
output = subprocess.Popen(l, stdout=subprocess.PIPE, | ||
env=env).communicate()[0] | ||
log.info(output) | ||
return output | ||
|
||
|
||
|
@@ -36,63 +37,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_tag(directory, tag, annotated=False): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
and I think that There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Directory makes reference to the tmp directory, and path is used for the cwd, |
||
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() | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -122,46 +122,12 @@ def clone(self): | |
|
||
@property | ||
def tags(self): | ||
retcode, stdout, _ = self.run( | ||
'git', | ||
'show-ref', | ||
'--tags', | ||
record_as_success=True, | ||
) | ||
# error (or no tags found) | ||
if retcode != 0: | ||
return [] | ||
return self.parse_tags(stdout) | ||
|
||
def parse_tags(self, data): | ||
""" | ||
Parses output of show-ref --tags, eg: | ||
|
||
3b32886c8d3cb815df3793b3937b2e91d0fb00f1 refs/tags/2.0.0 | ||
bd533a768ff661991a689d3758fcfe72f455435d refs/tags/2.0.1 | ||
c0288a17899b2c6818f74e3a90b77e2a1779f96a refs/tags/2.0.2 | ||
a63a2de628a3ce89034b7d1a5ca5e8159534eef0 refs/tags/2.1.0.beta2 | ||
c7fc3d16ed9dc0b19f0d27583ca661a64562d21e refs/tags/2.1.0.rc1 | ||
edc0a2d02a0cc8eae8b67a3a275f65cd126c05b1 refs/tags/2.1.0.rc2 | ||
|
||
Into VCSTag objects with the tag name as verbose_name and the commit | ||
hash as identifier. | ||
""" | ||
# parse the lines into a list of tuples (commit-hash, tag ref name) | ||
# StringIO below is expecting Unicode data, so ensure that it gets it. | ||
if not isinstance(data, str): | ||
data = str(data) | ||
delimiter = str(' ').encode('utf-8') if PY2 else str(' ') | ||
raw_tags = csv.reader(StringIO(data), delimiter=delimiter) | ||
vcs_tags = [] | ||
for row in raw_tags: | ||
row = [f for f in row if f != ''] | ||
if row == []: | ||
continue | ||
commit_hash, name = row | ||
clean_name = name.replace('refs/tags/', '') | ||
vcs_tags.append(VCSVersion(self, commit_hash, clean_name)) | ||
return vcs_tags | ||
repo = git.Repo(self.working_dir) | ||
versions = [ | ||
VCSVersion(self, str(tag.commit), str(tag)) | ||
for tag in repo.tags | ||
] | ||
return versions | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 commentThe reason will be displayed to describe this comment to others. Learn more. But no tests. |
||
|
||
@property | ||
def branches(self): | ||
|
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.
Why do we need to do this here?
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.
Because we don't make the
clone
part, so the vcs object will try to search the repo in/project/checkouts/...
. Sorry for the late reply, I was focused in fixin the unicode problem 😁