Get version from 'git describe' in the root of the source tree. This only gets called if the git-archive 'subst' keywords were *not* expanded, and _version.py hasn't already been rewritten with a short version string, meaning we're inside a checked out source tree.
(tag_prefix, root, verbose, runner=run_command)
| 1177 | |
| 1178 | @register_vcs_handler("git", "pieces_from_vcs") |
| 1179 | def git_pieces_from_vcs(tag_prefix, root, verbose, runner=run_command): |
| 1180 | """Get version from 'git describe' in the root of the source tree. |
| 1181 | |
| 1182 | This only gets called if the git-archive 'subst' keywords were *not* |
| 1183 | expanded, and _version.py hasn't already been rewritten with a short |
| 1184 | version string, meaning we're inside a checked out source tree. |
| 1185 | """ |
| 1186 | GITS = ["git"] |
| 1187 | if sys.platform == "win32": |
| 1188 | GITS = ["git.cmd", "git.exe"] |
| 1189 | |
| 1190 | # GIT_DIR can interfere with correct operation of Versioneer. |
| 1191 | # It may be intended to be passed to the Versioneer-versioned project, |
| 1192 | # but that should not change where we get our version from. |
| 1193 | env = os.environ.copy() |
| 1194 | env.pop("GIT_DIR", None) |
| 1195 | runner = functools.partial(runner, env=env) |
| 1196 | |
| 1197 | _, rc = runner(GITS, ["rev-parse", "--git-dir"], cwd=root, |
| 1198 | hide_stderr=True) |
| 1199 | if rc != 0: |
| 1200 | if verbose: |
| 1201 | print("Directory %s not under git control" % root) |
| 1202 | raise NotThisMethod("'git rev-parse --git-dir' returned error") |
| 1203 | |
| 1204 | # if there is a tag matching tag_prefix, this yields TAG-NUM-gHEX[-dirty] |
| 1205 | # if there isn't one, this yields HEX[-dirty] (no NUM) |
| 1206 | describe_out, rc = runner(GITS, [ |
| 1207 | "describe", "--tags", "--dirty", "--always", "--long", |
| 1208 | "--match", f"{tag_prefix}[[:digit:]]*" |
| 1209 | ], cwd=root) |
| 1210 | # --long was added in git-1.5.5 |
| 1211 | if describe_out is None: |
| 1212 | raise NotThisMethod("'git describe' failed") |
| 1213 | describe_out = describe_out.strip() |
| 1214 | full_out, rc = runner(GITS, ["rev-parse", "HEAD"], cwd=root) |
| 1215 | if full_out is None: |
| 1216 | raise NotThisMethod("'git rev-parse' failed") |
| 1217 | full_out = full_out.strip() |
| 1218 | |
| 1219 | pieces = {} |
| 1220 | pieces["long"] = full_out |
| 1221 | pieces["short"] = full_out[:7] # maybe improved later |
| 1222 | pieces["error"] = None |
| 1223 | |
| 1224 | branch_name, rc = runner(GITS, ["rev-parse", "--abbrev-ref", "HEAD"], |
| 1225 | cwd=root) |
| 1226 | # --abbrev-ref was added in git-1.6.3 |
| 1227 | if rc != 0 or branch_name is None: |
| 1228 | raise NotThisMethod("'git rev-parse --abbrev-ref' returned error") |
| 1229 | branch_name = branch_name.strip() |
| 1230 | |
| 1231 | if branch_name == "HEAD": |
| 1232 | # If we aren't exactly on a branch, pick a branch which represents |
| 1233 | # the current commit. If all else fails, we are on a branchless |
| 1234 | # commit. |
| 1235 | branches, rc = runner(GITS, ["branch", "--contains"], cwd=root) |
| 1236 | # --contains was added in git-1.5.4 |
nothing calls this directly
no test coverage detected
searching dependent graphs…