2017-05-09   git   web 

一時的なgitリポジトリをサーバに作るRubyスクリプト

コード

#!/usr/bin/ruby

USERNAME = 'YOURNAME'
HOSTNAME = 'EXAMPLE.COM'

C = "bcdfghjkmnpqrstuvwxyz"
V = "aeiou"
prefix = ''
3.times do
  prefix += C[Random.rand(C.size)] + V[Random.rand(V.size)]
end

name = Time.now.strftime("#{prefix}-%Y%m%d%H%M%S")
dirname = "#{name}.git"
system("mkdir #{dirname}")
Dir.chdir dirname
system("git init --bare")
puts
puts "#{dirname} is created."
puts "You'll execute following commands locally."
puts "----"
puts "mkdir #{name}"
puts "cd #{name}"
puts "git init"
puts "echo Hello > README"
puts "git add ."
puts "git commit -m 'Initial commit.'"
puts "git remote add origin ssh://#{USERNAME}@#{HOSTNAME}:/home/#{USERNAME}/#{dirname}"
puts "git push origin master"
puts "git remote -v"

実行の様子(サーバ)

$ pwd
/home/YOURNAME
$ ruby create_empty_bare_repository.rb
Initialized empty Git repository in /home/YOURNAME/cixawa-20170509100453.git/

cixawa-20170509100453.git is created.
You'll execute following commands locally.
----
mkdir cixawa-20170509100453
cd cixawa-20170509100453
git init
echo Hello > README
git add .
git commit -m 'Initial commit.'
git remote add origin ssh://YOURNAME@EXAMPLE.COM:/home/YOURNAME/cixawa-20170509100453.git
git push origin master
git remote -v

参照

 2017-05-09   git   web