From 3101df56fa5feb04ed78e6340f1ee7ead820625a Mon Sep 17 00:00:00 2001
From: Christian Couder <chriscool@tuxfamily.org>
Date: Sat, 13 Jun 2015 22:29:09 +0200
Subject: [PATCH 1/3] install-sharness.sh: implement updates

We want to be able to update Sharness to benefit from
new features.

License: MIT
Signed-off-by: Christian Couder <chriscool@tuxfamily.org>
---
 test/sharness/lib/install-sharness.sh | 35 +++++++++++++++++++++------
 1 file changed, 28 insertions(+), 7 deletions(-)

diff --git a/test/sharness/lib/install-sharness.sh b/test/sharness/lib/install-sharness.sh
index d573c4069..6377c7ee7 100755
--- a/test/sharness/lib/install-sharness.sh
+++ b/test/sharness/lib/install-sharness.sh
@@ -11,16 +11,37 @@ urlprefix=https://github.com/mlafeldt/sharness.git
 clonedir=lib
 sharnessdir=sharness
 
+if test -f "$clonedir/$sharnessdir/SHARNESS_VERSION_$version"
+then
+    # There is the right version file. Great, we are done!
+    exit 0
+fi
+
 die() {
-  echo >&2 "$@"
-  exit 1
+    echo >&2 "$@"
+    exit 1
 }
 
-mkdir -p "$clonedir" || die "Could not create '$clonedir' directory"
-cd "$clonedir" || die "Could not cd into '$clonedir' directory"
+checkout_version() {
+    git checkout "$version" || die "Could not checkout '$version'"
+    rm -f SHARNESS_VERSION_* || die "Could not remove 'SHARNESS_VERSION_*'"
+    touch "SHARNESS_VERSION_$version" || die "Could not create 'SHARNESS_VERSION_$version'"
+    echo "Sharness version $version is checked out!"
+}
 
-git clone "$urlprefix" || die "Could not clone '$urlprefix'"
-cd "$sharnessdir" || die "Could not cd into '$sharnessdir' directory"
-git checkout "$version" || die "Could not checkout '$version'"
+if test -d "$clonedir/$sharnessdir/.git"
+then
+    # We need to update sharness!
+    cd "$clonedir/$sharnessdir" || die "Could not cd into '$clonedir/$sharnessdir' directory"
+    git fetch || die "Could not fetch to update sharness"
+    checkout_version
+else
+    # We need to clone sharness!
+    mkdir -p "$clonedir" || die "Could not create '$clonedir' directory"
+    cd "$clonedir" || die "Could not cd into '$clonedir' directory"
 
+    git clone "$urlprefix" || die "Could not clone '$urlprefix'"
+    cd "$sharnessdir" || die "Could not cd into '$sharnessdir' directory"
+    checkout_version
+fi
 exit 0

From ac9f441f1f64bbcd845d1dc920082795247def13 Mon Sep 17 00:00:00 2001
From: Christian Couder <chriscool@tuxfamily.org>
Date: Sat, 13 Jun 2015 22:39:37 +0200
Subject: [PATCH 2/3] sharness/Makefile: force sharness version check

License: MIT
Signed-off-by: Christian Couder <chriscool@tuxfamily.org>
---
 test/sharness/Makefile | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/test/sharness/Makefile b/test/sharness/Makefile
index 100f952c8..fd3869428 100644
--- a/test/sharness/Makefile
+++ b/test/sharness/Makefile
@@ -35,8 +35,8 @@ aggregate: clean-test-results $(T)
 
 deps: $(SHARNESS) $(BINS) curl
 
-$(SHARNESS):
-	@echo "*** installing $@ ***"
+$(SHARNESS): FORCE
+	@echo "*** checking $@ ***"
 	lib/install-sharness.sh
 
 bin/%: FORCE

From 0befe2bf883a3b74e7a07e93dfffb01e9297a7f9 Mon Sep 17 00:00:00 2001
From: Christian Couder <chriscool@tuxfamily.org>
Date: Sat, 13 Jun 2015 22:40:34 +0200
Subject: [PATCH 3/3] install-sharness.sh: update sharness

License: MIT
Signed-off-by: Christian Couder <chriscool@tuxfamily.org>
---
 test/sharness/lib/install-sharness.sh | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/test/sharness/lib/install-sharness.sh b/test/sharness/lib/install-sharness.sh
index 6377c7ee7..5777ffa10 100755
--- a/test/sharness/lib/install-sharness.sh
+++ b/test/sharness/lib/install-sharness.sh
@@ -6,7 +6,7 @@
 #
 
 # settings
-version=50229a79ba22b2f13ccd82451d86570fecbd194c
+version=5eee9b51b5621cec95a64018f0cc779963b230d2
 urlprefix=https://github.com/mlafeldt/sharness.git
 clonedir=lib
 sharnessdir=sharness