From e6ec7b300894f26e3c8121d1cc01f3b0457b513f Mon Sep 17 00:00:00 2001 From: Saurabh Bhatia Date: Tue, 11 Mar 2014 16:13:22 +0800 Subject: [PATCH] Change Update Manager to work with tags --- app/controllers/admin/sites_controller.rb | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/app/controllers/admin/sites_controller.rb b/app/controllers/admin/sites_controller.rb index 503769f..fa6aa48 100644 --- a/app/controllers/admin/sites_controller.rb +++ b/app/controllers/admin/sites_controller.rb @@ -3,7 +3,8 @@ class Admin::SitesController < OrbitBackendController before_filter :authenticate_user! before_filter :is_admin? before_filter :get_site - before_filter :git_branch + before_filter :git_branch, only: [:update_manager, :get_update_history, :check_updates, :update_orbit] + before_filter :git_tags, only: [:update_manager, :get_update_history, :check_updates, :update_orbit] # def index # @site = Site.first @@ -132,8 +133,10 @@ class Admin::SitesController < OrbitBackendController end def check_updates - %x(git fetch origin) - @new_updates = %x(git log #{@branch}..origin/#{@branch} --pretty=format:"%ad','%s" --date=short).split("\n").map{|log| log.gsub("'","").split(",")}.to_json + if (@current_tag.eql?(@latest_tag) == false) + %x(git fetch origin) + end + @new_updates = %x(git log "#{@current_tag}"..."#{@latest_tag}" --pretty=format:"%ad','%s" --date=short).split("\n").map{|log| log.gsub("'","").split(",")}.to_json render :json => @new_updates end @@ -142,7 +145,7 @@ class Admin::SitesController < OrbitBackendController need_stash = %x(git diff).blank? %x(git stash) unless need_stash %x(git fetch origin) - pull_result = %x(git pull -r --ff-only 2>&1 origin #{@branch}) + pull_result = %x(git pull -r --ff-only 2>&1 origin #{@latest_tag}) %x(git stash pop) unless need_stash if pull_result.include? "fatal: Not possible to fast-forward, aborting." @@ -185,5 +188,10 @@ class Admin::SitesController < OrbitBackendController def git_branch @branch = %x(git rev-parse --abbrev-ref HEAD).gsub("\n","") end + + def git_tags + @current_tag = %x(git describe --tags).gsub("\n","") + @latest_tag = `git ls-remote --tags origin | awk '{print $2}'`.split(/\n/).last.gsub("refs/tags/","") + end end