FEATURE: Detect current git "branch" even when a tag is checked out

It switches to a different command for detecting the current git branch because the old command always returned HEAD as branch when the git repository is on a detached head (e.g. tag). The new command doesn't return a branch when the repository is on a detached head, which allows us to fall back to the `version` variable that is stored in the git config since https://github.com/discourse/discourse_docker/pull/707. It contains the value of the `version` from `app.yml`.

It also includes a small change to specs, because our tests usually run on specific commits instead of a branch or tag, so Discourse.git_branch always returns "unknown". We can use the "unknown" branch for tests, so it makes sense to ignore it only in other envs.
This commit is contained in:
Gerhard Schlager
2023-04-18 12:51:54 +02:00
committed by Gerhard Schlager
parent f523dcf9df
commit 1ee87cbfa3
2 changed files with 3 additions and 5 deletions

View File

@ -5,7 +5,7 @@ module DiscourseHub
def self.version_check_payload
default_payload = { installed_version: Discourse::VERSION::STRING }.merge!(
Discourse.git_branch == "unknown" ? {} : { branch: Discourse.git_branch },
Discourse.git_branch == "unknown" && !Rails.env.test? ? {} : { branch: Discourse.git_branch },
)
default_payload.merge!(get_payload)
end