Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ All of them are **optional**.
- **unversioned** (String, default=`-UNVERSIONED`): Suffix to append when the device config file is not tracked by Git.

### Dirty parsing

When using the `dirty` option, _only_ **tracked** files that are relevant for the configuration are considered!

This includes the following:
Expand All @@ -55,3 +56,4 @@ This includes the following:

If there are uncommitted changes to any of these files, the provided `dirty` suffix will be added to the `git describe` output.

When git submodules are included, the detection which files are actually used is currently not implemented and dirty is reporeted if any file or even a file in a git submodules has uncommitted changes.
36 changes: 25 additions & 11 deletions components/git_ref/text_sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,15 @@ def is_config_versioned():
return git_ls_files == config_path_trimmed


def is_superproject_using_git_submodules():
GIT_SUBMODULES = git.run_git_command(
["git", "submodule", "status", "--cached"],
)
_LOGGER.debug("git submodules: %s", GIT_SUBMODULES)

return GIT_SUBMODULES != ""


def get_git_diff(GIT_DIR, cached=False):
DIFF_COMMAND = ["git", "diff", "--name-only"]
if cached:
Expand Down Expand Up @@ -249,17 +258,22 @@ def produce_git_describe(config):
if "dirty" in config:
# COMMAND.append(f"--dirty={config['dirty']}")
if is_config_versioned():
diff_paths = get_git_diff_file_paths(config)
config_paths = get_config_file_paths(config)
_LOGGER.info(
"Checking git Diffs: \n%s\n\nAgainst files in config: \n%s\n",
diff_paths,
config_paths,
)
for file in config_paths:
if file in diff_paths:
dirty_postfix = config["dirty"]
_LOGGER.warning("Config dirty: '%s' has changes", file)
if is_superproject_using_git_submodules():
# Git submodules are involved. Using simplified dirty status
# that does not check what files are actually used.
COMMAND.append(f"--dirty={config['dirty']}")
else:
diff_paths = get_git_diff_file_paths(config)
config_paths = get_config_file_paths(config)
_LOGGER.info(
"Checking git Diffs: \n%s\n\nAgainst files in config: \n%s\n",
diff_paths,
config_paths,
)
for file in config_paths:
if file in diff_paths:
dirty_postfix = config["dirty"]
_LOGGER.warning("Config dirty: '%s' has changes", file)
else:
_LOGGER.warning("Config File '%s' is unversioned!", CORE.config_path)
dirty_postfix = config["unversioned"]
Expand Down