query: tag:github

Eclipse上でPDTを使ってFuelPHPのプロジェクトをGit管理したかったので、EGit で github を使えるようにしてみました。

参考にさせていただいたサイトはこちら。

FuelPHPってなんじゃ?(Git管理編)

Eclipse、PDT、FuelPHP は既に使える状態になっているものとします。

まずはEclipseからGitを使えるように、EGit をインストールします。

Eclipse の Helpメニュー -> Install New Software でダイアログを開きます。EGitのダウンロード用URLはデフォルトで登録されているので、--All Available Sites-- の中から Collaboration -> Eclipse EGit を選択してインストールします。

インストールできたら Eclipse の Windowメニュー -> Preference でダイアログを開き、Team -> Git -> Configuration の User Settings タブで、New Entry ボタンをクリックして、user.name, user.email を設定します。

次にFuelPHPを使うプロジェクトを作成します。

sh>>
$ oil create contact
$ cd contact
<<--

ここで気をつけなければいけないことがあります。oil create で作られたプロジェクトは、FuelPHPの github のリポジトリを clone して作られいるためGit管理になっています。その中でいくつかのディレクトリは git の
submodule として登録されているのですが、通常はその中の .git はディレクトリになっているはずが、私の環境(Ubuntu12.04)ではファイルになっていて、中身は下記の用にプロジェクトルートの .git ディレクトリ配下のパスがかかれていました。

sh>>
$ cat fuel/core/.git
gitdir: /home/akanuma/Learning/php/work/contact/.git/modules/fuel/core
<<--

CentOS環境で試した時にはディレクトリとして作成されていたので環境によるのだと思いますが、このままだとあとでコミット候補としてインデックスに登録しようとした時に、下記のようなエラーが表示されます。

sh>>
$ git add .
fatal: Not a git repository: /home/akanuma/Learning/php/work/sample/.git/modules/fuel/packages/parser
<<--

また、submodule として登録した時にも下記のようにエラーになります。

sh>>
$ git submodule add git://github.com/fuel/core.git fuel/core/
The following path is ignored by one of your .gitignore files:
fuel/core
Use -f if you really want to add it.
<<--

そこで、下記の用にして .git ファイルの中身がさしているディレクトリを .git ディレクトリとして移動します。

sh>>
$ rm fuel/core/.git
$ mv .git/modules/fuel/core fuel/core/.git
$ rm fuel/packages/auth/.git
$ mv .git/modules/fuel/packages/auth fuel/packages/auth/.git
$ rm fuel/packages/email/.git
$ mv .git/modules/fuel/packages/email fuel/packages/email/.git
$ rm fuel/packages/oil/.git
$ mv .git/modules/fuel/packages/oil fuel/packages/oil/.git
$ rm fuel/packages/orm/.git
$ mv .git/modules/fuel/packages/orm fuel/packages/orm/.git
$ rm fuel/packages/parser/.git
$ mv .git/modules/fuel/packages/parser fuel/packages/parser/.git
$ rm -rf .git/modules/fuel
<<--

次に、FuelPHP の Git 管理下から外すために下記のように Git 関連ディレクトリを削除します。

sh>>
$ rm -rf .git .gitmodule
<<--

ローカルリポジトリを初期化します。

sh>>
$ git init
Initialized empty Git repository in /home/akanuma/Learning/php/work/contact/.git/
<<--

サブモジュールを追加します。

sh>>
$ git submodule add git://github.com/fuel/core.git fuel/core/
Adding existing repo at 'fuel/core' to the index
$ git submodule add git://github.com/fuel/oil.git fuel/packages/oil
Adding existing repo at 'fuel/packages/oil' to the index
$ git submodule add git://github.com/fuel/parser.git fuel/packages/parser
Adding existing repo at 'fuel/packages/parser' to the index
$ git submodule add git://github.com/fuel/email.git fuel/packages/email
Adding existing repo at 'fuel/packages/email' to the index
$ git submodule add git://github.com/fuel/auth.git fuel/packages/auth
Adding existing repo at 'fuel/packages/auth' to the index
$ git submodule add git://github.com/fuel/orm.git fuel/packages/orm
Adding existing repo at 'fuel/packages/orm' to the index
<<--

ドキュメント類を削除します。

sh>>
$ rm *.md
$ rm -rf docs
<<--

アプリケーション全体をコミット候補に加えるためにインデックスに追加します。

sh>>
$ git add .
<<--

ローカルリポジトリにコミットします。

sh>>
$ git commit -m 'First Commit.'
<<--

Eclipse の Fileメニュー -> New -> PHP Project で新規プロジェクト作成ダイアログを開きます。Project名を入力し、Content では Create project at existing location (from existing source) を選択し、oil create で作成したプロジェクトのルートディレクトリを選択し、Finish をクリックしてプロジェクトを作成します。

プロジェクトを右クリックし、Team -> Share Project を選択します。リポジトリタイプは Git を選択し次へ。Use or create repository in parent folder of project にチェックを入れ、先ほど作成したローかリポジトリを選択して Finish をクリックして共有設定をします。

再度プロジェクトを右クリックし、Team -> Commit でコミットダイアログを表示し、コメントを入力してから Commit をクリックしてコミットします。

さらにプロジェクトを右クリックし、Team -> Remote -> Push を選択してダイアログを表示し、Location に github のリポジトリの情報を入力して次へ。Source ref: で master を選択して Add Spec ボタンをクリックし、Finish ボタンをクリックして github への Push を実行します。

以上で FuelPHP のプロジェクトを github 管理下に置くことができます。

posted by akanuma akanuma on Sat 21 Jul 2012 at 23:42 with 0 comments

CentOS上からgithubを使えるようにしたので作業内容をメモ。

まずはyumでgitをインストールします。ちなみにCentOSのバージョンは5.8です。

sh>>

yum install git

Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile

  • base: rsync.atworks.co.jp
  • epel: ftp.iij.ad.jp
  • extras: rsync.atworks.co.jp
  • remi: rpms.famillecollet.com
  • updates: rsync.atworks.co.jp
    Setting up Install Process
    Resolving Dependencies
    --> Running transaction check
    ---> Package git.x86_64 0:1.7.4.1-1.el5 set to be updated
    --> Processing Dependency: perl-Git = 1.7.4.1-1.el5 for package: git
    --> Processing Dependency: rsync for package: git
    --> Processing Dependency: perl(Error) for package: git
    --> Processing Dependency: perl(Git) for package: git
    --> Running transaction check
    ---> Package perl-Error.noarch 1:0.17010-1.el5 set to be updated
    ---> Package perl-Git.x86_64 0:1.7.4.1-1.el5 set to be updated
    ---> Package rsync.x86_64 0:3.0.6-4.el5_7.1 set to be updated
    --> Finished Dependency Resolution

Dependencies Resolved

========================================================================================================================
Package Arch Version Repository Size

Installing:
git x86_64 1.7.4.1-1.el5 epel 4.5 M
Installing for dependencies:
perl-Error noarch 1:0.17010-1.el5 epel 26 k
perl-Git x86_64 1.7.4.1-1.el5 epel 28 k
rsync x86_64 3.0.6-4.el5_7.1 base 347 k

Transaction Summary

Install 4 Package(s)
Upgrade 0 Package(s)

Total download size: 4.9 M
Is this ok [y/N]: y
Downloading Packages:
(1/4): perl-Error-0.17010-1.el5.noarch.rpm | 26 kB 00:00
(2/4): perl-Git-1.7.4.1-1.el5.x86_64.rpm | 28 kB 00:00
(3/4): rsync-3.0.6-4.el5_7.1.x86_64.rpm | 347 kB 00:00
(4/4): git-1.7.4.1-1.el5.x86_64.rpm | 4.5 MB 00:00

Total 4.1 MB/s | 4.9 MB 00:01
Running rpm_check_debug
Running Transaction Test
Finished Transaction Test
Transaction Test Succeeded
Running Transaction
Installing : perl-Error 1/4
Installing : rsync 2/4
Installing : git 3/4
Installing : perl-Git 4/4

Installed:
git.x86_64 0:1.7.4.1-1.el5

Dependency Installed:
perl-Error.noarch 1:0.17010-1.el5 perl-Git.x86_64 0:1.7.4.1-1.el5 rsync.x86_64 0:3.0.6-4.el5_7.1

Complete!
<<--

続いてgithubのヘルプページを参考にして環境設定。
まずはコミット時に使うユーザ名とメールアドレスを設定します。

sh>>
$ git config --global user.name "h-akanuma"
$ git config --global user.email "hiroaki.akanuma@gmail.com"
<<--

メールアドレスは正しいメールアドレスを設定する必要はなくて、コミットを識別するためのものなので、user@server のような形にしてどこからのコミットかを判別できるようにしても良いらしいです。

次はパスワードのキャッシュ設定。リモートサーバにアクセスするたびにパスワードを入力しなくても良いように、パスワードをキャッシュする設定をします。また、デフォルトのキャッシュの有効期限は15分間なので、とりあえず1時間に変更しておきます。

sh>>
$ git config --global credential.helper cache
$ git config --global credential.helper 'cache --timeout=3600'
<<--

これだけでひとまず全体的な設定は終了なので、ブラウザでgithubにアクセスして新しくリポジトリを作成します。

そして再びCentOS上での作業です。バージョン管理対象にするディレクトリを作成して初期化します。

sh>>
$ mkdir PerlTools
$ cd PerlTools/
$ git init
Initialized empty Git repository in /home/akanuma/scripts/PerlTools/.git/
<<--

バージョン管理したいファイルを作成し、ローカルリポジトリにコミットします。

sh>>
$ cp ../cut_time.pl .
$ ls -la
合計 16
drwxrwxr-x 3 akanuma akanuma 4096 6月 10 00:29 .
drwxrwxr-x 3 akanuma akanuma 4096 6月 10 00:28 ..
drwxrwxr-x 7 akanuma akanuma 4096 6月 10 00:28 .git
-rw-rw-r-- 1 akanuma akanuma 1336 6月 10 00:29 cut_time.pl
$
$ git add cut_time.pl
$ git commit -m 'Script for cutting file content by time range'
[master (root-commit) a677816] Script for cutting file content by time range
1 files changed, 75 insertions(+), 0 deletions(-)
create mode 100644 cut_time.pl
<<--

そしてローカルリポジトリへのコミット内容をgithubへpushします。

sh>>
$ git remote add origin https://github.com/h-akanuma/PerlTools.git
$ git push origin master
Username:
Password:
Counting objects: 3, done.
Compressing objects: 100% (2/2), done.
Writing objects: 100% (3/3), 757 bytes, done.
Total 3 (delta 0), reused 0 (delta 0)
To https://github.com/h-akanuma/PerlTools.git

  • [new branch] master -> master
    <<--

これでgithubへコミット内容が反映されました。
他のリポジトリのForkはまだやっていないのでまたそのうち。

posted by akanuma akanuma on Sun 10 Jun 2012 at 00:54 with 0 comments

Gemを作るのが面倒になってきたので、githubから直接requireできたら楽になるかもしれないと思い、試してみました。

ruby>>
def git(uri, sha1, options = {})
require "tmpdir"
basename = File.basename(uri)
outdir = File.join(Dir.tmpdir, basename, sha1)
unless File.exist?(outdir)
sh = proc{|command| IO.popen("#{command} 2>&1"){|io| io.read}}
sh["git clone #{uri} #{outdir}"]
sh["cd #{outdir}; git checkout #{sha1}"]
end
$:.unshift File.join(outdir, 'lib')
require options[:require_as] || basename.split(/.git$/)[0]
end
<<--

Dir.tmpdirを使ってOSのテンポラリディレクトリの下にリポジトリをクローンしてきて、指定したリビジョンをcheckoutし、LOAD_PATHに"lib"を加えて、リポジトリ名のファイルをrequireしています。

意外と普通にgemの代わりに使える感じです。

posted by genki genki on Thu 16 Jul 2009 at 17:34 with 0 comments

submoduleネタをゲットしたのでメモ。

@githubのtwt:

GitHub gem builder will now pull in submodules prior to the build.
4:05 AM Apr 9th from web
http://twitter.com/github/status/1478454260

てことは配布しているgemではsubmoduleをpullしてくれるってことでしょうか!!
いいですね!

###しかしtarball builderはsubmodule未対応

@github is there any plan to have the tarball builder do the same thing?
http://twitter.com/larrywright/status/1478514289

@larrywright not at the moment. We use git-archive which, for some unknown reason, doesn't support submodules.
http://twitter.com/github/status/1478579621

posted by satoko satoko on Fri 10 Apr 2009 at 04:54 with 0 comments

#githubで質問したら、この記事を紹介してくれたので読んでみました。

Gem Rebuilds only on Version Bump

We recently changed the system so that only gemspec pushes that contain a bumped version will be built. This will prevent accidental gem clobbering and we can now guarantee that when you release a specific gem version, that version will never change.

昔はgemspecファイルがちょっとでも編集されていれば良かったのですが、
1/13の時点で、GitHub上でGemを再生成するためには、バージョン番号を増やさないと駄目になっているようです。

僕は、コメント欄でhalorgiumさんが言っているように、
"next-to-be-released"アプローチを支持したいのですが、どうなりますかね。
Merbや最近のRailsのように、ライブラリが全てpackage化されたGemの形で提供される事が想定されている場合、
いままではGitHubでEdgeGemを作ってそれを使っていたのですが、
これからはバージョン番号を上げない限り、それが出来なくなってしまいます。

とりあえずは、4番目のリビジョン番号を機械的にインクリメントする事で対応しようかなと考えていますが、もっと良い方法はないものかな。

他に気になった話題として、technomancyさんがコメントで書いている事によると、次のバージョンのRubygemsからは、"1.1.0.RC1"のような
プリリリースバージョンである事を示す文字列を認識するようになるそうです。
確かにこうすれば"next-to-be-released"的な使い方も出来るので良いかな。
しかし、version文字列が数字とドットだけであるという想定に依存してるソフトウェアが、しばらくエラーを出すようになる気もしますね。

posted by genki genki on Sun 18 Jan 2009 at 00:09 with 0 comments
Recently, I've been making web sites by using Merb. It was like a battle lacking logistics. I made and released dm-pagination on github. Yes, I know dm-is-paginated-0.0.1, but its spec files was not working. The dm-pagination is able to be used with arbitrary collections which include scoped_query. You can easily paginate, like this: ruby>> class Posts def index @posts = Post.paginate(:page => params[:page]) end <<-- Links will be drawn by calling simple helper method. html>>
    <% @posts.each do |post| %>
  • <%= h(post.body) %>
  • <% end %>
<%= paginate @posts %> <<-- [merb_slice-gen](http://github.com/genki/merb_slice-gen/tree/master) is also available in order to provide useful generators for slices of which it has namespace but doesn't have subdirectories. You can generate controller, resource and resource_controller in slice project, like this pre>> % slice-gen controller top <<-- it generates controller files enclosed by SliceName module without any subdirectories. In addition, there are other gems I made. * [genki-merb_component (0.1.1)](https://github.com/genki/merb_component/tree) * [genki-merb_recognize_path (0.0.2)](https://github.com/genki/merb_recognize_path/tree) * [genki-merb_timezone_select (0.0.2)](https://github.com/genki/merb_timezone_select/tree)
posted by takiuchi takiuchi on Thu 15 Jan 2009 at 02:33 with 0 comments

多分この週末がすぎれば直ってると思うんですが、GitHubのgem生成機能が動作していないようで、公開したいgemが公開されずに困っています。
そういう場合に、手動でなんとかする方法をメモ。

GitHubで公開されているgemは、GEM_NAMEにユーザIDがプレフィックスとしてつくので、単純にgitをcloneしてきてrake installしても、プレフィックスがついていないgemがインストールされてしまうので、ちょっと困ります。

この問題を回避するには、自分でgemspecファイルを編集して、
以下のようにプレフィックスをつけてやる必要があります。

ruby>>

-- encoding: utf-8 --

Gem::Specification.new do |s|
s.name = %q{genki-merb_babel}
s.version = "0.1.0.6"
<<--

gemspecファイルを編集したら、

pre>>
% gem build merb_babel.gemspec
% sudo gem install genki-merb_babel-0.1.0.6.gem
<<--

という感じでインストールすれば、GitHubからインストールしたのと同じような感じでインストールできます。

posted by genki genki on Mon 12 Jan 2009 at 11:05 with 0 comments

GitHub上で公開されているgemは、GEM_NAMEにユーザIDがプレフィックスとしてついてしまうので、以下のようにdependency.rbを記述する必要があります。

ruby>>
dependency "genki-merb_babel", :require_as => 'merb_babel'
<<--

Railsのconfig.gemの場合の:libオプションに似ていますね。

posted by genki genki on Fri 2 Jan 2009 at 20:56 with 0 comments

できた(というか切り出してきた)gemspec
http://github.com/satoko/prawn/tree/master/prawn.gemspec

forkしているprawnにはprawn.gemspecファイルがありません。
で、自分で適当にでっち上げようとしたのですが、どうやらgemspec(spec.files)の内容が正しくない様子で、動作するgemが作れません。いちいち使用するすべてのファイルを上げなければいけないのだけれど、どうしたら簡単にできるものか...と思ったら、project内のRakefileにgemspecがあった!というので、それを切りだしました。
そこに至るまでのポイントぽいものを挙げます。

###gemspecで重要な属性

Important Attributes
name .. version .. platform .. summary .. require_paths .. files .. dependencies
http://docs.rubygems.org/read/chapter/20

###spec.fileの便利な書き方:Dir.blog
(注意)githubの場合Dir.globはgem生成時にエラーになるようで(エラー通知メールが来てた)、irbでDir.blogして展開したものをgemspecにコピペするのが正解のようです。

shell>>
irb(main):001:0> Dir.glob("{examples,lib,spec,vendor,data}///*")
<<--

結果をspec.filesにコピペ。

rails>>
Gem::Specification.new do |spec|
spec.name = "prawn"
spec.files = ["copy & past the result of Dir.blog"] +
["Rakefile"]
<<--

###gemspecでローカルで正しいgemが作れるかテストする
下記のコマンドで生成されたgemをインストールし、展開後のdirを見たりテストを実行したりして正しくgemが作られているかテストします。

shell>>
$ gem build prawn.gemspec
<<--

###githubでgems.githum.comの一覧に入れてもらう手順

  1. prawn.gemspecというファイルを用意する
  2. コミット
    shell>>
    git push prawn.gemspec -m "add gemspec file"
    <<--
  3. https://github.com/satoko/prawn/editRubyGemにチェックする
  4. gem searchで所望のgemが出てくるのを待つ(max 15分くらい?)
    shell>>
    $ gem search satoko-prawn -r
    *** REMOTE GEMS ***
    satoko-prawn (0.2.99.2)
    <<--

(注意)一覧とはここです。

###Refs
http://d.hatena.ne.jp/akm/20080621#1214036969
http://docs.rubygems.org/read/chapter/20
http://code.google.com/p/rubeus/source/browse/trunk/rubeus.gemspec#

posted by satoko satoko on Thu 2 Oct 2008 at 10:14 with 1 comment

以前書いた**prawnの記事**ですが、その時のgemは0.1.2でした。で色々ggってソースを読んでいくうちにどうやら最新だと:wrap => :characterオプションがあることがわかりました。というわけでgithubからインストールした時のメモです。

###gems.githubにない
http://gems.github.com/list.html
を見てもprawnはありません。ということでcloneしてインストールすることにしました。

###cloneしてgemを生成, インストール
shell>>
$git clone git://github.com/raggi/prawn.git prawn.git
$ cd prawn.git
$ rake gem
$ ls pkg/prawn-0.1.99.gem
pkg/prawn-0.1.99.gem
$sudo gem install pkg/prawn-0.1.99.gem
$gem search prawn

*** LOCAL GEMS ***
prawn (0.1.99, 0.1.2)
<<--

###gemのバージョンについて
prawnのバージョンが0.1.99とでていますが、あくまでもpre-0.2としての位置づけだそうで(作者のsandalさんに教えてもらった)、バグ報告などの場合は、git logで表示されるcommitの後のSHA1をバージョンとして用いるそうです。

shell>>
$git log
commit c92a03685cd013af8767e7327b3a5def74a0a2ff
Date: Wed Aug 20 17:45:18 2008 -0400

Minimal changes to support character based wrapping

<<--

posted by satoko satoko on Tue 9 Sep 2008 at 11:15 with 0 comments