From: Jeff King Date: Wed, 03 Feb 2010 09:31:51 GMT Subject: Re: [BUG] - "git commit --amend" commits, when exiting the editor with no changes written Message-ID: <20100203093150.GA23956@coredump.intra.peff.net> In-Reply-To: <20100203061535.GA6566@cthulhu> On Wed, Feb 03, 2010 at 01:15:35AM -0500, Larry D'Anna wrote: > * Avery Pennarun (apenwarr@gmail.com) [100202 18:41]: > > You can however add *new* stuff. That's why I suggested adding an > > option. You could even make it a config option so you only have to > > set it once (just like setting your preferred editor). > > Or, he can set his $EDITOR to a script that checks the mtime. Agreed. It could even look like this: -- >8 -- $ cat >vi-must-edit <<'EOF' #!/usr/bin/perl sub mtime { (stat $_[0])[9] } my $old = mtime($ARGV[-1]); system('vi', @ARGV) and die "vi failed"; if (mtime($ARGV[-1]) == $old) { print STDERR "Aborting unmodified message\n"; exit 1; } exit 0 EOF $ chmod +x vi-must-edit $ GIT_EDITOR=$PWD/vi-must-edit; export GIT_EDITOR $ git commit --amend ;# and then quit the editor immediately Aborting unmodified message error: There was a problem with the editor 'vi-must-edit'. Please supply the message using either -m or -F option. -- 8< -- Do note, though, that there is a subtle race condition in using the mtime. If you make a change and save within a second of the editor starting, it will be ignored. To be thorough, you would probably want to check the size and inode, as well. -Peff