From 09b7e93c1c1aa3bbfcfb5ee9a2cfe793d84f8e3b Mon Sep 17 00:00:00 2001 From: Esa Jokinen Date: Wed, 14 Aug 2024 11:14:34 +0300 Subject: [PATCH] follow-cvelist.py exit if git pull fails --- bin/follow-cvelist.py | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/bin/follow-cvelist.py b/bin/follow-cvelist.py index 4228f65..0c08011 100755 --- a/bin/follow-cvelist.py +++ b/bin/follow-cvelist.py @@ -165,20 +165,23 @@ def monitor(self) -> None: cursor = new_cursor def pull(self) -> None: - """Runs git pull""" + """Runs git pull. Exits if it fails.""" + result = subprocess.run( + ["git", "pull"], stdout=subprocess.PIPE, stderr=subprocess.PIPE + ) if self.args.verbose > 1: - result = subprocess.run( - ["git", "pull"], stdout=subprocess.PIPE, stderr=subprocess.STDOUT - ) print( f"{time.strftime('%Y-%m-%d %H:%M:%S', time.gmtime())} " f"{result.stdout.decode('utf-8').strip()}", file=sys.stderr, ) - else: - subprocess.call( - ["git", "pull"], stdout=subprocess.DEVNULL, stderr=subprocess.STDOUT + if result.returncode > 0: + print( + f"\n{result.stderr.decode('utf-8').strip()}\n{ANSI.code('red')}" + f"Manual intervention required; 'git pull' failed!{ANSI.code('end')}", + file=sys.stderr, ) + sys.exit(1) def get_cursor(self, offset: int = 0) -> str: """Gets commit id at the offset from the current head"""