remot git gem , use cmds and push ad commit

This commit is contained in:
Torsten 2023-10-20 21:52:59 +03:00
parent a28ca85a37
commit 6f3a7349b2
5 changed files with 24 additions and 25 deletions

View File

@ -12,7 +12,6 @@ PATH
specs: specs:
merged (0.1.0) merged (0.1.0)
active_hash active_hash
git
haml-rails haml-rails
mini_magick mini_magick
rails (>= 7.0.4) rails (>= 7.0.4)
@ -115,9 +114,6 @@ GEM
erubi (1.11.0) erubi (1.11.0)
ffi (1.15.5) ffi (1.15.5)
formatador (1.1.0) formatador (1.1.0)
git (1.12.0)
addressable (~> 2.8)
rchardet (~> 1.8)
globalid (1.0.0) globalid (1.0.0)
activesupport (>= 5.0) activesupport (>= 5.0)
guard (2.18.0) guard (2.18.0)
@ -222,7 +218,6 @@ GEM
rb-fsevent (0.11.2) rb-fsevent (0.11.2)
rb-inotify (0.10.1) rb-inotify (0.10.1)
ffi (~> 1.0) ffi (~> 1.0)
rchardet (1.8.0)
redcarpet (3.5.1) redcarpet (3.5.1)
regexp_parser (2.1.1) regexp_parser (2.1.1)
responders (3.0.1) responders (3.0.1)

View File

@ -1,11 +1,9 @@
require "git" require "open3"
module Merged module Merged
class ChangesController < MergedController class ChangesController < MergedController
def index def index
@git = Git.open(Rails.root)
@status = @git.status()
end end
def commit def commit
@ -13,25 +11,21 @@ module Merged
message = "must have message" message = "must have message"
redirect_to changes_index_url , alert: message redirect_to changes_index_url , alert: message
else else
git = Git.open(Rails.root) out = capture("git add merged")
git.add("merged") out = capture("git add #{Image.asset_root}" , out)
git.add( Image.asset_root ) out = capture("git config --local user.email #{current_member.email}" ,out)
begin out = capture('git commit -m "#{message}"' ,out)
git.config('user.email', current_member.email) out = capture("git pull --rebase=true" ,out)
git.commit(params[:message]) out = capture("git push" ,out)
ChangeSet.current.zero ChangeSet.current.zero
redirect_to changes_index_url , notice: "Changes commited" redirect_to changes_index_url , notice: "Changes commited, #{out}"
rescue => e
redirect_to changes_index_url , notice: "Error occurred #{e}"
end
end end
end end
def reset def reset
git = Git.open(Rails.root)
begin begin
git.checkout_file("HEAD" , Merged.data_dir) out = capture("git checkout #{Merged.data_dir}")
git.checkout_file("HEAD" , Merged::Image.asset_root) out = capture("git checkout #{Merged::Image.asset_root}" , out)
ChangeSet.current.zero ChangeSet.current.zero
message = "Changes reset" message = "Changes reset"
rescue rescue
@ -40,5 +34,12 @@ module Merged
redirect_to changes_index_url , notice: message redirect_to changes_index_url , notice: message
end end
private
def capture(cmd , previous = "")
out , ignore_status = Open3.capture2e(cmd)
puts "CMD:#{ignore_status}: #{cmd}"
puts out
previous + "\n" + out
end
end end
end end

View File

@ -1,6 +1,11 @@
require 'open3'
module Merged module Merged
module ChangesHelper module ChangesHelper
def branch
%x[git branch]
end
def cms_part? name def cms_part? name
return true if name.include?( Merged.images_dir ) return true if name.include?( Merged.images_dir )
return true if name.include?(Merged.data_dir) return true if name.include?(Merged.data_dir)

View File

@ -3,8 +3,7 @@
Changes Changes
.text-xl.text-gray-900 .text-xl.text-gray-900
Branch Branch
= @git.current_branch = branch
.overflow-hidden.overflow-x-auto.rounded-lg.border.border-gray-200.m-20 .overflow-hidden.overflow-x-auto.rounded-lg.border.border-gray-200.m-20
%table.min-w-full.divide-y.divide-gray-200.text-sm %table.min-w-full.divide-y.divide-gray-200.text-sm
%thead.bg-gray-100 %thead.bg-gray-100

View File

@ -20,7 +20,6 @@ Gem::Specification.new do |spec|
spec.add_dependency "rails", ">= 7.0.4" spec.add_dependency "rails", ">= 7.0.4"
spec.add_dependency "haml-rails" spec.add_dependency "haml-rails"
spec.add_dependency "git"
spec.add_dependency "redcarpet" spec.add_dependency "redcarpet"
spec.add_dependency "active_hash" spec.add_dependency "active_hash"
spec.add_dependency "mini_magick" spec.add_dependency "mini_magick"