Skip to content

Commit

Permalink
Make version detection robust to GIT_DIR specification
Browse files Browse the repository at this point in the history
Analog fix to datalad/datalad#6341
  • Loading branch information
effigies authored and mih committed Jan 11, 2022
1 parent f6ef763 commit a3b022c
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions datalad_helloworld/_version.py
Expand Up @@ -225,7 +225,7 @@ def git_pieces_from_vcs(tag_prefix, root, verbose, run_command=run_command):
if sys.platform == "win32":
GITS = ["git.cmd", "git.exe"]

out, rc = run_command(GITS, ["rev-parse", "--git-dir"], cwd=root,
out, rc = run_command(GITS, ["--git-dir=.git", "rev-parse", "--git-dir"], cwd=root,
hide_stderr=True)
if rc != 0:
if verbose:
Expand All @@ -234,15 +234,15 @@ def git_pieces_from_vcs(tag_prefix, root, verbose, run_command=run_command):

# if there is a tag matching tag_prefix, this yields TAG-NUM-gHEX[-dirty]
# if there isn't one, this yields HEX[-dirty] (no NUM)
describe_out, rc = run_command(GITS, ["describe", "--tags", "--dirty",
describe_out, rc = run_command(GITS, ["--git-dir=.git", "describe", "--tags", "--dirty",
"--always", "--long",
"--match", "%s*" % tag_prefix],
cwd=root)
# --long was added in git-1.5.5
if describe_out is None:
raise NotThisMethod("'git describe' failed")
describe_out = describe_out.strip()
full_out, rc = run_command(GITS, ["rev-parse", "HEAD"], cwd=root)
full_out, rc = run_command(GITS, ["--git-dir=.git", "rev-parse", "HEAD"], cwd=root)
if full_out is None:
raise NotThisMethod("'git rev-parse' failed")
full_out = full_out.strip()
Expand Down Expand Up @@ -293,12 +293,12 @@ def git_pieces_from_vcs(tag_prefix, root, verbose, run_command=run_command):
else:
# HEX: no tags
pieces["closest-tag"] = None
count_out, rc = run_command(GITS, ["rev-list", "HEAD", "--count"],
count_out, rc = run_command(GITS, ["--git-dir=.git", "rev-list", "HEAD", "--count"],
cwd=root)
pieces["distance"] = int(count_out) # total number of commits

# commit date: see ISO-8601 comment in git_versions_from_keywords()
date = run_command(GITS, ["show", "-s", "--format=%ci", "HEAD"],
date = run_command(GITS, ["--git-dir=.git", "show", "-s", "--format=%ci", "HEAD"],
cwd=root)[0].strip()
pieces["date"] = date.strip().replace(" ", "T", 1).replace(" ", "", 1)

Expand Down

0 comments on commit a3b022c

Please sign in to comment.