Re: [PATCH] Allow git-diff exit with codes similar to diff(1)
- From
Junio C Hamano <junkio@cox.net>
- Date
- Mar 14, 2007, 16:14 UTC
- Message-ID
- <7v1wjrby4w.fsf@assigned-by-dhcp.cox.net>
- In-Reply-To
- <81b0412b0703140701h60982fddw3ed8fa71288cb220@mail.gmail.com>
"Alex Riesen" <raa.lkml@gmail.com> writes:
Show 7 quoted lines
>> To implement --quick correctly, you need to know when it is safe >> to leave early. Presence of -S (pickaxe) would most likely mean >> you shouldn't leave early. > > Thanks, that got me thinking. Moved all exit code evaluation > into diffcore_std, added a field for the code to diff_options, > and use it if called with --exit-code.
Certainly --quick would be "interesting" and useful to add on top of your patch.
Show 20 quoted lines
> diff --git a/builtin-diff-files.c b/builtin-diff-files.c
> index aec8338..2525ae6 100644
> --- a/builtin-diff-files.c
> +++ b/builtin-diff-files.c
> @@ -17,6 +17,7 @@ int cmd_diff_files(int argc, const char **argv, const char *prefix)
> {
> struct rev_info rev;
> int nongit = 0;
> + int result;
>
> prefix = setup_git_directory_gently(&nongit);
> init_revisions(&rev, prefix);
> @@ -29,5 +30,6 @@ int cmd_diff_files(int argc, const char **argv, const char *prefix)
> argc = setup_revisions(argc, argv, &rev, NULL);
> if (!rev.diffopt.output_format)
> rev.diffopt.output_format = DIFF_FORMAT_RAW;
> - return run_diff_files_cmd(&rev, argc, argv);
> + result = run_diff_files_cmd(&rev, argc, argv);
> + return rev.diffopt.diff_exit_code ? rev.diffopt.exit_code: result;
> }Yuck. Let's call the former "exit_with_status" (meaning, the caller instructed us to do that) and the latter "has_changes".
Show 6 quoted lines
> +test_expect_failure 'git diff-index --cached HEAD^' ' > + echo text >>b && > + echo 3 >c && > + git add . && > + git diff-index --exit-code --cached HEAD^ > +'
Please:
test_expect_success '...
echo ... &&
git add . &&
! git diff-index ...
'I recall somebody on the list had a buggy shell that cannot handle "a && ! b" and tweaked a few tests to work around it. In that case...
echo ... &&
git add . &&
{
git diff-index ...; test $? != 0
}> +test_expect_failure 'git diff-files' ' > + echo 3 >>c && > + git diff-files --exit-code > +'
Likewise
> +git update-index c || error "update-index failed"
Please do not have command outside test_expect without good reason.