/
atom.xml
472 lines (358 loc) · 15.6 KB
/
atom.xml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
<title><![CDATA[Category: git | @znz blog]]></title>
<link href="http://blog.n-z.jp/blog/categories/git/atom.xml" rel="self"/>
<link href="http://blog.n-z.jp/"/>
<updated>2014-04-09T09:49:24+09:00</updated>
<id>http://blog.n-z.jp/</id>
<author>
<name><![CDATA[Kazuhiro NISHIYAMA]]></name>
</author>
<generator uri="http://octopress.org/">Octopress</generator>
<entry>
<title type="html"><![CDATA[pre-commit hookでmasterへのcommitを禁止した]]></title>
<link href="http://blog.n-z.jp/blog/2014-02-07-pre-commit-hook.html"/>
<updated>2014-02-07T16:57:54+09:00</updated>
<id>http://blog.n-z.jp/blog/pre-commit-hook</id>
<content type="html"><![CDATA[<p>git flow を使っていて、
<code>git flow release finish</code>
後に master ブランチのままなのに気付かずに
develop ブランチのつもりで git commit してしまうということが起きるので、
pre-commit hook で禁止するようにしてみました。</p>
<!--more-->
<h2>参考</h2>
<p>twitter で
<a href="https://github.com/bleis-tift/Git-Hooks/blob/rewrite/hooks/pre-commit">https://github.com/bleis-tift/Git-Hooks/blob/rewrite/hooks/pre-commit</a>
というのを教えてもらって、
Git.pm に依存しているこれをそのまま使うのは面倒そうだったので、
シェルスクリプトで実装してみました。</p>
<h2>pre-commit の引数</h2>
<p>さきほどの pre-commit だと <code>my $gitdir = shift;</code> としていて、
pre-commit の第一引数で git-dir が渡されるのかと思ったのですが、
実際に試してみるとそんなことはなくて、
<code>.git/hooks/pre-commit.sample</code>
をみても <code>--git-dir</code> は付けていなかったので、
付けずに git コマンドを呼び出すことにしました。</p>
<h2>is_master_branch</h2>
<p><code>is_master_branch</code> の実装を GitHub の検索を使って探してみると
<code>git --git-dir="$dir" symbolic-ref HEAD 2>/dev/null</code>
の結果を
<code>s"refs/heads/""</code>
で処理して
<code>'master'</code>
と比較しているだけだったので、</p>
<p><code>``sh is_master_branch
if test "</code>git symbolic-ref HEAD | sed -e ’s:^refs/heads/::‘`“ = master; then</p>
<pre><code>echo "cannot commit on master branch."
exit 1
</code></pre>
<p>fi
```</p>
<p>とすることにしました。</p>
<p>pre-commit.sample を pre-commit にコピーして、
<code>exec 1>&2</code>
の下に追加しました。</p>
<h2>pre-commit 全体</h2>
<p>元の pre-commit.sample からコピーした部分も含めて、
pre-commit hook 全体は以下のようになりました。</p>
<p>```sh .git/hooks/pre-commit</p>
<h1>!/bin/sh</h1>
<p>#</p>
<h1>An example hook script to verify what is about to be committed.</h1>
<h1>Called by “git commit” with no arguments. The hook should</h1>
<h1>exit with non-zero status after issuing an appropriate message if</h1>
<h1>it wants to stop the commit.</h1>
<p>#</p>
<h1>To enable this hook, rename this file to “pre-commit”.</h1>
<p>if git rev-parse —verify HEAD >/dev/null 2>&1
then</p>
<pre><code>against=HEAD
</code></pre>
<p>else</p>
<pre><code># Initial commit: diff against an empty tree object
against=4b825dc642cb6eb9a060e54bf8d69288fbee4904
</code></pre>
<p>fi</p>
<h1>If you want to allow non-ascii filenames set this variable to true.</h1>
<p>allownonascii=$(git config hooks.allownonascii)</p>
<h1>Redirect output to stderr.</h1>
<p>exec 1>&2</p>
<p>if test “<code>git symbolic-ref HEAD | sed -e 's:^refs/heads/::'</code>” = master; then</p>
<pre><code>echo "cannot commit on master branch."
exit 1
</code></pre>
<p>fi</p>
<h1>Cross platform projects tend to avoid non-ascii filenames; prevent</h1>
<h1>them from being added to the repository. We exploit the fact that the</h1>
<h1>printable range starts at the space character and ends with tilde.</h1>
<p>if [ “$allownonascii” != “true” ] &&</p>
<pre><code># Note that the use of brackets around a tr range is ok here, (it's
# even required, for portability to Solaris 10's /usr/bin/tr), since
# the square bracket bytes happen to fall in the designated range.
test $(git diff --cached --name-only --diff-filter=A -z $against |
LC_ALL=C tr -d '[ -~]\0' | wc -c) != 0
</code></pre>
<p>then</p>
<pre><code>echo "Error: Attempt to add a non-ascii file name."
echo
echo "This can cause problems if you want to work"
echo "with people on other platforms."
echo
echo "To be portable it is advisable to rename the file ..."
echo
echo "If you know what you are doing you can disable this"
echo "check using:"
echo
echo " git config hooks.allownonascii true"
echo
exit 1
</code></pre>
<p>fi</p>
<h1>If there are whitespace errors, print the offending file names and fail.</h1>
<p>exec git diff-index —check —cached $against —
```</p>
]]></content>
</entry>
<entry>
<title type="html"><![CDATA[octopressをアップデートしてisolateを使い始めた]]></title>
<link href="http://blog.n-z.jp/blog/2013-12-21-update-octopress.html"/>
<updated>2013-12-21T22:43:36+09:00</updated>
<id>http://blog.n-z.jp/blog/update-octopress</id>
<content type="html"><![CDATA[<p>気が向いたので、また octopress の更新をしてみました。
そして <code>rake isolate</code> を使い始めました。</p>
<p>記事中では <code>git fetch --prune</code> とか、
zsh の <code>(mm-1)</code> を使っているので、
カテゴリに <code>git</code> と <code>zsh</code> も付けています。</p>
<!--more-->
<h2>octopress のアップデート</h2>
<p><code>git fetch</code> します。
最近は <code>--prune</code> を付けてリモートで削除されたブランチは手元でも削除されるようにしていることが多いので、
今回も付けています。</p>
<p><code>console
% git remote -v
octopress git://github.com/imathis/octopress.git (fetch)
octopress git@github.com:imathis/octopress.git (push)
origin git@github.com:znz/znz.github.io (fetch)
origin git@github.com:znz/znz.github.io (push)
origin ssh://git@bitbucket.org/znz/blog.n-z.jp.git (push)
% git fetch --prune octopress
remote: Counting objects: 33, done.
remote: Compressing objects: 100% (18/18), done.
remote: Total 24 (delta 16), reused 14 (delta 6)
Unpacking objects: 100% (24/24), done.
From git://github.com/imathis/octopress
* [new branch] jekyll-1-3 -> octopress/jekyll-1-3
64ba603..78defff master -> octopress/master
%
</code></p>
<p>差分を確認してからマージしました。</p>
<p><code>console
% git diff source...octopress/master
% git merge octopress/master
Auto-merging Rakefile
Merge made by the 'recursive' strategy.
.themes/classic/sass/base/_theme.scss | 2 +-
.themes/classic/source/_includes/archive_post.html | 2 +-
.themes/classic/source/_includes/custom/category_feed.xml | 4 +-
.themes/classic/source/_includes/disqus.html | 2 +-
.themes/classic/source/_includes/head.html | 4 +-
.themes/classic/source/atom.xml | 4 +-
README.markdown | 2 +-
Rakefile | 6 +--
plugins/category_generator.rb | 3 +-
plugins/code_block.rb | 2 +-
plugins/date.rb | 53 +++++++++----------------
plugins/gist_tag.rb | 8 +++-
plugins/include_code.rb | 2 +-
plugins/jsfiddle.rb | 2 +-
14 files changed, 41 insertions(+), 55 deletions(-)
</code></p>
<p>themes も更新されているので、
<a href="http://octopress.org/docs/updating/">Updating Octopress</a>
の手順に従ってアップデートしました。</p>
<p><code>console
% bundle install
Using rake (0.9.2.2)
Using RedCloth (4.2.9)
Using chunky_png (1.2.5)
Using fast-stemmer (1.0.1)
Using classifier (1.3.3)
Using fssm (0.2.9)
Using sass (3.2.9)
Using compass (0.12.2)
Using directory_watcher (1.4.1)
Using haml (3.1.7)
Using kramdown (0.13.8)
Using liquid (2.3.0)
Using syntax (1.0.0)
Using maruku (0.6.1)
Using posix-spawn (0.3.6)
Using yajl-ruby (1.1.0)
Using pygments.rb (0.3.4)
Using jekyll (0.12.0)
Using rack (1.5.2)
Using rack-protection (1.5.0)
Using rb-fsevent (0.9.1)
Using rdiscount (2.0.7.3)
Using rubypants (0.2.0)
Using sass-globbing (1.0.0)
Using tilt (1.3.7)
Using sinatra (1.4.2)
Using stringex (1.4.0)
Using bundler (1.3.5)
Your bundle is complete!
Use `bundle show [gemname]` to see where a bundled gem is installed.
% bundle exec rake update_source
mkdir source.old
cp -r source/. source.old
## Copied source into source.old/
cp -r --remove-destination .themes/classic/source/. source
cp -r --remove-destination source.old/_includes/custom/. source/_includes/custom/
cp source.old/favicon.png source
## Updated source ##
% bundle exec rake update_style
mv sass sass.old
## Moved styles into sass.old/
cp -r .themes/classic/sass/ sass
cp -r sass/custom/. sass.old/custom
## Updated Sass ##
%
</code></p>
<p><code>git diff</code> で確認するとローカルでの変更が消えてしまっていたので、
<code>git checkout ファイルパス</code> で戻したり、
再適用したりしてからコミットしました。</p>
<h2>rake isolate</h2>
<p><a href="http://rcmdnk.github.io/blog/2013/10/07/blog-octopress/">Octopressでチェック用に高速にgenerate/previewする</a>
で紹介されていた
<code>rake isolate[filename]</code>
を使い始めてみました。</p>
<h3>ファイル名の指定を省略する</h3>
<p>最終更新時刻でソートして最新だけ、という絞り込みをしたかったのですが、
zsh の機能だけでうまく表現できなかったので、
<a href="http://qiita.com/mollifier/items/1c4a4930a89aa75e5ced">zsh で find を使わずに簡単にファイルを絞り込む</a>
を参考にして1分以内に変更されたファイルだけという絞り込みで妥協することにしました。</p>
<p><code>console
bundle exec rake "isolate[$(echo source/_posts/*.markdown(mm-1))]"
bundle exec rake preview
bundle exec rake integrate
</code></p>
<h3>rake integrate 忘れを防ぐ</h3>
<p>isolate した状態で deploy する事故を防ぐために
<a href="https://github.com/imathis/octopress/pull/1444">check stash dir before deploy</a>
という変更を入れてから使うようにしてみました。</p>
<p>Rakefile をみてみると</p>
<p><code>ruby Rakefile
desc "Generate website and deploy"
task :gen_deploy => [:integrate, :generate, :deploy] do
end
</code></p>
<p>となっているので、
<code>bundle exec rake deploy</code> ではなく
<code>bundle exec rake gen_deploy</code> を使うようにしていれば
大丈夫そうですが、
念のためチェックした方が安全だと思いました。</p>
<p>octopress の fork で作成したこの変更は</p>
<p><code>console
git pull git@github.com:znz/octopress.git check-stash-before-deploy
</code></p>
<p>で手元の source ブランチに取り込みました。</p>
]]></content>
</entry>
<entry>
<title type="html"><![CDATA[githubでhttpsのURLを指定してもgitプロトコルやssh経由にする方法]]></title>
<link href="http://blog.n-z.jp/blog/2013-11-28-git-insteadof.html"/>
<updated>2013-11-28T22:22:00+09:00</updated>
<id>http://blog.n-z.jp/blog/git-insteadof</id>
<content type="html"><![CDATA[<p>要約すると <code>url.<base>.insteadOf</code> や <code>url.<base>.pushInsteadOf</code>
を使えば良いという話です。
github 以外でも使えます。</p>
<!--more-->
<h2>設定例</h2>
<p>自分では今のところ、以下の設定にしています。</p>
<p>最初の
<code>[url "git@github.com:"]</code>
のセクションは URL の指定として
<code>https:</code> や <code>git:</code> を使っていても
<code>git push</code> のときには <code>ssh</code> 経由にする、
という意味になります。</p>
<p>次の
<code>[url "git://github.com/"]</code>
は、その他の <code>git fetch</code> や <code>git pull</code> の時は
<code>https:</code> の代わりに <code>git:</code> を使うという意味になります。</p>
<p>```ini ~/.gitconfig
[url “git@github.com:”]</p>
<pre><code>pushInsteadOf = git://github.com/
pushInsteadOf = https://github.com/
</code></pre>
<p>[url “git://github.com/”]</p>
<pre><code>insteadOf = https://github.com/
</code></pre>
<p>```</p>
<h2>pushInsteadOf なしの場合</h2>
<p><code>pushInsteadOf</code> を指定せずに <code>insteadOf</code> だけの場合は
<code>git push</code> の時も <code>insteadOf</code> の設定が使われます。</p>
<p>例えば設定例とは逆に、
proxy を通さないといけないとかの理由で
すべて https に統一したいのなら
以下のような設定になると思います。</p>
<p>```ini ~/.gitconfig
[url “<a href="https://github.com/">https://github.com/</a>”]</p>
<pre><code>insteadOf = git@github.com:
insteadOf = git://github.com/
</code></pre>
<p>```</p>
<h2>コマンドでの設定方法</h2>
<p><code>git config</code> コマンド経由で <code>pushInsteadOf</code> を設定するなら、
以下のように指定します。</p>
<p><code>~/.gitconfig</code> に <code>github.token</code> などの秘密にすべき情報が入っていて
共有しにくい時にはコマンドで設定できた方が便利です。</p>
<p><code>bash
GITHUB_URL_PREFIX="url.git@github.com:"
git config --global --remove-section "$GITHUB_URL_PREFIX" || :
git config --global "$GITHUB_URL_PREFIX".pushInsteadOf "git://github.com/"
git config --global --add "$GITHUB_URL_PREFIX".pushInsteadOf "https://github.com/"
</code></p>
<h2>設定確認方法</h2>
<p>実際にどういう URL が使われるのかは
<code>git remote -v</code>
で確認できます。</p>
<p><code>.git/config</code> の <code>remote</code> の <code>url</code> と見比べると
ちゃんと設定が反映されていることがわかると思います。</p>
<p>```console
$ git remote -v
origin git://github.com/znz/rbenv-plug.git (fetch)
origin git@github.com:znz/rbenv-plug.git (push)
$ cat .git/config
[core]</p>
<pre><code>repositoryformatversion = 0
filemode = true
bare = false
logallrefupdates = true
ignorecase = true
precomposeunicode = false
</code></pre>
<p>[remote “origin”]</p>
<pre><code>url = https://github.com/znz/rbenv-plug.git
fetch = +refs/heads/*:refs/remotes/origin/*
</code></pre>
<p>[branch “master”]</p>
<pre><code>remote = origin
merge = refs/heads/master
</code></pre>
<p>```</p>
<h2>URL の選ばれ方</h2>
<p>github の URL で説明していますが、
git の機能なので他の URL でも当然使えます。</p>
<p>URL は最初の部分だけ見て、最長一致するものが使われるようです。
git 1.8.4.3 の <code>git config --help</code> に
<code>When more than one insteadOf strings match a given URL, the longest match is used.</code>
と書いてあります。</p>
<h2>まとめ</h2>
<p><code>~/.gitconfig</code> での記述例の話はよくあるのですが、
コマンドでの設定方法とか、
設定の確認方法を見かけたことがなかったので、
まとめてみました。</p>
<p>そして github 以外でも使えるという話も付け加えておきました。</p>
]]></content>
</entry>
</feed>