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

Re: default editor

From
Jeff King <peff@peff.net>
Date
Feb 7, 2021, 18:37 UTC
Message-ID
<YCAzcs1e08Qnk2wa@coredump.intra.peff.net>
In-Reply-To
<xmqqlfbz927i.fsf@gitster.c.googlers.com>
On Sun, Feb 07, 2021 at 10:12:33AM -0800, Junio C Hamano wrote:
Show 19 quoted lines
> > I don't think the return value is the problem.  Both Unix and Windows
> > return 0 on success and nonzero on error, and Git will interpret
> > editor return codes that way.
> 
> When git spawns an editor, it is asking the editor to give the text
> file that has been edited by the end user into a shape that the end
> user is happy with.  A non-zero exit is a way for the end user to
> tell the editor (and hence git) that, even though the user has ended
> the editor session, the resulting contents is not satisfactory and
> not to be used.
> 
> If the 'ed' in question behaves the same as traditional UNIX 'ed' (I
> am guessing so, as even this is on Windows, Cygwin was mentioned),
> you can start making changes and attempt to quit without saving by
> typing 'q<RET>' twice (the first one will be greeted with '?'
> meaning "are you sure you want to quit without saving", and the
> second one lets you quit).  'ed' will signal the calling environment
> that the editor session was aborted by exiting with a non-zero
> status.

There are lots of ways to make ed exit non-zero. Any invalid command during the session will do. E.g.:

       $ echo bar >foo
       $ ed foo
 ed -> 4
 me -> l
 ed -> bar$
 me -> 2l
 ed -> ?
 me -> q
       $ echo $?
       1

The "2l" was bogus (there is no line 2). It seems likely that an interactive user might make at least one invalid command while editing. Some versions (like GNU ed) have a "-l" option to loosen the exit code.

-Peff
Previous: Junio C HamanoNext: brian m. carlson
Message 4 of 9 in “default editor”
  1. M Douglas McIlroyFeb 7, 2021
  2. brian m. carlsonFeb 7, 2021
  3. Junio C HamanoFeb 7, 2021
  4. Jeff KingFeb 7, 2021
  5. brian m. carlsonFeb 7, 2021
  6. Eric SunshineFeb 7, 2021
  7. Adam DinwoodieFeb 8, 2021
  8. M Douglas McIlroyFeb 11, 2021
  9. Eric SunshineFeb 12, 2021

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.