git/list[1] front-page[2] threads[3] people[4] search[5] about
 

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.

Previous: Alex RiesenNext: Alex Riesen
Message 26 of 32 in “Allow git-diff exit with codes similar to diff(1)”
  1. Allow git-diff exit with codes similar to diff(1)Alex Riesen, Mar 14, 2007
  2. Johannes SchindelinMar 14, 2007
  3. Linus TorvaldsMar 14, 2007
  4. Junio C HamanoMar 14, 2007
  5. Linus TorvaldsMar 14, 2007
  6. Johannes SchindelinMar 14, 2007
  7. Linus TorvaldsMar 14, 2007
  8. Johannes SchindelinMar 14, 2007
  9. Alex RiesenMar 14, 2007
  10. Johannes SchindelinMar 14, 2007
  11. Alex RiesenMar 14, 2007
  12. Johannes SchindelinMar 14, 2007
  13. Simon 'corecode' SchubertMar 15, 2007
  14. Alex RiesenMar 15, 2007
  15. Junio C HamanoMar 14, 2007
  16. Alex RiesenMar 14, 2007
  17. Junio C HamanoMar 14, 2007
  18. Junio C HamanoMar 14, 2007
  19. Alex RiesenMar 14, 2007
  20. Junio C HamanoMar 14, 2007
  21. Alex RiesenMar 14, 2007
  22. Junio C HamanoMar 14, 2007
  23. Alex RiesenMar 14, 2007
  24. Junio C HamanoMar 14, 2007
  25. Allow git-diff exit with codes similar to diff(1)Alex Riesen, Mar 14, 2007
  26. Junio C HamanoMar 14, 2007
  27. Alex RiesenMar 14, 2007
  28. Junio C HamanoMar 14, 2007
  29. Allow git-diff exit with codes similar to diff(1)Alex Riesen, Mar 14, 2007
  30. Junio C HamanoMar 14, 2007
  31. Junio C HamanoMar 14, 2007
  32. Alex RiesenMar 14, 2007

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.