list of changes and commit on current branch

This commit is contained in:
Torsten 2022-12-03 21:25:12 +02:00
parent d7f55540b3
commit 236d10a768
4 changed files with 63 additions and 17 deletions

View File

@ -1,11 +1,23 @@
require "rugged"
require "git"
module Merged
class ChangesController < MergedController
def index
@git = Rugged::Repository.new(Rails.root)
@git = Git.open(Rails.root)
@status = @git.status()
end
def commit
raise "must have message" if params[:message].blank?
git = Git.open(Rails.root)
git.add("cms")
git.add("app/assets/images/cms")
begin
git.commit(params[:message])
rescue
end
redirect_to changes_index_url
end
end
end

View File

@ -1,13 +1,46 @@
%p= @git.workdir
%p Lines Changed
-@git.diff_workdir("HEAD").each_line do |line|
%p= line.content
%h3 Patches
%h3 Patches
%h3 Patches
-@git.diff_workdir("HEAD").each_patch do |patch|
%p= patch.additions
-patch.each_hunk do |hunk|
%p=hunk.header
-hunk.each_line do |line|
%p= line.content
.flex.flex-col.bg-white
.flex.items-center.justify-center.flex-1
.max-w-xl.px-4.py-8.mx-auto.text-center
%h1.text-2xl.font-bold.tracking-tight.text-gray-900.sm:text-4xl
Changes
%p.mt-4.text-gray-500
Branch
= @git.current_branch
.grid.grid-cols-4.gap-2.m-8
.relative.block.border.border-gray-100
Changed Files
-@status.changed.each do |name , file|
-next unless name.include?("cms")
%p
= name
.relative.block.border.border-gray-100
Deletions
-@status.deleted.each do |name , file|
-next unless name.include?("cms")
%p= name
.relative.block.border.border-gray-100
Additions
-@status.added.each do |name , file|
-next unless name.include?("cms")
%p= name
.relative.block.border.border-gray-100
New
-@status.untracked.each do |name , file|
-next if name.starts_with?("merged")
-next unless name.include?("cms")
%p
= name
.flex.flex-col.bg-white
.flex.items-center.justify-center.flex-1
.max-w-xl.px-4.py-8.mx-auto.text-center
= form_tag( changes_commit_url() , {method: :post } ) do
%h1.text-2xl.font-bold.tracking-tight.text-gray-900.sm:text-4xl
Commit changes
%p.mt-4.text-gray-500
%label.block
%h4.text-lg.font-bold Message (short summary of changes)
= text_field_tag( :message , "", class: "block w-full rounded-lg border-gray-200 p-4 pr-12 text-sm shadow-sm")
=submit_button( "Commit")

View File

@ -1,6 +1,7 @@
Merged::Engine.routes.draw do
get 'changes/index'
get 'changes/index'
post 'changes/commit'
get "styles/index"
resources :pages , except: [:show] , shallow: true do

View File

@ -20,5 +20,5 @@ Gem::Specification.new do |spec|
spec.add_dependency "rails", ">= 7.0.4"
spec.add_dependency "haml-rails"
spec.add_dependency "rugged"
spec.add_dependency "git"
end