From 57ceebbc81f97da2e6ca28d8c145918732be5382 Mon Sep 17 00:00:00 2001
From: Tristan Partin <tristan@neon.tech>
Date: Thu, 14 Dec 2023 10:39:32 -0600
Subject: [PATCH v3 3/3] Allow --check and --diff to passed in the same
 pgindent command

This means to print the diff and exit if a diff exists.
---
 src/tools/pgindent/pgindent | 21 +++++++++++----------
 1 file changed, 11 insertions(+), 10 deletions(-)

diff --git a/src/tools/pgindent/pgindent b/src/tools/pgindent/pgindent
index 38a0222573..eb2f52f4b9 100755
--- a/src/tools/pgindent/pgindent
+++ b/src/tools/pgindent/pgindent
@@ -40,9 +40,6 @@ GetOptions(%options) || usage("bad command line argument");
 
 usage() if $help;
 
-usage("Cannot have both --check and --diff")
-  if $check && $diff;
-
 usage("Cannot use --commit with command line file list")
   if (@commits && @ARGV);
 
@@ -417,17 +414,21 @@ foreach my $source_filename (@files)
 
 	if ($source ne $orig_source)
 	{
-		if ($check)
-		{
-			exit 2;
-		}
-		elsif ($diff)
+		if (!$diff && !$check)
 		{
-			print diff($source, $source_filename);
+			write_source($source, $source_filename);
 		}
 		else
 		{
-			write_source($source, $source_filename);
+			if ($diff)
+			{
+				print diff($source, $source_filename);
+			}
+
+			if ($check)
+			{
+				exit 2;
+			}
 		}
 	}
 }
-- 
Tristan Partin
Neon (https://neon.tech)

