From 0a39954b44a16c6c03a38b953c9b844b386df4cc Mon Sep 17 00:00:00 2001 From: Stephen Haberman Date: Mon, 25 Aug 2008 12:59:42 -0500 Subject: [PATCH] Flush out tattoo and tests. --- scripts/gc-tattoo | 24 ++++++++++- tests/t5500-script-tattoo.sh | 78 ++++++++++++++++++++++++++++++++++++ 2 files changed, 100 insertions(+), 2 deletions(-) create mode 100644 tests/t5500-script-tattoo.sh diff --git a/scripts/gc-tattoo b/scripts/gc-tattoo index 75f0ea2..7ad1e54 100644 --- a/scripts/gc-tattoo +++ b/scripts/gc-tattoo @@ -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 index 0000000..7352183 --- /dev/null +++ b/tests/t5500-script-tattoo.sh @@ -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 + -- 2.39.5