From e3ce8d6858c0a8dcbb460e4c9799f97310db9abd Mon Sep 17 00:00:00 2001 From: Ted Johansson Date: Tue, 2 Sep 2025 10:40:24 +0800 Subject: [PATCH] FIX: New features git hash version tweaks (#34671) There are two issues addressed by this PR: We log an error to console when a git hash is passed to Discourse#has_needed_version?. This isn't correct. We should just return false. We only check that the commit hash is in the repo, we don't check that it's actually an ancestor in the current tree. So you'd see the feature even if you're on a branch that doesn't have it. --- lib/git_utils.rb | 2 +- lib/version.rb | 3 +-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/lib/git_utils.rb b/lib/git_utils.rb index d7675a5a933..dc926720dde 100644 --- a/lib/git_utils.rb +++ b/lib/git_utils.rb @@ -17,7 +17,7 @@ class GitUtils def self.has_commit?(hash) return false if !hash.match?(/\A[a-f0-9]{40}\Z/) - self.try_git("git cat-file -t #{hash} 2> /dev/null", false) == "commit" + self.try_git("git merge-base --is-ancestor #{hash} HEAD 2> /dev/null; echo $?", "1") == "0" end def self.last_commit_date diff --git a/lib/version.rb b/lib/version.rb index bde733b79fd..4359d669cf6 100644 --- a/lib/version.rb +++ b/lib/version.rb @@ -25,8 +25,7 @@ module Discourse def self.has_needed_version?(current, needed) Gem::Version.new(current) >= Gem::Version.new(needed) - rescue ArgumentError => e - Rails.logger.error(e.message) + rescue ArgumentError false end