Flush out tattoo and tests.
authorStephen Haberman <stephen@exigencecorp.com>
Mon, 25 Aug 2008 17:59:42 +0000 (12:59 -0500)
committerStephen Haberman <stephen@exigencecorp.com>
Mon, 25 Aug 2008 17:59:42 +0000 (12:59 -0500)
scripts/gc-tattoo
tests/t5500-script-tattoo.sh [new file with mode: 0644]

index 75f0ea2..7ad1e54 100644 (file)
@@ -10,11 +10,31 @@ fi
 case "$branch" in
        refs/heads/*)
                branch=${branch##refs/heads/}
-               number=$(git rev-list --first-parent "$head" ^stable | wc -l)
-               echo "$branch-$number"
                ;;
        *)
                echo "unknown"
                exit 1
+               ;;
 esac
 
+# Ensure pushed
+git branch -r --contains $head | grep --quiet "origin/$branch"
+if [ $? -ne 0 ] ; then
+       echo "$branch has not been pushed"
+       exit 1
+fi
+
+# Handle stable special to look for the annotated tag
+if [ "$branch" == "stable" ] ; then
+       describe=$(git describe $head 2>/dev/null)
+       if [ $? -eq 0 ] ; then
+               echo "$describe"
+       else
+               echo "stable-$head"
+       fi
+       exit 0
+fi
+
+number=$(git rev-list --first-parent "$head" ^origin/stable | wc -l)
+echo "$branch-$number"
+
diff --git a/tests/t5500-script-tattoo.sh b/tests/t5500-script-tattoo.sh
new file mode 100644 (file)
index 0000000..7352183
--- /dev/null
@@ -0,0 +1,78 @@
+#!/bin/sh
+
+test_description='script tattoo'
+
+. ./test-lib.sh
+
+export PATH=$PATH:../../scripts
+
+test_expect_success 'setup' '
+       echo "setup" >a &&
+       git add a &&
+       git commit -m "setup" &&
+       git clone ./. server &&
+       rm -fr server/.git/hooks &&
+       git remote add origin ./server &&
+       git checkout -b stable &&
+       git push origin stable
+'
+
+test_expect_success 'tattoo 0' '
+       git checkout -b topic1 &&
+       git push origin topic1 &&
+       gc-tattoo | grep topic1-0
+'
+
+test_expect_success 'tattoo 1' '
+       echo "$test_name" >a &&
+       git commit -a -m "make topic1-1" &&
+       git push origin topic1 &&
+       gc-tattoo | grep topic1-1
+'
+
+test_expect_success 'merge topic2 topic1 as tattoo 2' '
+       git checkout -b topic2 stable &&
+       echo "$test_name" >a.topic2 &&
+       git add a.topic2
+       git commit -m "make topic2" &&
+       git push origin topic2 &&
+       gc-tattoo | grep topic2-1
+
+       git checkout topic1 &&
+       git merge topic2 &&
+       git push origin topic1 &&
+       gc-tattoo | grep topic1-2
+'
+
+test_expect_success 'stable without a tag' '
+       git checkout stable &&
+       head=$(git rev-parse HEAD) &&
+       gc-tattoo | grep "stable-$head"
+'
+
+test_expect_success 'stable with a tag' '
+       git tag -m "1.0" 1.0 &&
+       gc-tattoo | grep "1.0"
+'
+
+test_expect_success 'fails if not pushed' '
+       git checkout topic1 &&
+       echo "$test_name" >a &&
+       git commit -a -m "make topic1-3" &&
+       gc-tattoo | grep "topic1 has not been pushed"
+'
+
+test_expect_success 'stable fails if not pushed' '
+       git checkout stable &&
+       git merge --no-ff topic1 &&
+       gc-tattoo | grep "stable has not been pushed"
+'
+
+test_expect_success 'use origin stable not local' '
+       git checkout topic1 &&
+       git push origin topic1 &&
+       gc-tattoo | grep "topic1-3"
+'
+
+test_done
+