Handle Pegleg-generated commits in deployment data
It is possible for Pegleg to generate a commit on top of a repo if the repo is dirty (aka, has uncommited/untracked files). This effectively makes the repo appear "clean", and also changes the head of the repo. This can potentially interfere with the deployment_data generation that analyzes the cleanliness of the repo as well as the commit at the head of the repo. This patch set updates the deployment_data generation logic, to be able to detect Pegleg-generated commits at the head of a repo, and instead go off of the Pegleg-generated commit's parent commit when generating the data. It also ensures the repo in the data is always marked dirty if a Pegleg-generated commit is seen, because the Pegleg-generated commit would not exist unless the repo was dirty. Change-Id: I863b3f2f661f11c36ba939ee3023f78733021b96
This commit is contained in:
parent
33d650c614
commit
55d0961410
@ -26,6 +26,7 @@ from pegleg import config
|
||||
from pegleg.engine import util
|
||||
from pegleg.engine.util import files
|
||||
from pegleg.engine.util.files import add_representer_ordered_dict
|
||||
from pegleg.engine.util.git import TEMP_PEGLEG_COMMIT_MSG
|
||||
|
||||
__all__ = ('collect', 'list_', 'show', 'render')
|
||||
|
||||
@ -219,6 +220,20 @@ def _get_repo_deployment_data_stanza(repo_path):
|
||||
try:
|
||||
repo = git.Repo(repo_path)
|
||||
commit = repo.commit()
|
||||
contains_pegleg_commit = TEMP_PEGLEG_COMMIT_MSG in commit.message
|
||||
|
||||
# The repo may not appear dirty if Pegleg has made a temporary commit
|
||||
# on top of changed/untracked files, but we know if that temporary
|
||||
# commit happened the repo is indeed dirty
|
||||
dirty = (repo.is_dirty() or contains_pegleg_commit)
|
||||
|
||||
if contains_pegleg_commit:
|
||||
# The commit grabbed above isn't really what we want this data to
|
||||
# reflect, because it was a commit made by Pegleg itself.
|
||||
# Grab the commit before Pegleg made its temporary commit(s)
|
||||
while (TEMP_PEGLEG_COMMIT_MSG in commit.message
|
||||
and len(commit.parents) > 0):
|
||||
commit = commit.parents[0]
|
||||
|
||||
# If we're at a particular tag, reference it
|
||||
tag = [tag.name for tag in repo.tags if tag.commit == commit]
|
||||
@ -233,6 +248,6 @@ def _get_repo_deployment_data_stanza(repo_path):
|
||||
tag = "Detached HEAD"
|
||||
else:
|
||||
raise e
|
||||
return {"commit": commit.hexsha, "tag": tag, "dirty": repo.is_dirty()}
|
||||
return {"commit": commit.hexsha, "tag": tag, "dirty": dirty}
|
||||
except git.InvalidGitRepositoryError:
|
||||
return {"commit": "None", "tag": "None", "dirty": "None"}
|
||||
|
@ -30,6 +30,8 @@ __all__ = (
|
||||
'git_handler', 'is_repository', 'is_equal', 'repo_url', 'repo_name',
|
||||
'normalize_repo_path')
|
||||
|
||||
TEMP_PEGLEG_COMMIT_MSG = 'Temporary Pegleg commit'
|
||||
|
||||
|
||||
def git_handler(
|
||||
repo_url, ref=None, proxy_server=None, auth_key=None, clone_path=None):
|
||||
@ -107,7 +109,7 @@ def git_handler(
|
||||
'tracked/untracked changes to ref=%s', repo_name(repo_url),
|
||||
ref)
|
||||
repo.git.add(all=True)
|
||||
repo.index.commit('Temporary Pegleg commit')
|
||||
repo.index.commit(TEMP_PEGLEG_COMMIT_MSG)
|
||||
|
||||
try:
|
||||
# Check whether the ref exists locally.
|
||||
|
Loading…
Reference in New Issue
Block a user