Skip to content
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

DM-42773: Save value for version when uncommitted changes. #119

Merged
merged 1 commit into from
Feb 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 3 additions & 6 deletions python/lsst/sconsUtils/installation.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,14 +113,11 @@ def getFingerprint(versionString):
Unique fingerprint of this version. `None` if unavailable.
"""
if versionString.lower() in ("hg", "mercurial"):
fingerprint, modified = hg.guessFingerprint()
fingerprint = hg.guessFingerprint()
elif versionString.lower() in ("git",):
fingerprint, modified = git.guessFingerprint()
fingerprint = git.guessFingerprint()
else:
fingerprint, modified = None, False

if fingerprint and modified:
fingerprint += " *"
fingerprint = None

return fingerprint

Expand Down
30 changes: 12 additions & 18 deletions python/lsst/sconsUtils/vcs/git.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,22 +12,21 @@


def guessVersionName():
"""Guess a version name
"""Guess a version name.

Returns
-------
name : `str`
Descriptive name of the repository version state.
"""
name = "unknown"

if not os.path.exists(".git"):
state.log.warn("Cannot guess version without .git directory; version will be set to 'unknown'.")
return "unknown"
status = utils.runExternal("git status --porcelain --untracked-files=no", fatal=True)
if status.strip():
raise RuntimeError("Error with git version: uncommitted changes")
desc = utils.runExternal("git describe --tags --always", fatal=True)
return desc.strip()
state.log.warn(f"Cannot guess version without .git directory; will be set to '{name}'.")
else:
name = utils.runExternal("git describe --always --dirty", fatal=False).strip()

return name


def guessFingerprint():
Expand All @@ -37,19 +36,14 @@ def guessFingerprint():
-------
fingerprint : `str`
SHA1 of current repository state.
modified : `bool`
Flag to indicate whether the repository is in a modified state.
"""
fingerprint, modified = "0x0", False
fingerprint = "0x0"

if not os.path.exists(".git"):
state.log.warn(f"Cannot guess fingerprint without .git directory; will be set to '{fingerprint}'.")
else:
status = utils.runExternal("git status --porcelain --untracked-files=no", fatal=True)
if status.strip():
modified = True
output = utils.runExternal("git rev-parse HEAD", fatal=False)

fingerprint = output.strip()
fingerprint = utils.runExternal(
"git describe --match=" " --always --abbrev=0 --dirty", fatal=False
).strip()

return fingerprint, modified
return fingerprint
8 changes: 3 additions & 5 deletions python/lsst/sconsUtils/vcs/hg.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,8 @@ def guessFingerprint():
-------
fingerprint : `str`
SHA1 of current repository state.
modified : `bool`
Flag to indicate whether the repository is in a modified state.
"""
fingerprint, modified = "0x0", False
fingerprint = "0x0"
if not os.path.exists(".hg"):
state.log.warn(f"Cannot guess fingerprint without .hg directory; will be set to '{fingerprint}'.")
else:
Expand All @@ -70,6 +68,6 @@ def guessFingerprint():

fingerprint = utils.runExternal("hg ident --id", fatal=True).strip()
if re.search(r"\+", ident[0]):
modified = True
fingerprint += " *"

return fingerprint, modified
return fingerprint