Open calestyo opened 6 months ago
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
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
’s 2
.
Sorry for the noise.
btw: Is there a way in delta
to disable colour output?
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.
No worries.
I reproduced it... wait a second...
$ 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
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!
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).
Also when doing using a directory as existent file:
$ delta /tmp non-existent
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
).
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
.
Well unless for the other cases mentioned above, where one does have delta a b
style and it still doesn't act like diff
. :-)
Hey.
It seems right now, that
delta
has an exit status of0
in case no differences were found, and one of1
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:
Thanks, Chris.