From: Gerrit Pape Date: Thu, 14 Feb 2008 20:13:55 GMT Subject: [PATCH] hash-object: cleanup handling of command line options Message-ID: <20080214201355.6021.qmail@6a68c4de06516f.315fe32.mid.smarden.org> In-Reply-To: <7v8x1oo2w8.fsf@gitster.siamese.dyndns.org> git hash-object used to process the --stdin command line argument before reading subsequent arguments. This caused 'git hash-object --stdin -w' to fail to actually write the object into the database, while '-w --stdin' properly did. Now git hash-object processes --stdin at the end, after all other arguments. This regresses the use case of running: $ git hash-object --stdin Makefile --- hash-object.c | 7 ++++++- t/t5303-hash-object.sh | 35 +++++++++++++++++++++++++++++++++++ 2 files changed, 41 insertions(+), 1 deletions(-) create mode 100755 t/t5303-hash-object.sh diff --git a/hash-object.c b/hash-object.c index 0a58f3f..67d9922 100644 --- a/hash-object.c +++ b/hash-object.c @@ -41,6 +41,7 @@ int main(int argc, char **argv) const char *prefix = NULL; int prefix_length = -1; int no_more_flags = 0; + int hashstdin = 0; git_config(git_default_config); @@ -65,7 +66,9 @@ int main(int argc, char **argv) else if (!strcmp(argv[i], "--help")) usage(hash_object_usage); else if (!strcmp(argv[i], "--stdin")) { - hash_stdin(type, write_object); + if (hashstdin) + die("Multiple --stdin arguments are not supported"); + hashstdin = 1; } else usage(hash_object_usage); @@ -79,5 +82,7 @@ int main(int argc, char **argv) no_more_flags = 1; } } + if (hashstdin) + hash_stdin(type, write_object); return 0; } diff --git a/t/t5303-hash-object.sh b/t/t5303-hash-object.sh new file mode 100755 index 0000000..14be455 --- /dev/null +++ b/t/t5303-hash-object.sh @@ -0,0 +1,35 @@ +#!/bin/sh + +test_description=git-hash-object + +. ./test-lib.sh + +test_expect_success \ + 'git hash-object -w --stdin saves the object' \ + 'obname=$(echo foo | git hash-object -w --stdin) && + obpath=$(echo $obname | sed -e "s/\(..\)/\1\//") && + test -r .git/objects/"$obpath" && + rm -f .git/objects/"$obpath"' + +test_expect_success \ + 'git hash-object --stdin -w saves the object' \ + 'obname=$(echo foo | git hash-object --stdin -w) && + obpath=$(echo $obname | sed -e "s/\(..\)/\1\//") && + test -r .git/objects/"$obpath" && + rm -f .git/objects/"$obpath"' + +test_expect_success \ + 'git hash-object --stdin file0 file0 && + obname0=$(git hash-object file0) && + obname1=$(echo bar | git hash-object --stdin) && + obname0new=$(echo bar | git hash-object --stdin file0 | sed -n -e 1p) && + obname1new=$(echo bar | git hash-object --stdin file0 | sed -n -e 2p) && + test "$obname0" = "$obname0new" && + test "$obname1" = "$obname1new"' + +test_expect_success \ + 'git hash-object refuses multiple --stdin arguments' \ + '! git hash-object --stdin --stdin < file0' + +test_done -- 1.5.4.1