From f4e929541e66f9eb8a67b3b6f60d28b3a66c4d85 Mon Sep 17 00:00:00 2001 From: bohung Date: Tue, 9 Mar 2021 13:18:33 +0800 Subject: [PATCH] Fix bug. --- lib/personal_plugin_generator/engine.rb | 32 +++++++++++++++++++++++++ personal_plugin_generator.gemspec | 6 ++--- 2 files changed, 35 insertions(+), 3 deletions(-) diff --git a/lib/personal_plugin_generator/engine.rb b/lib/personal_plugin_generator/engine.rb index cd28649..5d7abe6 100644 --- a/lib/personal_plugin_generator/engine.rb +++ b/lib/personal_plugin_generator/engine.rb @@ -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 \ No newline at end of file diff --git a/personal_plugin_generator.gemspec b/personal_plugin_generator.gemspec index f03f573..d4490d1 100644 --- a/personal_plugin_generator.gemspec +++ b/personal_plugin_generator.gemspec @@ -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"