Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

馃殌 use diff-compatible exit statuses that differ between difference-found and error #1584

Open
calestyo opened this issue Dec 19, 2023 · 11 comments

Comments

@calestyo
Copy link

calestyo commented Dec 19, 2023

Hey.

It seems right now, that delta has an exit status of 0 in case no differences were found, and one of 1 either when differences were found or an error (e.g. file not found) occurred.

It would be nice if one could differ between the latter two, ideally following POSIX' exit statuses for diff, that is:

0 No differences were found.
1 Differences were found.
>1 An error occurred.

Thanks,
Chris.

@dandavison
Copy link
Owner

Hi @calestyo, I thought that it worked like that already! Can you post an example? This is MacOS in zsh.

~ delta <(echo a) <(echo a) > /dev/null; echo $?
0
~ delta <(echo a) <(echo b) > /dev/null; echo $?
1
~ delta <(echo a) __not_there__ > /dev/null; echo $?
diff: __not_there__: No such file or directory
2

@calestyo
Copy link
Author

Indeed. Not sure how I produced the contradicting result.... I've been calling delta from a shell script, and I think there might have been an exit 1 at a wrong point, which has overridden delta鈥檚 2.

Sorry for the noise.

btw: Is there a way in delta to disable colour output?

@dandavison
Copy link
Owner

No worries.

btw: Is there a way in delta to disable colour output?

You mean, keep all the reformatting and decorations but specifically disable colour? I don't think there is a way to do that, although perhaps there are enough colour settings in delta to achieve it piecemeal!

So in a script the answer would be not to call delta if one only wants the raw git/diff input, and of course, git doesn't invoke delta at all if output is not a tty. But if you explicitly pipe to delta in a script then it will add colours and text decorations / reformatting.

@calestyo
Copy link
Author

No worries.

I reproduced it... wait a second...

@calestyo
Copy link
Author

$ touch foo
$ stat /tmp/bar
stat: cannot statx '/tmp/bar': No such file or directory
$ delta foo /tmp/bar ; echo $?
error: Could not access '/tmp/bar'
1

If I do however:

$ delta <(echo foo) /tmp/bar ; echo $?
diff: /tmp/bar: No such file or directory
2

@dandavison dandavison reopened this Dec 19, 2023
@dandavison
Copy link
Owner

Ah-ha, I'm not at my computer but I do remember that the code handling process substitutions had to do something unfortunate. Feel free to investigate!

@calestyo
Copy link
Author

There are more cases:

$ delta /dev/null non-existent
$ delta /dev/random non-existent
$ delta /dev/uinput non-existent

all give 1, and only uinput is permission-wise not accessible by the user.

Also:

$ ln -s /nonexistent dangling.symlink
$ delta dangling.symlink non-existent

Though it works when comparing with an existent file (not sure, btw. whether it should even then, cause then there's still one inaccessible file - the target of the dangling symlink).

@calestyo
Copy link
Author

Also when doing using a directory as existent file:

$ delta /tmp non-existent

@calestyo
Copy link
Author

That issue may even go yet a bit further.

Assume I do:

foo="$(diff -u a b)"

(and there is a difference)

and then:

printf '%s\n' "$foo"  |  delta

I get the differences shown, but exit status is 0 (and not 1).

@dandavison
Copy link
Owner

That's right, in something | delta delta behaves like cat or bat -- it's just a pager displaying stuff and exit code is 0 unless something goes wrong. On the other hand in delta a b delta acts as a diff program, and exit codes are as diff.

@calestyo
Copy link
Author

Well unless for the other cases mentioned above, where one does have delta a b style and it still doesn't act like diff. :-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants