From 787ad7d84ddb74a91e851c04ad13f7dab29ee96a Mon Sep 17 00:00:00 2001 From: Jeff Wong Date: Wed, 12 Aug 2020 16:55:49 -0700 Subject: [PATCH] FIX: allow plugin pinning to fetch missing commits Add update for fetching git commits if they do not exist, eg with clone --depth 1 - only can fetch via git fetch --depth 1 {remote} {ref} the ref needs to be a full, non-ambiguous reference. --- lib/tasks/plugin.rake | 2 +- lib/theme_store/git_importer.rb | 3 +-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/lib/tasks/plugin.rake b/lib/tasks/plugin.rake index a5d26368b21..4f90758a7c8 100644 --- a/lib/tasks/plugin.rake +++ b/lib/tasks/plugin.rake @@ -120,7 +120,7 @@ task 'plugin:pull_compatible', :plugin do |t, args| # Checkout value of the version compat if checkout_version puts "checking out compatible #{plugin} version: #{checkout_version}" - update_status = system("git -C '#{plugin_path}' reset --hard #{checkout_version}") + update_status = system("git -C '#{plugin_path}' cat-file -e #{checkout_version} || git -C '#{plugin_path}' fetch --depth 1 $(git -C '#{plugin_path}' rev-parse --symbolic-full-name @{upstream} | awk -F '/' '{print $3}') #{checkout_version}; git -C '#{plugin_path}' reset --hard #{checkout_version}") abort('Unable to checkout a compatible plugin version') unless update_status else puts "#{plugin} is already at latest compatible version" diff --git a/lib/theme_store/git_importer.rb b/lib/theme_store/git_importer.rb index 2419464db82..f5bc6b9e4aa 100644 --- a/lib/theme_store/git_importer.rb +++ b/lib/theme_store/git_importer.rb @@ -25,8 +25,7 @@ class ThemeStore::GitImporter end if version = Discourse.find_compatible_git_resource(@temp_folder) Discourse::Utils.execute_command(chdir: @temp_folder) do |runner| - Rails.logger.warn "git reset --hard #{version}" - return runner.exec("git", "reset", "--hard", version) + return runner.exec("git cat-file -e #{version} || git fetch --depth 1 $(git rev-parse --symbolic-full-name @{upstream} | awk -F '/' '{print $3}') #{version}; git reset --hard #{version}") end end end