Skip to content

BUG: handle git-describe failing to find a tag - #149

Merged
slivingston merged 1 commit into
python-control:masterfrom
roryyorke:rory/no-git-tag
Jun 26, 2017
Merged

slivingston merged 1 commit into
python-control:masterfrom
roryyorke:rory/no-git-tag

Conversation

@roryyorke

Copy link
Copy Markdown
Contributor

This can happen with shallow clones, e.g., on Travis-CI.

This bit me here; basically, Travis-CI by default does a depth-50 clone, and the 0.7.0 tag wasn't within that.

While there are other workarounds (increasing depth, etc.), a simple fallback for when git describe fails to produce a full version description is a reasonable idea.

@coveralls

coveralls commented Jun 23, 2017 •

Copy link
Copy Markdown

Coverage Status

Coverage remained the same at 77.674% when pulling a31a5a7 on roryyorke:rory/no-git-tag into 55878a3 on python-control:master.

@slivingston slivingston self-assigned this Jun 25, 2017

@slivingston slivingston left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Besides my comment about the type of commit, I think that this change is good.

There is a security concern of code injection from check_output combined with an instrumented git command. This concern existed before this PR but is somewhat amplified by it because the condition of len(output) == 3 is easier to skip over while preserving injected code. E.g.,

#!/bin/sh

echo '"; print("Hola!"); "'

If the above is placed in a file named git and the PATH is expanded appropriately, then imports of control will cause "Hola!" to be printed.

Comment thread make_version.py Outdated
# and https://github.com/travis-ci/travis-ci/issues/3412
version = 'unknown'
build = 'unknown'
commit = output

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be the following, given that split() always returns a list of strings?

commit = output[0]

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

or perhaps

commit = '-'.join(output)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, thanks -- I see control/_version.py has the line __commit__ = "['0ede87e']" in my test shallow clone.

On the '-'.join(output) form. I don't know if describe ever puts out a line with a single dash (I couldn't find definitive documentation), but if a tag has one or more dashes, .split will return a list with more than 3 elements (I just tested this with a fake tag to confirm it). I could replace the .split with .rsplit('-',2) to handle this case, and use '-'.join in the event that git describe outputs a line with only one dash.

I had never considered a security aspect here. I would have thought that since we're handling 'git describe' output as a string, and storing its results as a string in _make_version.py, there's not an obvious way to get code injection. (I don't know how __conda_version__.txt and __conda_buildnum__.txt are processed.) If we postulate a compromised git, wouldn't it be possible to do code injection when git clone is executed anyway?

A final point: how useful is this elaborate versioning? Why not just use '0.8.0a0+git' in setup.py until the 0.8.0 release is made? Or, alternatively, 0.8.0a0+git<commit-hash>, which is somewhat complex, but simpler than we have now.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that your updated changes are good.

Regarding security, the attack is still feasible with a correct git clone program if the repository itself is corrupted. However, like having a compromised git initially, this precondition is very difficult to satisfy, so I think that it is not critical to consider.

Regarding elaborate version strings, the basic argument for including the commit hash in nonrelease revisions is the existence of many users that work from repository clones rather than releases. In my experience, these users may git clone and then perform a system-wide installation, after which work proceeds from a different directory and the original clone directory may be deleted.

To include commit hashes or other data in the version string, PEP 440 defines developmental releases to facilitate this, which involves ".dev", e.g., as used in numpy.

In the case of python-control, creating a conda package involves a build number. I am not aware of a definition of this value, but at least two recommendations are:

  1. number of commits from most recent tag, http://conda-test.pydata.org/docs/build.html#environment-variables-set-during-the-build-process
  2. "the number of the build" (https://docs.continuum.io/docs_oss/conda/bdist_conda#build-number), which I guess implies every time conda build is used, this value should increment.

However, some projects just fix this value at 0 or 1, e.g., bison in the conda-recipes repo.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I performed the merge because changes from this PR are needed now, and we can continue discussion and possibly change the version string generation as a separate issue or pull request.

This can happen with shallow clones, e.g., on Travis-CI.
@coveralls

coveralls commented Jun 25, 2017 •

Copy link
Copy Markdown

Coverage Status

Coverage remained the same at 77.674% when pulling a2cc0b3 on roryyorke:rory/no-git-tag into 55878a3 on python-control:master.

@slivingston
slivingston merged commit a2cc0b3 into python-control:master Jun 26, 2017
slivingston added a commit that referenced this pull request Jun 26, 2017
"BUG: handle git-describe failing to find a tag"
#149
@roryyorke
roryyorke deleted the rory/no-git-tag branch July 1, 2017 04:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants