git/list[1] front-page[2] threads[3] people[4] search[5] about
 

'EDITOR=false git add -e' adds to index

From
RCRuss Cox <rsc@golang.org>
Date
May 13, 2015, 00:31 UTC
Message-ID
<CAA8EjDS9HePk6ZFa0kOy7GDa9_c_TsJ7uv7t+N9RL-3z=ZrQFQ@mail.gmail.com>

In contrast to most other git commands, git add -e does not check whether the editor it invokes exits successfully. This means that if you cause your editor to exit unsuccessfully, hoping to abort the add -e, the add -e continues anyway.

The specific instance I've observed is that you set EDITOR to a program that starts the editor outside the current terminal and waits for it to exit. Then you realize you didn't want to add anything and type ^C in the terminal where git is waiting for $EDITOR to finish. That makes $EDITOR exit unsuccessfully, and git prints an error about not being able to invoke the editor, but it continues on with the add -e, adding everything from the patch to the index.

I am using the acme editor, but I believe that EDITOR='emacs -nw' or EDITOR='subl -w' for Sublime Text are more common settings that would have the same problem. In a test, EDITOR=false suffices.

The root cause seems to be that builtin/add.c's edit_patch does not check the result of the launch_editor call. It probably should.

The call to launch_editor in builtin/config.c should probably also be checked, although there it's not as big a deal, provided the editor did not modify the file; reapplying the same file should be a no-op. This is different from git add -e.

I am seeing this behavior with git 2.2.1, but I checked the main repo and commit c518059 from yesterday still has the unchecked launch_editor call.

Thanks. Russ

Next: Jeff King
Message 1 of 3 in “'EDITOR=false git add -e' adds to index”
  1. Russ CoxMay 13, 2015
  2. add: check return value of launch_editorJeff King, May 13, 2015
  3. Johannes SchindelinMay 13, 2015

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.