git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: Jeff King <peff@peff.net>
To: Junio C Hamano <gitster@pobox.com>
Cc: "brian m. carlson" <sandals@crustytoothpaste.net>,
	M Douglas McIlroy <m.douglas.mcilroy@dartmouth.edu>,
	git@vger.kernel.org
Subject: Re: default editor
Date: Sun, 7 Feb 2021 13:37:38 -0500	[thread overview]
Message-ID: <YCAzcs1e08Qnk2wa@coredump.intra.peff.net> (raw)
In-Reply-To: <xmqqlfbz927i.fsf@gitster.c.googlers.com>

On Sun, Feb 07, 2021 at 10:12:33AM -0800, Junio C Hamano wrote:

> > 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

  reply	other threads:[~2021-02-07 18:38 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-02-07 13:24 default editor M Douglas McIlroy
2021-02-07 17:35 ` brian m. carlson
2021-02-07 18:12   ` Junio C Hamano
2021-02-07 18:37     ` Jeff King [this message]
2021-02-07 19:09       ` brian m. carlson
2021-02-07 21:57       ` Eric Sunshine
2021-02-08 10:03         ` Adam Dinwoodie
2021-02-11 15:15           ` M Douglas McIlroy
2021-02-12  6:03             ` Eric Sunshine

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: http://vger.kernel.org/majordomo-info.html

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=YCAzcs1e08Qnk2wa@coredump.intra.peff.net \
    --to=peff@peff.net \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=m.douglas.mcilroy@dartmouth.edu \
    --cc=sandals@crustytoothpaste.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).