From 635a414ed8657dfccd587b10f162eb9136220eee Mon Sep 17 00:00:00 2001
From: Andrew Mogan <amogan@fnal.gov>
Date: Tue, 30 Apr 2024 17:38:08 +0200
Subject: [PATCH 1/4] Check if tags starting with 'v' exist before cloning

---
 scripts/spack/make-release-repo.py | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/scripts/spack/make-release-repo.py b/scripts/spack/make-release-repo.py
index d33206923..405494682 100755
--- a/scripts/spack/make-release-repo.py
+++ b/scripts/spack/make-release-repo.py
@@ -44,6 +44,13 @@ def get_commit_hash(repo, tag_or_branch, fall_back_tag="develop"):
             fi"""
         output = check_output(cmd)
         tag_or_branch = output[0].decode('utf-8').strip()
+    else: # Check if tag exists
+        cmd = f"""cd {tmp_dir}/{repo}; \
+            if ! git show-ref --tags --verify --quiet "refs/tags/{tag_or_branch}"; then \
+              echo "{tag_or_branch} does not exist for package {repo}. Exiting..."; \
+              exit 1; \
+            fi;""" 
+        output = check_output(cmd)
     cmd = f"""cd {tmp_dir}/{repo}; \
         git checkout --quiet {tag_or_branch}; \
         git rev-parse --short HEAD"""

From e716700fc31a0d435508eced1dca5cca986ca128 Mon Sep 17 00:00:00 2001
From: Andrew Mogan <amogan@fnal.gov>
Date: Tue, 30 Apr 2024 17:38:48 +0200
Subject: [PATCH 2/4] Check if tags exist before cloning

---
 scripts/checkout-daq-package.py | 1 +
 1 file changed, 1 insertion(+)

diff --git a/scripts/checkout-daq-package.py b/scripts/checkout-daq-package.py
index 27742a728..e7fbfdce4 100755
--- a/scripts/checkout-daq-package.py
+++ b/scripts/checkout-daq-package.py
@@ -41,6 +41,7 @@ def checkout_tag(repo, commit, outdir):
     cmd = f"""\nmkdir -p {outdir}; cd {outdir}; \
 git clone https://github.com/DUNE-DAQ/{repo}.git; \
 cd {repo}; \
+if ! git show-ref --tags --verify --quiet "refs/tags/{commit}"; then exit 1; fi
 git checkout {commit}; \
 cmake_version=`grep "^project" CMakeLists.txt |grep ")$"|grep -oP "(([[:digit:]]+\.)([[:digit:]]+\.)([[:digit:]]+))"`; \
 tag=v"$cmake_version"; \

From c88c398f8529cab113632eed3ddb16b0fb407aa7 Mon Sep 17 00:00:00 2001
From: Andrew Mogan <amogan@fnal.gov>
Date: Tue, 30 Apr 2024 17:44:33 +0200
Subject: [PATCH 3/4] Add failure output message if tag doesn't exist

---
 scripts/checkout-daq-package.py | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/scripts/checkout-daq-package.py b/scripts/checkout-daq-package.py
index e7fbfdce4..1bd8f0a51 100755
--- a/scripts/checkout-daq-package.py
+++ b/scripts/checkout-daq-package.py
@@ -41,7 +41,10 @@ def checkout_tag(repo, commit, outdir):
     cmd = f"""\nmkdir -p {outdir}; cd {outdir}; \
 git clone https://github.com/DUNE-DAQ/{repo}.git; \
 cd {repo}; \
-if ! git show-ref --tags --verify --quiet "refs/tags/{commit}"; then exit 1; fi
+if ! git show-ref --tags --verify --quiet "refs/tags/{commit}"; then \
+  echo "{tag_or_branch} does not exist for package {repo}. Exiting..."; \
+  exit 1; \
+fi; \
 git checkout {commit}; \
 cmake_version=`grep "^project" CMakeLists.txt |grep ")$"|grep -oP "(([[:digit:]]+\.)([[:digit:]]+\.)([[:digit:]]+))"`; \
 tag=v"$cmake_version"; \

From 3fd1a766f1219a4983991b6906d160cc93c0df65 Mon Sep 17 00:00:00 2001
From: Andrew Mogan <amogan@fnal.gov>
Date: Tue, 30 Apr 2024 17:45:59 +0200
Subject: [PATCH 4/4] Fix typo caused by bad copy-paste

---
 scripts/checkout-daq-package.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/scripts/checkout-daq-package.py b/scripts/checkout-daq-package.py
index 1bd8f0a51..99c43b2b1 100755
--- a/scripts/checkout-daq-package.py
+++ b/scripts/checkout-daq-package.py
@@ -42,7 +42,7 @@ def checkout_tag(repo, commit, outdir):
 git clone https://github.com/DUNE-DAQ/{repo}.git; \
 cd {repo}; \
 if ! git show-ref --tags --verify --quiet "refs/tags/{commit}"; then \
-  echo "{tag_or_branch} does not exist for package {repo}. Exiting..."; \
+  echo "{commit} does not exist for package {repo}. Exiting..."; \
   exit 1; \
 fi; \
 git checkout {commit}; \