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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

patch: standard exit code #779

Merged
merged 1 commit into from
Nov 3, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 15 additions & 9 deletions bin/patch
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,11 @@ use strict;

use File::Temp qw();

my $VERSION = '0.28';
use constant EX_SUCCESS => 0;
use constant EX_REJECTS => 1;
use constant EX_FAILURE => 2;

my $VERSION = '0.29';

$|++;

Expand All @@ -33,7 +37,7 @@ sub version {
You may play with this software in accordance with the
Perl Artistic License.
];
exit;
exit EX_SUCCESS;
}

my ($patchfile, @options);
Expand Down Expand Up @@ -252,17 +256,17 @@ while (<PATCH>) {
close PATCH;

if (ref $patch eq 'Patch') {
$patch->note("Hmm... I can't seem to find a patch in there anywhere.\n");
die "Hmm... I can't seem to find a patch in there anywhere.\n";
} else {
$patch->end;
}

$patch->note("done\n");
exit($patch->error ? 1 : 0);
exit($patch->error ? EX_REJECTS : EX_SUCCESS);

END {
close STDOUT || die "$0: can't close stdout: $!\n";
$? = 1 if $? == 255; # from die
$? = EX_FAILURE if $? == 255; # from die
}


Expand Down Expand Up @@ -1512,10 +1516,12 @@ text in the patch file and that I<patch> is attempting to
intuit whether there is a patch in that text and, if so,
what kind of patch it is.

I<Patch> will exit with a non-zero status if any reject files
were created. When applying a set of patches in a loop it
behooves you to check this exit status so you don't apply
a later patch to a partially patched file.
=head1 EXIT STATUS

The patch utility exits with status of 0 if the input diff
briandfoy marked this conversation as resolved.
Show resolved Hide resolved
was applied successfully. If part of the input was rejected
an exit status of 1 is used. Exit status 2 indicates an error
occurred.

=head1 CAVEATS

Expand Down
Loading