2010/02/17

git push error

% git push origin master
を実行したら

 ! [rejected]        master -> master (non-fast-forward)

error: failed to push some refs to (...略) 
To prevent you from losing history, non-fast-forward updates were rejected
Merge the remote changes before pushing again.  See the 'non-fast-forward'
section of 'git push --help' for details.


となってしまった。思い当たることとしては OS を再インストールして git repository へのパスを変えてしまったことと git のバージョンをあげたこと。

% git push --help

/non-fast-forward
next していたら次のような文章があった。

       There is another common situation where you may encounter non-fast-forward rejection when you try to push, and it is possible even
       when you are pushing into a repository nobody else pushes into. After you push commit A yourself (in the first picture in this
       section), replace it with "git commit --amend" to produce commit B, and you try to push it out, because forgot that you have pushed A
       out already. In such a case, and only if you are certain that nobody in the meantime fetched your earlier commit A (and started
       building on top of it), you can run "git push --force" to overwrite it. In other words, "git push --force" is a method reserved for a
       case where you do mean to lose history.

辞書をひきつつ 2 回読んでみたけどもなぜこうなってしまったのか?や、どうすればいいのか?は読み解けない。

Google にて "non-fast forward"
を検索してみたところ
http://blog.digital-squad.net/article/132085683.html

こういうときは --forceオプションをつけてやることで強制的にpushできる。
git push origin master --force

とありまして --force をつけて試してみるとあっさり git push に成功しました。とても助かりました。
一時は ssh-keygen で鍵を作りなおさなくちゃいけないのかと思った。

さて、落ち着いてから上の英文を読みなおすと

you can run "git push --force" to overwrite it. In other words, "git push --force" is a method reserved for a
       case where you do mean to lose history.

... "git push --force" はあなたが歴史を失うケースに備えての予備のメソッド?
間違えて読んでる可能性大だけど歴史を失うとはどういうことだろ。
OS 再インストールしてパスが変わってるから何かが失われたってことなのかな。何が?

% git log
ちゃんと動いてる。最初からのlog もみえてる。はて?

+++ 教訓 +++

% git push midore@github.com:midore/mblogger.git

などしても

...
Permission denied (publickey).
fatal: The remote end hung up unexpectedly

エラーになる。だからといって ~/.ssh/ の中の鍵のパーミションが関係してる?とか考えない。

remote 先を明示したい時は

% git push git@github.com:midore/mblogger.git


~/.gitconfig や ~/.ssh/ にゆるぎない自信があれば

% git push origin master

で OK.

[後日談]
入門Git(秀和システム) を読みましてこの時何がおこっていたか?を考えてみました。
p81 に non fast forward エラーについて解説がありました。

私の場合OS を入れ替える前にバックアップをとり、OS を新規インストールした後にこのバックアップから
local git repository を読み込んだわけだけどもバックアップした直後で新規インストールする直前に
github.com/midore/mdiary に対してgit push しちゃっていたのかもしれません(驚)
だとすればこの挙動はものすごく納得がいきます。
バックアップとった後に git push した記憶がない自分が怖い...

私がうっかり git push していたのならば上記の対処は正しいやり方じゃなかったようです。
% git pull
を使い
(pull 先は add remote した先を指し、clone したproject の場合は自動的にclone 元になるそうだ)
github.com においてあるリポジトリの最新コミットと手元のリポジトリのコミットをマージさせるべきでした。
git pull してみればどこで conflict していたか明らかになったはずなのでした。
(ただしgit push した記憶がない状態で pull する勇気をもてたかは不明)
conflict メッセージがでていたのならそのファイルを編集した上でcommit するべきだったのかもしれません。

2010/02/16

Remove resource fork in AppleScript

私は Twitter に参加していませんが何日か前に Google Reader で
急募: OS XのiTunesから、mp3ファイルを_リソースフォークなしに...
を見かけました。

早速 AppleScript で try

tell application "Finder"
  set src to quoted form of POSIX path of (choose folder)
  set dst to quoted form of POSIX path of (choose folder)
  set str to "ditto -v --norsrc  " & src & "  " & dst
  do shell script str
end tell

日本語名のフォルダを指定しても大丈夫でした。でもこれだけだと愛想がないのでいろいろ付け足し。

# remove-resource-forlk.scpt
tell application "Finder"
  # フォルダを選択
  set src to quoted form of POSIX path of (choose folder with prompt "リソースフォークをまるっと取り除きたいフォルダを選択してください。")
  # 保存先フォルダの選択
  set dst to quoted form of POSIX path of (choose folder with prompt "保存先であるフォルダを選択してください。")
  # コマンド文字列
  set str to "ditto -v --norsrc  " & src & "  " & dst
  if src is dst then
    set err_str to "指定したフォルダと保存先であるフォルダが同じです!異なるフォルダを選択してください。"
    display dialog err_str buttons {"OK"} default button 1 with icon 2 with title "Error"
    return
  end if
  set warn_str to "多くのファイルが含まれているフォルダを選択した場合時間がかかる(数分)場合があります。よろしいですか?"
  display dialog warn_str buttons {"OK", "Cancel"} default button 2 with icon 2 with title "Warning"
  try
  # コマンドの実行
  set res to do shell script str
  on error num
    display dialog "エラーが発生しました。" buttons {"OK"} default button 1
    return
  end try
  if res is "" then display dialog "おわりました。" buttons {"OK"} default button 1 with icon 1 with title "Success"
end tell


[用途]
フォルダに含まれるファイルからリソースフォークを削除したファイルを保存先フォルダに保存します。(もとのファイル名は維持されます。)
複数のフォルダを内包しているフォルダを指定した場合、保存先フォルダの階層は、もとのフォルダの階層を維持します。

# iTunes Music フォルダにあるミュージシャン(Artist) の名前がついたフォルダを選択すると、そこに含まれるアルバム名のついたフォルダにある音楽ファイル( 末尾に.m4a .mp3 などの名前のついたファイル)から、リソースフォークを削除したものを、保存先フォルダに保存します。
# ターミナルからコマンドを叩くことなく、操作できます。

[使い方]
Finder メニュ-> 移動-> アプリケーションを開く (Command + Shift + A でApplication フォルダ を表示)
->ユーティリティ ->AppleScript Editor.app(AppleScript エディタ.app) をダブルクリックで起動し新しいファイルを作り上記をコピー and ペーストします。

1, コマンドKey(⌘) + K でコンパイルします。
2, コマンドKey(⌘) + S で File 保存(必ずスクリプト として)
3, コマンドKey(⌘) + R で実行 です。

処理がおわると『おわりました。』と表示します。エラーが発生した場合は『エラーが発生しました。』と表示します。

複数のアルバムフォルダが含まれている ミュージシャン(Artist) のフォルダなどを選択するとファイル数にして何百曲などのファイルを処理することになります。その場合ものすごく時間がかかる(数分)こともあります。なので最初は下記の手順でテストしてみてどのくらい時間がかかるものかを体感してみてください。

[テスト手順]
(1) デスクトップに2つ新規フォルダを作りそれぞれ「SRC」「DST」と名付けておく。
(2) 「SRC」フォルダの中にリソースフォークを取り除きたいフォルダを1 つだけコピーしておく。
  その際極力ファイル数の少ないフォルダを選ぶ。
「DST」フォルダは空っぽのままにしておく。
(3) 保存しておいた AppleScript ファイルを開いてから コマンドKey(⌘) + R をおす。または「実行」ボタンを押す。
「リソースフォークをまるっと...」ときかれたら「SRC」を選ぶ。
「保存先...」 ときかれたら 「DST」を選ぶ。

処理している間はなんのメッセージも表示しません。
10 枚程のファイルを処理した場合 2,3 秒でおわります。

# 注意1:
OS X 10.5x 時代のファイルにはリソースフォークがついてるけど、Snow Leopard 時代に作ったファイルにはついてません。

# 注意2:
指定フォルダとしてミュージシャン(Artist)名のついたフォルダを指定し
保存先フォルダには適当な名前(「test」とか)のフォルダを指定し実行した場合

iTunes->詳細->”iTunes Media”フォルダを整理する
にチェックをいれてから保存先フォルダ(「test」とか)を iTunes に取り込むと本来のミュージシャン(Artist)名のついたフォルダ名に自動変換されます。
(iTunes 9.03)

[ターミナルで確認]

# % ditto -h
# % xattr -h

# 指定フォルダ: test-src
# 保存先フォルダ: test-dst


指定フォルダ内

% ls -FRl test-src/
total 0
drwx------  3 foo  staff  102  2 15 16:35 Makana/
drwx------  3 foo  staff  102  2  4 11:48 平沢 進/

test-src//Makana:
total 0
drwx------  17 foo  staff  578  2 15 16:33 Different Game/

test-src//Makana/Different Game:
total 92824
-rw-------@ 1 foo  staff  4428672  6  6  2009 01 Away.m4p
-rw-------@ 1 foo  staff   623834  2  4 18:09 02 Interlude I.m4p
-rw-------@ 1 foo  staff  3821305  6  6  2009 03 Mars Declares.m4p
# ... 略

test-src//平沢 進:
total 0
drwx------  4 foo  staff  136  2  4 11:48 時空の水/

test-src//平沢 進/時空の水:
total 15344
-rw-------@ 1 foo  staff  4542192  4  4  2008 01 ハルディン・ホテル.m4p
-rw-------@ 1 foo  staff  3311160  4  4  2008 10 金星.m4p

% xattr -x test-src/Makana/Different\ Game/01\ Away.m4p 
# => com.apple.FinderInfo

% xattr -x test-src/平沢\ 進/時空の水/01\ ハルディン・ホテル.m4p
# => com.apple.FinderInfo


AppleScipt 実行後
保存先フォルダ内

% ls -FRl test-dst/
total 0
drwx------  3 foo  staff  102  2 15 16:35 Makana/
drwx------  3 foo  staff  102  2  4 11:48 平沢 進/

test-dst//Makana:
total 0
drwx------  17 foo  staff  578  2 15 16:33 Different Game/

test-dst//Makana/Different Game:
total 92824
-rw-------  1 foo  staff  4428672  6  6  2009 01 Away.m4p
-rw-------  1 foo  staff   623834  2  4 18:09 02 Interlude I.m4p
-rw-------  1 foo  staff  3821305  6  6  2009 03 Mars Declares.m4p
# ... 略

test-dst//平沢 進:
total 0
drwx------  4 foo  staff  136  2  4 11:48 時空の水/

test-dst//平沢 進/時空の水:
total 15344
-rw-------  1 foo  staff  4542192  4  4  2008 01 ハルディン・ホテル.m4p
-rw-------  1 foo  staff  3311160  4  4  2008 10 金星.m4p

% xattr -x test-dst/Makana/Different\ Game/01\ Away.m4p
# => 何もかえってこない。

% xattr -x test-dst/平沢\ 進/時空の水/01\ ハルディン・ホテル.m4p
# => 何もかえってこない。


[2010-02-16]
s/errr_str/err_str/g
s/warm_str/warn_str/g
s/やめる/Cancel/g
[2010-02-18]
s/folk/fork/g

2010/02/11

Snow Leopard Re-Install memo

# backup
$ sudo launchctl bslist -j > default-launchctl-bslist.txt
# PRAM Clear
# $ sudo nvram -c -xp

0) Remove Extensions
# Bluetooth
$ sudo srm -rf /System/Library/Extensions/IOBluetooth*
# iSight
$ sudo srm -rf /System/Library/Extensions/Apple_iSight.kext/
$ sudo srm -rf /System/Library/Extensions/IOUSBFamily.kext/Contents/PlugIns/AppleUSBVideoSupport.kext/

# Touch
$ sudo touch /System/Library/Extensions/

# blued
$ sudo launchctl unload -w /System/Library/LaunchDaemons/com.apple.blued.plist
$ sudo chmod 600 /usr/sbin/blued

$ sudo reboot

1) mDNSResponder.plist
$ ps aux | grep mDNS
# => ... /usr/sbin/mDNSResponder -launchd

$ sudo vi /System/Library/com.apple.mDNSResponder.plist
$ sudo vi /System/Library/LaunchDaemons/com.apple.mDNSResponder.plist

        <array>
                <string>/usr/sbin/mDNSResponder</string>
                <string>-launchd</string>
                <string>-NoMulticastAdvertisements</string>
        </array>


# Reload com.apple.mDNSResponder.plist
$ sudo launchctl unload /System/Library/LaunchDaemons/com.apple.mDNSResponder.plist
$ sudo launchctl load /System/Library/LaunchDaemons/com.apple.mDNSResponder.plist

$ ps aux | grep mDNS
# => .... /usr/sbin/mDNSResponder -launchd -NoMulticastAdvertisements

See: support.apple.com/kb/HT3789

2) change mode
$ man samba
$ apropos smbd

$ sudo chmod 600 /usr/sbin/nmbd
$ sudo chmod 600 /usr/sbin/smbd
$ sudo chmod 600 /usr/sbin/cupsaddsmb

$ sudo chmod 600 /usr/bin/smb*
$ sudo chmod 600 /usr/bin/nmblookup
$ sudo chmod 600 /etc/smb.conf
$ sudo chmod 600 /etc/smb.conf.template

# httpd
$ sudo chmod 600 /usr/sbin/httpd

# sshd
$ sudo chmod 600 /usr/sbin/sshd

# ftpd
# sudo chmod 600 /usr/libexec/ftpd

# nfsd
$ sudo chmod 600 /sbin/nfsd

# Apple FileServer
# $ ls -la /usr/sbin/AppleFileServer
$ sudo chmod 0 /System/Library/CoreServices/AppleFileServer.app/Contents/MacOS/AppleFileServer

# ae server (Apple Event)
# $ more /System/Library/LaunchDaemons/com.apple.eppc.plist
$ sudo chmod 0 /System/Library/Frameworks/CoreServices.framework/Frameworks/AE.framework/Versions/A/Support/AEServer

# Problem Reporter
$ sudo chmod 600 /System/Library/CoreServices/Problem\ Reporter.app/Contents/MacOS/Problem\ Reporter

See: http://www.macosxhints.com/

# Plug-Ins
$ ls -la /Library/Internet\ Plug-Ins/
$ sudo chmod 700 /System/Library/Frameworks/JavaVM.framework/Resources/JavaPluginCocoa.bundle
$ sudo chmod 700 /Library/Internet\ Plug-Ins/Flash Player.plugin
$ sudo chmod 700 /Library/Internet\ Plug-Ins/QuickTime Plugin.plugin
$ sudo chmod 0 /Library/Internet\ Plug-Ins/NP-PPC-Dir-Shockwave
$ ls -la /Library/Internet\ Plug-Ins/

3) launchctl unload
$ sudo launchctl unload -w /System/Library/LaunchDaemons/org.cups.cupsd.plist
$ sudo launchctl unload -w /System/Library/LaunchDaemons/org.x.privileged_startx.plist
$ sudo launchctl unload -w /System/Library/LaunchDaemons/com.apple.webdavfs_load_kext.plist

# com.apple.smb.server.preferences.plist com.apple.smb.sharepoints.plist com.apple.smbfs_load_kext.plist
$ sudo launchctl unload -w /System/Library/LaunchDaemons/com.apple.smb.sharepoints.plist
$ sudo launchctl unload -w /System/Library/LaunchDaemons/com.apple.smb.server.preferences.plist
$ sudo launchctl unload -w /System/Library/LaunchDaemons/com.apple.smbfs_load_kext.plist

$ sudo launchctl unload -w /System/Library/LaunchDaemons/com.apple.RFBRegisterMDNS_ScreenSharing.plist
$ sudo launchctl unload -w /System/Library/LaunchDaemons/com.apple.RFBRegisterMDNS_RemoteManagement.plist

$ sudo launchctl unload -w /System/Library/LaunchDaemons/com.apple.printtool.plist
$ sudo launchctl unload -w /System/Library/LaunchDaemons/com.apple.portmap.plist
$ sudo launchctl unload -w /System/Library/LaunchDaemons/com.apple.nfsd.plist
$ sudo launchctl unload -w /System/Library/LaunchDaemons/com.apple.RemoteDesktop.PrivilegeProxy.plist
$ sudo launchctl unload -w /System/Library/LaunchDaemons/com.apple.IIDCAssistant.plist

# 2010-03-30
$ sudo launchctl unload -w /System/Library/LaunchDaemons/com.apple.dashboard.advisory.fetch.plist

# /System/Library/Filesystems/AppleShare/check_afp.app/Contents/MacOS/check_afp
# $ more /System/Library/LaunchDaemons/com.apple.afpfs_checkafp.plist

# /System/Library/Filesystems/AppleShare/afpLoad
# $ more /System/Library/LaunchDaemons/com.apple.afpfs_afpLoad.plist

# /System/Library/PrivateFrameworks/SoftwareUpdate.framework/Resources/suhelperd
# $ more /System/Library/LaunchDaemons/com.apple.suhelperd.plist

$ sudo launchctl bslist -j
$ sudo lsof -i

4) Spotlight
# as admin-user
$ sudo chmod 600 /System/Library/CoreServices/Search.bundle/Contents/MacOS/Search
$ sudo mdutil -i off /Volumes/abc
$ sudo mdutil -E /Volumes/abc
$ sudo mdutil -s /Volumes/abc

See: http://www.macosxhints.com/article.php?story=20091030173117381

5) fseventsd
$ sudo touch /Volumes/abc/.fseventsd/no_log
$ sudo touch /Users/foo/.fseventsd/no_log
$ sudo chmod 644 /Users/foo/.fseventsd/no_log
$ sudo chown -R foo:staff /Users/foo/.fseventsd/

See: ファイルシステムイベントストレージの防止

# default value "ttyskeepawake" of pmset is 1.
$ sudo pmset ttyskeepawake 0

See: http://forums.applenova.com/showthread.php?t=33172

$ sudo reboot
$ Login as admin-user
$ syslog -w 120 | more

# fseventsd[xx] <Critical>: Logging disabled completely for device:1: /Users/foo

6) Login as User foo
% rm ~/.fseventsd/000000*
% mdutil -i off /Users/foo
% mdutil -E /Users/foo
% mdutil -s /Users/foo
% pmset -g

% syslog -w 30
# What is this warning ?
# (com.apple.ReportCrash) <Warning>: Falling back to default Mach exception handler. Could not find: com.apple.ReportCrash.Self

% more /System/Library/LaunchAgents/com.apple.ReportCrash.Self.plist

% launchctl list | grep Repo

-	0	com.apple.ReportPanic
-	0	com.apple.ReportCrash.Self
-	0	com.apple.ReportCrash


See: http://www.insanelymac.com/forum/index.php?showtopic=192563

# User foo
% mkdir ~/Library/LaunchAgents
# if you did't set umask
# % chmod 700 ~/Library/LaunchAgents

% cd ~/Library/LaunchAgents
% cp /System/Library/LaunchAgents/com.apple.ReportCrash.Self.Plist .

# User admin
$ su admin-user
$ cd /path/to/backup-dir/
$ sudo mv /System/Library/LaunchAgents/com.apple.ReportCrash.Self.Plist .

# logout and login as User foo
% syslog -w
# not found, "... (com.apple.ReportCrash) <Warning>: (...) Could not find: com.apple.ReportCrash.Self"

[2010-02-11]
# RemotManagement
# $ sudo srm -rf /System/Library/CoreServices/RemoteManagement/
# or
# cd /path/to/backup-dir/
# $ sudo mv /System/Library/CoreServices/RemoteManagement/ .

[2010-02-12]
# User foo
# % launchctl list | grep Remote
# => exist.

# Admin user
# $ grep 'Remote' /System/Library/LaunchAgents/*
# $ sudo mv /System/Library/LaunchAgents/com.apple.RemoteDesktop.plist /path/to/backup-dir/
# $ sudo mv /System/Library/LaunchAgents/com.apple.ScreenSharing.plist /path/to/backup-dir/

# reboot

# User foo
# % launchctl list | grep Remote
# => not exist.


[2010-05-31]
Apple Releases Snow Leopard Security Configuration Guide
http://blog.intego.com/2010/05/26/apple-releases-snow-leopard-security-configuration-guide/

Apple has released their Snow Leopard Security Configuration Guide,


Mac OS X Security Configuration Guides
http://www.apple.com/support/security/guides/