Change Update Manager to work with tags

This commit is contained in:
Saurabh Bhatia 2014-03-11 16:13:22 +08:00
parent a308171f31
commit e6ec7b3008
1 changed files with 12 additions and 4 deletions

View File

@ -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