[X2Go-Commits] [maintenancescripts] 08/08: git/hooks/x2go-post-receive-close-bugs: rework previous tag detection.

git-admin at x2go.org git-admin at x2go.org
Thu Mar 5 19:23:41 CET 2020


This is an automated email from the git hooks/post-receive script.

x2go pushed a commit to branch master
in repository maintenancescripts.

commit 92f1708b3b78d2ddf7edb555c480f1c79773b367
Author: Mihai Moldovan <ionic at ionic.de>
Date:   Thu Mar 5 19:17:54 2020 +0100

    git/hooks/x2go-post-receive-close-bugs: rework previous tag detection.
    
    Add sanity checks.
    
    If we stumble upon a rev that looks invalid (according to git
    rev-parse), chances are that the previous rev doesn't have a parent
    (i.e., is a root commit) and looking further back for another tag
    doesn't make sense if we haven't found one yet.
    
    In that case, stop looking (and, for that matter, don't create an
    endless loop) and just use the empty tree object as the oldrev that will
    be baked into URL as the parent/base.
---
 git/hooks/x2go-post-receive-close-bugs | 31 +++++++++++++++++++++++++------
 1 file changed, 25 insertions(+), 6 deletions(-)

diff --git a/git/hooks/x2go-post-receive-close-bugs b/git/hooks/x2go-post-receive-close-bugs
index 83497f7..625ea8b 100755
--- a/git/hooks/x2go-post-receive-close-bugs
+++ b/git/hooks/x2go-post-receive-close-bugs
@@ -135,13 +135,32 @@ while read oldrev newrev refname; do
       continue
       ;;
   esac
-    # find the last tag on this branch
-    tag="${refname/refs\/tags\//}"
-    oldrev="$(git rev-parse "${tag}")^"
+
+  # Find the previous tag reachable from the current one.
+  emptytree="$(printf '' | git hash-object --stdin -t tree)"
+  oldrev="$(git rev-parse "${refname}" 2>'/dev/null')^"
+  if git rev-parse "${oldrev}" 2>'/dev/null'; then
     # rewind back from current ref back to the previous tag we find
-    while ! git describe "${oldrev}" --exact-match 2>/dev/null; do oldrev="${oldrev}^"; done
-    oldrev="$(git rev-parse "${oldrev}")"
-    oldtag="$(git tag --contains "${oldrev}" | head -n1)"
+    while ! git describe "${oldrev}" --exact-match 2>'/dev/null'; do
+      oldrev="${oldrev}^"
+
+      # Sanity check - does the rev actually exist?
+      if ! git rev-parse "${oldrev}" 2>'/dev/null'; then
+        oldrev="${emptytree}"
+        break
+      fi
+    done
+
+    # If we actually found something, massage it.
+    if [ "${oldrev}" != "${emptytree}" ]; then
+      oldrev="$(git rev-parse "${oldrev}")"
+      oldtag="$(git describe "${oldrev}" --exact-match 2>'/dev/null')"
+    else
+      oldtag=''
+    fi
+  else
+    oldrev="${emptytree}"
+  fi
 
   c="${tempdir}/${newrev}.changelog"
   d="${tempdir}/${newrev}.diff"

--
Alioth's /home/x2go-admin/maintenancescripts/git/hooks/post-receive-email on /srv/git/code.x2go.org/maintenancescripts.git


More information about the x2go-commits mailing list