Windows で Cygwin の Git を使うときに

NTEmacs は(当然ながら) Cygwin の file permission を無視してファイルを保存します。

そのため、Cygwin の Git で管理しているファイル群を NTEmacs で変更すると、file mode の変更が頻繁に検出されてしまいます。

そこで、git diff の結果を使用して、必要があれば file mode を元に戻す hook を書いた……のですが、書き終ったあとに

$ git config core.filemode false

だけで良い事がわかりました :(

何となく惜しいので、書いたコードも晒しておきます。後で何かの役に立ちますように……。

(and
 (eq system-type 'windows-nt)
 (executable-find "chmod")
 (add-hook 'after-save-hook
	   (lambda ()
	     (let*
		 ((git-dir (egg-git-dir))
		  (base-dir (and git-dir
				 (string-match "\\(.+\\).git" git-dir)
				 (match-string 1 git-dir)))
		  (file-name (and base-dir
				  (string-match (format "%s\\(.+\\)" base-dir)
						(buffer-file-name))
				  (match-string 1 (buffer-file-name))))
		  (old-mode (and file-name
				 (with-temp-buffer
				   (call-process "git" nil t t "diff" file-name)
				   (goto-char (point-min))
				   (when (re-search-forward "^old mode.+\\([0-9]..\\)$" nil t)
				     (match-string 1))))))

	       (when old-mode
		 (call-process "chmod" nil t t old-mode (buffer-file-name)))))))