Skip to contentSkip to conversation

rebase -i: abort cleanly if the editor fails to launch

PATCH In review Björn Gustavsson 3 participants 5 messages Jun 15, 2016

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 rebase -i: abort cleanly if the editor fails to launch

If the user's configured editor is emacsclient, the editor will fail to launch if emacs is not running and the git command that tried to lanuch the editor will abort. For most commands, all you have to do is to start emacs and repeat the command.

The "git rebase -i" command, however, aborts without cleaning the "$GIT_DIR/rebase-merge" directory if it fails to launch the editor, so you'll need to do "git rebase --abort" before repeating the rebase command.

Change "git rebase -i" to terminate using "die_abort" (instead of with "die") if the initial launch of the editor fails.

---
 git-rebase--interactive.sh |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
git-rebase--interactive.sh +1 -1
index 0bd3bf7..d529328 100755
@@ -779,7 +779,7 @@ EOF
 
 		cp "$TODO" "$TODO".backup
 		git_editor "$TODO" ||
-			die "Could not execute editor"
+			die_abort "Could not execute editor"
 
 		has_action "$TODO" ||
 			die_abort "Nothing to do"
Signature · 1 line
1.6.6.rc3.dirty
#1 lore raw
Quoted 11 lines · Björn Gustavsson

If the user's configured editor is emacsclient, the editor will fail to launch if emacs is not running and the git command that tried to lanuch the editor will abort. For most commands, all you have to do is to start emacs and repeat the command.

The "git rebase -i" command, however, aborts without cleaning the "$GIT_DIR/rebase-merge" directory if it fails to launch the editor, so you'll need to do "git rebase --abort" before repeating the rebase command.

Quoted 4 lines

Change "git rebase -i" to terminate using "die_abort" (instead of with "die") if the initial launch of the editor fails.

Two questions:

- Is emacsclient the _only_ editor that can exit with non-zero status to signal an error condition "the user invoked me to edit an existing file, but I ended up not letting the user edit it"?

- Are there editors that let you exit with non-zero status on demand?

The above is not a complaint to your log message, but is a genuine request for information.

An editor that can exit with non-zero status on demand could use this codepath to abort the rebase, when a user realizes that the edit s/he has done so far was completely bogus [*1*]. In such a case, the existing error message "Could not execute editor" may sound funny.

Regardless of that small issue, I think the patch to clean-up makes sense.

Thanks.

[Footnote]

*1* We interpret a completely empty $TODO as a signal from the user to abort the sequencer (the literal interpretation of such a $TODO would be to not pick any commits, which could be a source of potential confusion), so it is not an issue in practice if your editor does not allow you to exit with non-zero status to signal an exception. You can remove all lines and exit the editor normally instead.

#2 lore raw

2009/12/19 Junio C Hamano <[email protected]>:

Quoted 5 lines

Two questions:

 - Is emacsclient the _only_ editor that can exit with non-zero status to signal an error condition "the user invoked me to edit an existing file, but I ended up not letting the user edit it"?

I have no idea, but my guess is that it would only happen in exceptional circumstances (e.g. a file system that has run out of space).

Quoted 9 lines

 - Are there editors that let you exit with non-zero status on demand?

The above is not a complaint to your log message, but is a genuine request for information.

An editor that can exit with non-zero status on demand could use this codepath to abort the rebase, when a user realizes that the edit s/he has done so far was completely bogus [*1*].  In such a case, the existing error message "Could not execute editor" may sound funny.

Again, no idea, but I have never heard of such a feature. I think that anyone advanced enough to use such a feature in an editor would not be troubled by "Could not execute editor".

I mentioned emacsclient because it is a real annoyance that has bitten me more than once (usually because I have closed my local emacs while working on a remote computer because I prefer to only keep windows that I am actively working with), but my patch will help if the user has configured a non-existent editor too (but such a problem usually only happens once).

Signature · 1 line
Björn Gustavsson, Erlang/OTP, Ericsson AB
#3 lore raw
In reply to Junio C Hamano

Hi,

Quoted 16 lines · Junio C Hamano
Quoted 14 lines · Björn Gustavsson

If the user's configured editor is emacsclient, the editor will fail to launch if emacs is not running and the git command that tried to lanuch the editor will abort. For most commands, all you have to do is to start emacs and repeat the command.

The "git rebase -i" command, however, aborts without cleaning the "$GIT_DIR/rebase-merge" directory if it fails to launch the editor, so you'll need to do "git rebase --abort" before repeating the rebase command.

Change "git rebase -i" to terminate using "die_abort" (instead of with "die") if the initial launch of the editor fails.

Quoted 7 lines
Quoted 1 line

Two questions:

- Is emacsclient the _only_ editor that can exit with non-zero status to signal an error condition "the user invoked me to edit an existing file, but I ended up not letting the user edit it"?

The non-existent editor also aborts with a non-zero status.

Quoted 2 lines

An editor that can exit with non-zero status on demand could use this codepath to abort the rebase,

Removing all lines of the edit script will abort an interactive rebase.

Ciao,
Dscho

#4 lore raw
Quoted 1 line · Johannes Schindelin

The non-existent editor also aborts with a non-zero status.

Thanks; that is a good point. Perhaps we might want to say what editor we tried to run in the error message.

Quoted 4 lines
Quoted 2 lines

An editor that can exit with non-zero status on demand could use this codepath to abort the rebase,

Removing all lines of the edit script will abort an interactive rebase.

I guess you replied too fast without reading the message to the end ;-)