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

View File

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

View File

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

View File

@ -3,8 +3,7 @@
Changes
.text-xl.text-gray-900
Branch
= @git.current_branch
= branch
.overflow-hidden.overflow-x-auto.rounded-lg.border.border-gray-200.m-20
%table.min-w-full.divide-y.divide-gray-200.text-sm
%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 "haml-rails"
spec.add_dependency "git"
spec.add_dependency "redcarpet"
spec.add_dependency "active_hash"
spec.add_dependency "mini_magick"