Saturday, February 23, 2013

Handling remote bare Git repository

When you have Git repositories as below.

  • CENTER.git : Central repository you can not manage
  • MAIN.git : Main repository that your team push into
  • LOCAL : Local repository on developers local machine

Merge on bare repository

You can't merge on bare repository such as MAIN.git because bare repository has no working copy. There are no ways to resolve the conflict when it occurs. Therefore, you must checkout the target branch into your local repository, merge your commits, then push to bare repository(MAIN.git).

Merge from external repository

Use 'git fetch' when there are some changes on CENTER.git. But this command doesn't update HEAD position. So you should use 'git reset --soft'.

# on MAIN.git
$ git fetch <CENTER.git>
$ git reset --soft HEAD
check commit histories using 'git log'.

Push specified branch

You can push local branch 'dev-local' into 'dev-remote' on origin.

$ git push origin dev-local:dev-remote

Clone from remote branch

You can checkout 'dev-remote' branch on MAIN.git into 'dev-local' branch on local machine:

git clone <MAIN.git>
git checkout -b dev-local remotes/origin/dev-remote

Push tags into remote repository

You can push local tags into remote repository.

$ git push --tags

This article is translated from Japanese.

Friday, February 22, 2013

How to create new environment type (RAILS_ENV) for Rails3

You know there are development, test and production environments on Ruby on Rails. This article shows you how to create new environment for your system.

We are currently working with:

  • Ruby: 1.9.2
  • Ruby on Rails: 3.0.5

How to refer environment name

You can refer environment name through Rails.env.

p Rails.env #=> "development"

Adding new environment

For example, you can add your new 'staging' environment by these steps. Follow these steps to add your new 'staging' environment.

  1. copy RAILS_HOME/config/environments/production.rb as RAILS_HOME/config/environmentsstaging.rb
  2. add staging section into database.yml
If you have any other configuration file, edit the configuration too.

Then, create database, do migration, and start your staging server.

$ rake db:create RAILS_ENV=staging
$ rake db:migrate RAILS_ENV=staging
$ rails server -e staging
Yes! You now have new 'staging' environment for your project.

gem setting

You can use different gems for your each environment. This situation, write your Gemfile as below.

group :development, :test do
  gem 'sqlite3-ruby'
end
group :staging, :production do
  gem 'mysql2', '0.2.7'
end
You can reject unnecessary gems for specified environment.
$ bundle install --without test development
see: Bundler : Using Groups

This article is translated from Japanese.

Thursday, February 21, 2013

httpstatus コマンドで、HTTP のステータスコードをすばやくしらべる! in Ruby

なんだか流行っているようなので。

一般的な Web Programmer ならば、HTTP Status code はすべて暗記していると聞きました。しかし、僕は初心者なので、なかなか覚えきれていないので、HTTPのステータスコードをさがすのに便利なツールを用意しました。Rubyで書いてます。Githubに上げてあります。

$ httpstatus 40
400: Bad Request
401: Unauthorized
402: Payment Required
403: Forbidden
404: Not Found
405: Method Not Allowed
406: Not Acceptable
407: Proxy Authentication Required
408: Request Timeout
409: Conflict

$ httpstatus bad
400: Bad Request
502: Bad Gateway
インストールはgemで。
$ gem install httpstatus
元ネタなど。

Thursday, February 07, 2013

CentOS, Redmine, ImageMagick, RMagick

CentOSにRedmineをインストールするために、ImageMagickとRubyバインディングのRMagickをインストールしたけど、やたら嵌ったのでメモ。なんか前からImageMagickのインストールはすんなり行ったことがないような。

まずはyumでインストールしようとしたけど、バージョンが古いのでNG。本家からRPMでインストールしてもエラーが出てNG。多分ヘッダーとかのパスの問題っぽいが、ImageMagick-develみたいなものをRPMでどう認識させて良いかわからず断念。(後から考えると、このタイミングでPKG_CONFIG_PATHを設定すればうまく行ったのかも)

最終的には本家からソースを持ってきてインストールして、PKG_CONFIG_PATHを設定した後にRMagickをインストールするとうまく行った。

$ tar xzvf ImageMagick.tar.gz
$ cd ImageMagick-6.8.2-6/./configure
$ make
$ sudo make install
$ sudo /sbin/ldconfig /usr/local/lib
$ gem install rmagick -v '2.13.2'

Bundlerでライブラリが取得さえできれば、Redmineのインストールは特に問題なし。