From 4a73c45126a02b322477f62d57ead4b4aa646a05 Mon Sep 17 00:00:00 2001
From: Spigot <noreply+git-spigot@papermc.io>
Date: Mon, 21 Jan 2013 21:46:26 -0500
Subject: [PATCH] Update rebuildPatches to ignore git version string.

By: Aikar <aikar@aikar.co>
---
 rebuildPatches.sh | 12 ++++++++++--
 1 file changed, 10 insertions(+), 2 deletions(-)

diff --git a/rebuildPatches.sh b/rebuildPatches.sh
index d9f9399fe5..4f0a843af0 100755
--- a/rebuildPatches.sh
+++ b/rebuildPatches.sh
@@ -5,8 +5,16 @@ echo "Rebuilding patch files from current fork state..."
 function cleanupPatches {
     cd $1
     for patch in *.patch; do
-        lines=$(git diff --staged $patch | grep -E "^(\+|\-)" | grep -Ev "(From [a-z0-9]{32,}|\-\-\- a|\+\+\+ b|.index)" | wc -l)
-        if [ "$lines" == "0" ] ; then
+        gitver=$(tail -n 2 $patch | grep -ve "^$" | tail -n 1)
+        diffs=$(git diff --staged $patch | grep -E "^(\+|\-)" | grep -Ev "(From [a-z0-9]{32,}|\-\-\- a|\+\+\+ b|.index)")
+
+        testver=$(echo "$diffs" | tail -n 2 | grep -ve "^$" | tail -n 1 | grep "$gitver")
+        if [ "x$testver" != "x" ]; then
+            diffs=$(echo "$diffs" | head -n -2)
+        fi
+        
+
+        if [ "x$diffs" == "x" ] ; then
             git reset HEAD $patch >/dev/null
             git checkout -- $patch >/dev/null
         fi