====== Windows 10のEmacs 26.1でMagitを使う ====== ===== 試した環境 ===== * Windows 10 Pro. バージョン1803 * [[http://cha.la.coocan.jp/doc/NTEmacs.html|IMEパッチ適用済みEmacs 26.1]] (いわゆるNTEmacs) * PuTTY (64bit) Release 0.70 * Magit v2.13.0 ===== 手順 ===== ==== Magitのインストール ==== ''M-x package-install magit''でインストールできる・・・はずなんだけど、うちの環境では Wrong number of argumentsなるエラーが出て入らなかった(´・ω・`) 仕方ないので[[https://github.com/magit/magit|公式リポジトリ]]からzip取ってきて、LoadPathが通ってるところに設置。Magitの動作には以下のパッケージが要るので、必要に応じてM-x package-installする。 * async * dash * with-editor * git-commit * magit-popup magit-popupのみ、うちの環境では(ryだったので[[https://github.com/magit/magit-popup|公式リポジトリ]]から(ry v2.90からtransientパッケージも必要になったっぽい? ==== git実行ファイルの設定 ==== Magitはgitコマンド実行時に''magit-git-executable''変数のgitコマンドを使用する。 [[https://magit.vc/manual/magit/Git-Executable.html|マニュアル]]によれば、WindowsとmacOSではMagit読み込み時にgitコマンドの絶対パスが設定される。[[https://github.com/magit/magit/blob/456735401b6524f822fecc3fbb49a5c9199f9d4d/lisp/magit-git.el#L135|magit-git.el]]を見ると、何やらgitコマンドのパスを求める処理が確かに入っている。環境変数PATHが通っているgit.exeを自動で探してくれるようだが、上手く設定されない場合は手動で設定する。 TRAMPを使ってリモートのリポジトリを操作する場合は、''magit-remote-git-executable''が使用される。大抵、リモート環境といえばUNIX系だと思うが、その場合はデフォルト値の"git"のままで動くはず。動かなければリモート環境のgitをフルパスで設定してやる。 (require 'magit) (setq magit-git-executable "U:/msys64/usr/bin/git.exe") ;(setq magit-remote-git-executable "/path/to/remote/git") まずは何も指定せずgit管理下のファイルを開き、M-x magit-statusが動くかどうかを見るのが手っ取り早い。Git管理下にもかかわらず「Create repository in /path/to/gitrepo/?」や「Searching for program: No such file or directory, git」出たら、Magitがgitコマンドを見つけられなかった可能性が高い。それからmagit-git-executableをアレコレ指定してみるのが良いだろう。 この辺はPATHやらTRAMPの設定やら接続先の環境やらが絡んでて非常にわかりづらい。 ===== 参考サイト ===== * [[https://emacs.stackexchange.com/questions/27461/magit-doesnt-recognise-git-repo-through-ssh-connection|tramp - Magit doesn't recognise git repo through ssh connection - Emacs Stack Exchange]] * [[https://qiita.com/khiraiwa/items/bf9924f3a19c780c6ae9|EmacsのTRAMPとmagitでリモートのリポジトリを扱えなかった件について]] * [[https://stackoverflow.com/questions/26630640/tramp-ignores-tramp-remote-path|emacs - TRAMP ignores tramp-remote-path - Stack Overflow]] * [[https://emacs.stackexchange.com/questions/35055/magit-with-tramp-is-not-working-with-git-correctly|magit with tramp is not working with git correctly - Emacs Stack Exchange]] * [[https://qiita.com/takc923/items/c7a11ff30caedc4c5ba7|EmacsのGitクライアント:Magit]] * [[http://yamakichi.hatenablog.com/entry/2016/06/29/133246|Emacs Magit使い方 - yamarkz's blog]]