From: Miles Bader <hidden> Date: 2016-06-15 22:48:33
Junio C Hamano [off-list ref] writes:
As a Porcelain, "git commit" has some leeway to enforce sensible policy on
the users, and "forbid commit that does not explain anything" is one such
policy. It is not generally a good idea to expose the full capabilities
of plumbing to Porcelain if it leads to bad user behaviour, and such
"artificial" limitations are safety features we do not want to remove.
Isn't the requirement of using a longish option like
"--allow-empty-message" enough of a warning to users though?
Although it seems reasonable for git _discourage_ bad practices, I think
that should generally also be moderated with "... but if you _reallllly_
want to, you can do this somewhat annoying thing....". Forcing someone
to use commit-tree, though, seems a bit much to me; an annoyingly long
option seems about right.
-Miles
--
Love is the difficult realization that something other than oneself is real.
[Iris Murdoch]
From: Jeff King <hidden> Date: 2016-06-15 22:48:33
On Mon, Apr 05, 2010 at 02:10:58PM +0900, Miles Bader wrote:
Junio C Hamano [off-list ref] writes:
quoted
As a Porcelain, "git commit" has some leeway to enforce sensible policy on
the users, and "forbid commit that does not explain anything" is one such
policy. It is not generally a good idea to expose the full capabilities
of plumbing to Porcelain if it leads to bad user behaviour, and such
"artificial" limitations are safety features we do not want to remove.
Isn't the requirement of using a longish option like
"--allow-empty-message" enough of a warning to users though?
Although it seems reasonable for git _discourage_ bad practices, I think
that should generally also be moderated with "... but if you _reallllly_
want to, you can do this somewhat annoying thing....". Forcing someone
to use commit-tree, though, seems a bit much to me; an annoyingly long
option seems about right.
Yes and no. There are other reasons not to use "git commit" in your
import script. You probably want to pass --allow-empty, too, and
--no-verify. And you probably want to use --cleanup=none to keep
messages intact.
But most of all, even if you do everything right, we still don't promise
not to change it out from under you in a future version. Because it's
porcelain, and the plumbing method is to use commit-tree. If
commit-tree is too hard to use, I would rather see the plumbing made
more friendly than encouraging people to build on top of porcelain.
All of that being said, I looked at the snerp-vortex source code (which
started this thread):
http://github.com/rcaputo/snerp-vortex/blob/master/lib/SVN/Dump/Replayer/Git.pm
It uses several pieces of porcelain. Some in silly ways, like calling
"git status" to avoid calling git-commit when there are no changes and
getting an error code. Which is silly (if you are importing, you
probably want --allow-empty), wasteful (you just need the diff-index
part of status), and now broken (because status is no longer "commit
--dry-run", it always exits with status 0 whether there are changes or
not). Then there are things like calling "git add -f" with arguments,
and a "TODO: split arguments to handle larger filesets" comment. When he
should be using update-index, which takes updates on stdin.
He also notes in the README that it takes 250 seconds to convert his
test repo to git, but only 70 to make a flat filesystem, and that he
wants to move to using fast-import.
So yes, it sucks that his importer does not support empty comments, and
that the OP had to hack around it. But it already doesn't support many
things (like commits with a large number of files, and from what I can
see, files with spaces will break his `find` invocation). The right
answer is for him to move to fast-import, which will be way faster, more
robust, and is actually a supported plumbing interface.
I don't think it's worth adding new features to support a scripting
interface that we are trying to discourage. And I haven't seen another
argument in favor of empty commits besides importing. Are people
really wanting to make empty commit messages while using git itself?
-Peff
On Mon, Apr 5, 2010 at 05:51, Jeff King [off-list ref] wrote:
So yes, it sucks that his importer does not support empty comments, and
that the OP had to hack around it. But it already doesn't support many
things (like commits with a large number of files, and from what I can
see, files with spaces will break his `find` invocation). The right
answer is for him to move to fast-import, which will be way faster, more
robust, and is actually a supported plumbing interface.
Thanks for looking at the importer, that'll be very useful when fixing
it. But FWIW that `find` invocation isn't a bug. Perl doesn't have a "
" input field separator so "my @files = `find . -type f`" does the
right thing, unlike in the shell.
I don't think it's worth adding new features to support a scripting
interface that we are trying to discourage. And I haven't seen another
argument in favor of empty commits besides importing. Are people
really wanting to make empty commit messages while using git itself?
I'm sorry that I brought snerp-vortex into this at all. It wasn't the
main motivation behind this patch, just the straw that broke the
camel's back.
I've run into this limitation a lot when playing with and learning
Git. Sometimes I'm e.g. making small throwaway repositories in /tmp
using the porcelain for experimentation. Those have seen a lot of
"blah!" commit messages immediately following "Git exited abnormally
with code 1".
Miles Bader said it better than I could. Tools should provide sane
defaults and discourage bad practices, but they shouldn't *enforce*
good practices. That'll inevitably burn people whose use for the tools
isn't what you expect.
Even if they Git maintainers don't like this people *do* write
automated scripts and wrappers around Git using the porcelain, simply
because that's what they're used to. Learning to use and switching to
something like git-fast-import(1) or git-commit-tree(1) is too big of
a hurdle for small throwaway scripts that take ~1m to write and aren't
big dedicated importers like snerp-vortex.
There's probably a lot of code out there doing `git commit -m"Yet
another revision"' from some cron job. I sprinkled a lot of such
meaningless messages about when I switched from Subversion (which
supports empty commits in the porcelain) for these automated jobs to
Git.
Of course Junio may disagree (and that's fine!), how much you babysit
your users is ultimately a design decision up to the maintainer. I
just find this inconsistent with the rest of the porcelain which
usually gives me plenty of ammo to blow both my legs of (and the
planet they were standing on) if I so choose :)
From: Jonathan Nieder <hidden> Date: 2016-06-15 22:48:33
Hi,
Ævar Arnfjörð Bjarmason wrote:
Learning to use and switching to
something like git-fast-import(1) or git-commit-tree(1) is too big of
a hurdle for small throwaway scripts that take ~1m to write and aren't
big dedicated importers like snerp-vortex.
There's probably a lot of code out there doing `git commit -m"Yet
another revision"' from some cron job.
FWIW, I have no strong opinion about whether to add this --allow-empty-message
option. Maybe it would make something more convenient for someone,
though that has to be weighed against it making it harder for everyone
else to read the manual.
Instead, I just wanted to suggest that it is really worth the time to
learn to use ‘git commit-tree’. Mostly because it does not take much
time to learn at all.
Hint:
parent=HEAD && : or whatever &&
tree=$(git write-tree) &&
printf "%s\n" message |
commit=$(git commit-tree "$tree" -p "$parent") &&
git update-ref refs/heads/somebranch "$commit"
It is a very flexible tool, and I think you will find yourself fighting
with git much less if you use tools like it in situations that would
be unusual for a human to run into.
Cheers,
Jonathan
I rearranged this example the last minute and broke it. You might
say this proves the opposite of my point, though I don’t think that
would be warranted. Anyway, to feed the message into ‘git
commit-tree’ standard input, the relevant part of the example should
have read as follows:
commit=$(
printf "%s\n" message |
git commit-tree "$tree" -p "$parent"
)
Incidentally, outside of the user manual and contrib/examples/ in the
sources, the git documentation does not have many examples like this
to point to, which is too bad.
Sorry for the confusion,
Jonathan
From: Jeff King <hidden> Date: 2016-06-15 22:48:33
On Mon, Apr 05, 2010 at 12:50:11PM +0000, Ævar Arnfjörð Bjarmason wrote:
Thanks for looking at the importer, that'll be very useful when fixing
it. But FWIW that `find` invocation isn't a bug. Perl doesn't have a "
" input field separator so "my @files = `find . -type f`" does the
right thing, unlike in the shell.
He calls `find $dir -type f`, without a quotemeta on $dir, which perl
will pass to the shell to interpret (and is actually a security issue if
I can convince you to try importing my svn repository with directory ';
rm -rf /;').
I'm sorry that I brought snerp-vortex into this at all. It wasn't the
main motivation behind this patch, just the straw that broke the
camel's back.
I don't in particular have a problem with --allow-empty-message for
casual use. Why anybody would want to use it when they could type the
much shorter -mnone, I don't know. But it is long enough that people
will have to think about using it, which means the people who do so will
probably really want it.
-Peff
From: Jeff King <hidden> Date: 2016-06-15 22:48:33
On Mon, Apr 05, 2010 at 12:58:22PM -0500, Jonathan Nieder wrote:
quoted
There's probably a lot of code out there doing `git commit -m"Yet
another revision"' from some cron job.
FWIW, I have no strong opinion about whether to add this --allow-empty-message
option. Maybe it would make something more convenient for someone,
though that has to be weighed against it making it harder for everyone
else to read the manual.
I meant to mention this in my other response: I would prefer if such an
option doesn't clutter up the usage message. --allow-empty is already
there, and probably doesn't need to be. "git commit -h 2>&1 | wc -l"
shows a whopping 39 lines, which IMHO is too many for a short usage
summary. I mean, "--no-post-rewrite", is that really one of the top-used
options?
In addition to the bug you mention later, you also probably want to do:
parent=`git rev-parse --verify HEAD`
[...]
git update-ref \
-m 'automated commit by tool X' \
refs/heads/somebranch $commit $parent
which will give your reflog entry a more useful message, and will
protect against simultaneous updates losing history (update-ref will
make sure, while locked, that somebranch contains the $parent sha1 you
wrote as part of the commit object).
And of course it still doesn't handle parentless root commits.
So doing it right really is a bit more work than just calling "git
commit".
-Peff
@@ -131,6 +131,12 @@ OPTIONS from making such a commit. This option bypasses the safety, and is primarily for use by foreign scm interface scripts.+--allow-empty-message::+ Like --allow-empty this command is primarily for use by foreign+ scm interface scripts. It allows you to create a commit with an+ empty commit message without using plumbing commands like+ linkgit:git-commit-tree[1].+ --cleanup=<mode>:: This option sets how the commit message is cleaned up. The '<mode>' can be one of 'verbatim', 'whitespace', 'strip',
@@ -141,6 +141,7 @@ static struct option builtin_commit_options[] = {OPT_BOOLEAN(0,"no-post-rewrite",&no_post_rewrite,"bypass post-rewrite hook"),{OPTION_STRING,'u',"untracked-files",&untracked_files_arg,"mode","show untracked files, optional modes: all, normal, no. (Default: all)",PARSE_OPT_OPTARG,NULL,(intptr_t)"all"},OPT_BOOLEAN(0,"allow-empty",&allow_empty,"ok to record an empty change"),+OPT_BOOLEAN(0,"allow-empty-message",&allow_empty_message,"ok to record a change with an empty message"),/* end commit contents options */OPT_END()
@@ -1293,7 +1294,7 @@ int cmd_commit(int argc, const char **argv, const char *prefix)if(cleanup_mode!=CLEANUP_NONE)stripspace(&sb,cleanup_mode==CLEANUP_ALL);-if(message_is_empty(&sb)){+if(message_is_empty(&sb)&&!allow_empty_message){rollback_index_files();fprintf(stderr,"Aborting commit due to empty commit message.\n");exit(1);
@@ -0,0 +1,41 @@+#!/bin/sh+#+# Copyright (c) 2010 Ævar Arnfjörð Bjarmason+#++test_description='git commit --allow-empty-message'++../test-lib.sh++commit_msg_is(){+test"`git log --pretty=format:%s%b -1`"="$1"+}++# A sanity check to see if commit is working at all.+test_expect_success'a basic commit in an empty tree should succeed''+(+echocontent>foo&&+gitaddfoo&&+gitcommit-m"initial commit"+)&&+commit_msg_is"initial commit"+'++test_expect_success'Commit no message with --allow-empty-message''+(+echo"more content">>foo&&+gitaddfoo&&+printf""|gitcommit--allow-empty-message+)&&+commit_msg_is""+'++test_expect_success'Commit a message with --allow-empty-message''+(+echo"even more content">>foo&&+gitaddfoo&&+gitcommit--allow-empty-message-m"hello there"+)&&+commit_msg_is"hello there"+'+test_done
On Tue, Apr 6, 2010 at 05:55, Jeff King [off-list ref] wrote:
On Mon, Apr 05, 2010 at 12:58:22PM -0500, Jonathan Nieder wrote:
quoted
quoted
There's probably a lot of code out there doing `git commit -m"Yet
another revision"' from some cron job.
FWIW, I have no strong opinion about whether to add this --allow-empty-message
option. Maybe it would make something more convenient for someone,
though that has to be weighed against it making it harder for everyone
else to read the manual.
I meant to mention this in my other response: I would prefer if such an
option doesn't clutter up the usage message. --allow-empty is already
there, and probably doesn't need to be. "git commit -h 2>&1 | wc -l"
shows a whopping 39 lines, which IMHO is too many for a short usage
summary. I mean, "--no-post-rewrite", is that really one of the top-used
options?
I just put it there because --allow-empty was there and I thought the
SYNOPSIS might be going for a complete listing. I completely agree
though, the option shouldn't be in the SYNOPSIS, and neither should
--allow-empty be. They're both analogous to obscure options like
--porcelain (which isn't listed).
I've just submitted a new patch to rectify this. I can send another
one to remove --allow-empty from the SYNOPSIS.
The --allow-empty option is too rarley used to warrant being displayed
in the SYNOPSIS. It should only be mentioned in the main body of the
documentation like --porcelain.
The issue was raised in the thread discussing the new
--allow-empty-message option (see 1aadbfad) by Jeff King
[off-list ref]:
http://marc.info/?l=git&m=127054334121604
Signed-off-by: Ævar Arnfjörð Bjarmason <redacted>
---
Documentation/git-commit.txt | 5 ++---
1 files changed, 2 insertions(+), 3 deletions(-)
Heya,
On Wed, Apr 7, 2010 at 10:09, Ævar Arnfjörð Bjarmason [off-list ref] wrote:
--allow-empty-message option (see 1aadbfad) by Jeff King
The hash of that commit is likely to change before it is included, so
I'm not sure if it's wise to include it here right now, unless Junio
is willing to make sure this reference stays correct?
--
Cheers,
Sverre Rabbelier
The --allow-empty option is too rarley used to warrant being displayed
in the SYNOPSIS. It should only be mentioned in the main body of the
documentation like --porcelain.
The issue was raised in the thread discussing the new
--allow-empty-message option by Jeff King [off-list ref]:
http://marc.info/?l=git&m=127039258902941http://marc.info/?l=git&m=127054334121604
Signed-off-by: Ævar Arnfjörð Bjarmason <redacted>
---
I'd forgotten how the Git project likes rebasing :)
Here's a better patch that just cites the two relevant mailing list
posts instead of the commit sha1.
Documentation/git-commit.txt | 5 ++---
1 files changed, 2 insertions(+), 3 deletions(-)
Heya,
On Wed, Apr 7, 2010 at 12:28, Ævar Arnfjörð Bjarmason [off-list ref] wrote:
I'd forgotten how the Git project likes rebasing :)
It's not so much the rebasing, but your patch gets applied manually
from the mbox (meaning a different timestamp) by Junio (meaning a
different committer), who adds his S-o-b (meaning a different commit
message), so yeah, the hash is gonna change ;).
--
Cheers,
Sverre Rabbelier
On Wed, Apr 7, 2010 at 17:52, Sverre Rabbelier [off-list ref] wrote:
Heya,
On Wed, Apr 7, 2010 at 12:28, Ævar Arnfjörð Bjarmason [off-list ref] wrote:
quoted
I'd forgotten how the Git project likes rebasing :)
It's not so much the rebasing, but your patch gets applied manually
from the mbox (meaning a different timestamp) by Junio (meaning a
different committer), who adds his S-o-b (meaning a different commit
message), so yeah, the hash is gonna change ;).
Of course, but in this case the patch had already been pushed by Junio
to the Git repository as 1aadbf, my original commit was 1eb6f8. The
SHA1 wouldn't change when it was cherry-picked to master unless it was
further rewritten.
But in any case referencing the mailing list post instead of the SHA1 is better.
The --allow-empty option is too rarely used to warrant being displayed
in the SYNOPSIS. It should only be mentioned in the main body of the
documentation like --porcelain.
The issue was raised in the thread discussing the new
--allow-empty-message option by Jeff King [off-list ref]:
http://marc.info/?l=git&m=127039258902941http://marc.info/?l=git&m=127054334121604
Signed-off-by: Ævar Arnfjörð Bjarmason <redacted>
---
Thanks for catching that. Here's the commit without the tyop :)
Documentation/git-commit.txt | 5 ++---
1 files changed, 2 insertions(+), 3 deletions(-)
IMO the option should not be removed from the synopsis section of the
documentation. I would agree that it is removed from the output of 'git
commit -h', and I think this was the original intent when someone (Junio?)
suggested to remove it.
-- Hannes