最近Visual Studio CodeのDev Containerを使って開発している。 使い始めのときgit commitを試みたところ、「Waiting for your editor to close the file... 」と出てきて焦ったため解消法をメモしておく。
エラー内容
「vimなんてないからコミットメッセージが編集できませんよ」と言われている。
node ➜ /workspaces/repository (branch-name) $ git commit → No staged files match any configured task. hint: Waiting for your editor to close the file... vim -c "set fenc=utf-8": 1: vim: not found error: There was a problem with the editor 'vim -c "set fenc=utf-8"'. Please supply the message using either -m or -F option.
devcontainer.json
TypeScript + Node.js用のimageを使っている。Dev Containerの設定はOSのgitconfig設定を引き継ぐように設定している。
{ "name": "Node.js & TypeScript", "image": "mcr.microsoft.com/devcontainers/typescript-node:0-20", "features": { "ghcr.io/devcontainers/features/node:1": {} } }
解消法
gitconfigの設定を変更し、git commit用のエディタを再指定し直す。 「core.editor」でcommitやgit tagのメッセージを編集するために利用するエディタを設定する。
利用したいエディタを指定すれば良い。
Vimを使いたい場合
Vimでコミットメッセージを書くのに慣れている場合、vim.tinyを指定する。
git config --global core.editor "vim.tiny"
Visual Studio Codeのエディタを使いたい場合
code --waitコマンドを使ってVisual Studio Codeのエディタを起動する。
git config --global core.editor "code --wait"
原因
OS用の設定をDev Containerの設定でも引き継ぐようにしているが、Dev Containerが動くimageにVimは存在しない。
理由はimageのOSがDebianなので、デフォルトではvim
ではなくvim.tiny
(Vimの簡易版)がインストールされているため。
結果、エラーメッセージの通り「Vimがないためコミットメッセージが書けない」状態となる。
OSのgitconfig設定の確認
--get
オプションを利用し、デフォルトの設定状況を確認してみる。これを引き継ぐため、Dev Containerのgitconfigも同じ設定になっている。
$ git config --get core.editor vim -c "set fenc=utf-8"
Dev Container imageのOSを確認
OS情報は/etc/xxx-release
などで確認できる。
まずはgrepでそれらしきファイルを探す。
node ➜ /workspaces/repository (branch-name) $ ls /etc/ | grep release os-release
os-releaseファイルの中身を確認してみる。
node ➜ /workspaces/repository (branch-name) $ cat /etc/os-release PRETTY_NAME="Debian GNU/Linux 11 (bullseye)" NAME="Debian GNU/Linux" VERSION_ID="11" VERSION="11 (bullseye)" VERSION_CODENAME=bullseye ID=debian HOME_URL="https://www.debian.org/" SUPPORT_URL="https://www.debian.org/support" BUG_REPORT_URL="https://bugs.debian.org/"
Debianだった。Vimのアプリケーションが存在するか確認してみる。/usr/bin
にコマンドやプログラムが保存されているのでlsしてみる。
node ➜ /workspaces/repository (branch-name) $ ls -al /usr/bin/vim ls: cannot access '/usr/bin/vim': No such file or directory
存在しない。仮説は当たっていると言える。一応簡易版Vimがあるか確認する。
node ➜ /workspaces/repository (branch-name) $ ls -al /usr/bin/vim.tiny -rwxr-xr-x 1 root root 1404616 Oct 1 2021 /usr/bin/vim.tiny
vim.tinyは存在する。こちらを使うように切り替えれば良いとわかる。
参考URL
- https://docs.github.com/en/get-started/getting-started-with-git/associating-text-editors-with-git
- https://code.visualstudio.com/docs/sourcecontrol/overview#_vs-code-as-git-editor
- https://git-scm.com/book/en/v2/Customizing-Git-Git-Configuration
- https://manpages.debian.org/unstable/vim-tiny/vi.1.ja.html
- https://stackoverflow.com/questions/52195877/how-can-i-fix-git-commit-error-waiting-for-your-editor-to-close-the-file-wi
- https://dev.classmethod.jp/articles/linux-os-version/
- https://linuc.org/study/knowledge/544/