From 1b331343530a0d749d5fbc90917a99ec54a51176 Mon Sep 17 00:00:00 2001
From: Matthias Schiffer <mschiffer@universe-factory.net>
Date: Sat, 28 Dec 2013 21:35:16 +0100
Subject: [PATCH] Make patch and update scripts a bit nicer

---
 Makefile          |  1 +
 scripts/patch.sh  | 11 +++++++++--
 scripts/update.sh |  3 ++-
 3 files changed, 12 insertions(+), 3 deletions(-)

diff --git a/Makefile b/Makefile
index 3e8d26ba..9925550b 100644
--- a/Makefile
+++ b/Makefile
@@ -21,6 +21,7 @@ export TOPDIR
 
 update: FORCE
 	$(GLUONDIR)/scripts/update.sh $(GLUONDIR)
+	$(GLUONDIR)/scripts/patch.sh $(GLUONDIR)
 
 patch: FORCE
 	$(GLUONDIR)/scripts/patch.sh $(GLUONDIR)
diff --git a/scripts/patch.sh b/scripts/patch.sh
index 6302141f..0e431b39 100755
--- a/scripts/patch.sh
+++ b/scripts/patch.sh
@@ -7,8 +7,15 @@ shopt -s nullglob
 
 for module in $GLUON_MODULES; do
 	dir="$1"/$module
-	git -C $dir checkout -B patched base
+	git -C $dir checkout -B patching base
 
 	if [ -z "$1"/patches/$module/*.patch ]; then continue; fi
-	git -C "$dir" am "$1"/patches/$module/*.patch
+	git -C "$dir" am "$1"/patches/$module/*.patch || (
+		git -C "$dir" am --abort
+		git -C "$dir" checkout patched
+		git -C "$dir" branch -D patching
+		false
+	)
+	git -C "$dir" checkout -B patched
+	git -C "$dir" branch -d patching
 done
diff --git a/scripts/update.sh b/scripts/update.sh
index 40d2b50c..2bda671f 100755
--- a/scripts/update.sh
+++ b/scripts/update.sh
@@ -11,6 +11,7 @@ for module in $GLUON_MODULES; do
 	eval repo=\${MODULE_${var}_REPO}
 	eval commit=\${MODULE_${var}_COMMIT}
 	git -C "$dir" init
-	git -C "$dir" fetch $repo
+
+	git -C "$dir" checkout $commit 2>/dev/null || git -C "$dir" fetch $repo
 	git -C "$dir" checkout -B base $commit
 done
-- 
GitLab