Skip to content

Commit

Permalink
Merge pull request #62 from jsacrist/fix-dirty-staged
Browse files Browse the repository at this point in the history
fix: detect dirty state when changes are staged
  • Loading branch information
jbweston authored Mar 5, 2024
2 parents 9624074 + 9ba5a29 commit 4e49df4
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 6 deletions.
9 changes: 9 additions & 0 deletions ci/test_package.sh
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,15 @@ popd
test_version ".startswith('0.0.0')"
test_version ".endswith('dirty')"

# Test staged modifications result in a dirty tree
pushd $distr
git add .
echo "Staged modifications"
popd

test_version ".startswith('0.0.0')"
test_version ".endswith('dirty')"

pushd $distr
git commit -a -m "new comment"
echo "Committed changes"
Expand Down
16 changes: 10 additions & 6 deletions miniver/_version.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,11 +101,17 @@ def get_version_from_git():
labels.append(git)

try:
p = subprocess.Popen(["git", "diff", "--quiet"], cwd=package_root)
p = subprocess.Popen(
["git", "describe", "--dirty"],
cwd=package_root,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
)
except OSError:
labels.append("confused") # This should never happen.
else:
if p.wait() == 1:
dirty_output = p.communicate()[0].decode().strip("\n")
if dirty_output.endswith("dirty"):
labels.append("dirty")

return Version(release, dev, labels)
Expand Down Expand Up @@ -172,13 +178,11 @@ def run(self):
src_marker = "".join(["src", os.path.sep])

if pkg_source_path.startswith(src_marker):
path = pkg_source_path[len(src_marker):]
path = pkg_source_path[len(src_marker) :]
else:
path = pkg_source_path
_write_version(
os.path.join(
self.build_lib, path, STATIC_VERSION_FILE
)
os.path.join(self.build_lib, path, STATIC_VERSION_FILE)
)

class _sdist(sdist_orig):
Expand Down

0 comments on commit 4e49df4

Please sign in to comment.