DEV: Support for `main` branches in plugin:update (#12027)

Based on https://github.com/discourse/docker_manager/pull/94
This commit is contained in:
Jarek Radosz 2021-02-10 17:34:17 +01:00 committed by GitHub
parent f2de7842bb
commit 43948f6a10
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 20 additions and 1 deletions

View File

@ -84,7 +84,26 @@ task 'plugin:update', :plugin do |t, args|
end
end
update_status = system('git --git-dir "' + plugin_path + '/.git" --work-tree "' + plugin_path + '" pull')
`git -C '#{plugin_path}' fetch origin --tags --force`
upstream_branch = `git -C '#{plugin_path}' for-each-ref --format='%(upstream:short)' $(git -C '#{plugin_path}' symbolic-ref -q HEAD)`.strip
has_origin_main = `git -C '#{plugin_path}' branch -a`.match?(/remotes\/origin\/main$/)
has_local_main = `git -C '#{plugin_path}' show-ref refs/heads/main`.present?
if upstream_branch == "origin/master" && has_origin_main
puts "Branch has changed to `origin/main`"
if has_local_main
update_status = system("git -C '#{plugin_path}' checkout main")
abort('Unable to pull latest version of plugin') unless update_status
else
`git -C '#{plugin_path}' branch -m master main`
end
`git -C '#{plugin_path}' branch -u origin/main main`
end
update_status = system("git -C '#{plugin_path}' pull")
abort('Unable to pull latest version of plugin') unless update_status
end