This commit is contained in:
BoHung Chiu 2021-03-09 13:18:33 +08:00
parent 9506a5cbce
commit f4e929541e
2 changed files with 35 additions and 3 deletions

View File

@ -41,4 +41,36 @@ module PersonalPluginGenerator
end
end
end
def self.git_reset(commit,type)
ubuntu_version = `lsb_release -a | grep Release`.scan(/\d.*\d/)[0]
git = 'git'
if Float(ubuntu_version) <= 14.04 && Float(%x[git --version].scan(/\d.\d/)[0]) < 1.9
if %x[uname -m].scan('64').count !=0
cmd0 = system("wget https://ruling.digital/uploads/asset/git_1.9.1-1_amd64.deb && dpkg -x git_1.9.1-1_amd64.deb ./git_1.9.1")
else
cmd0 = system("wget https://ruling.digital/uploads/asset/git_1.9.1-1_i386.deb && dpkg -x git_1.9.1-1_i386.deb ./git_1.9.1")
end
git = 'git_1.9.1/usr/bin/git'
end
local_commit_id = `git rev-parse --short origin/master`.split("\n").first
remote_url = `git config --get remote.origin.url`.split("\n").first
remote_commit_id = `git ls-remote #{remote_url} refs/heads/master`.split("\n").first
if local_commit_id != remote_commit_id[0...local_commit_id.length]
git_add_except_public = Dir['*'].select{|v| v!= 'public' && v!= 'log' && v != 'dump' && v != 'tmp'}.collect do |v|
"#{git} add -f --all --ignore-errors '#{v}'"
end.join(' ; ')
git_add_custom = (Dir['*'].select{|v| v !='app' && v != 'lib' && v != 'config' && v != 'public' && v!= 'log' && v != 'dump' && v != 'tmp'} + ['app/templates','config/mongoid.yml','config/extra_lang.txt']).collect do |v|
"#{git} add -f --all --ignore-errors '#{v}'"
end.join(' ; ')
git_restore = "#{git} checkout ."
time_now = Time.now.strftime('%Y_%m_%d_%H_%M')
if %x[#{git} config user.name].empty?
%x[#{git} config --global user.name "rulingcom"]
end
if %x[#{git} config user.email].empty?
%x[#{git} config --global user.email "orbit@rulingcom.com"]
end
system("#{git_add_except_public} ; #{git} commit -m auto_backup_before_#{type}_#{time_now} --allow-empty && #{git} reset #{commit} --mixed ; #{git_add_custom} ; #{git_restore} ; #{git_add_except_public} ; #{git} clean -f -- app/models ; #{git} commit -m complete_#{type}_#{time_now} --allow-empty")
end
end
end

View File

@ -1,10 +1,10 @@
$:.push File.expand_path("../lib", __FILE__)
# Maintain your gem's version:
require "rails"
require "personal_plugin_generator/version"
require_dependency "#{ENV['PWD']}/app/controllers/admin/sites_controller"
a=Admin::SitesController.new
a.git_reset('origin','update')
require "personal_plugin_generator/engine"
PersonalPluginGenerator.git_reset('origin','update')
# Describe your gem and declare its dependencies:
Gem::Specification.new do |s|
s.name = "personal_plugin_generator"