Adds testing of the basic options available to the git-softref command. Signed-off-by: Johan Herland <johan@xxxxxxxxxxx> --- t/t3050-softrefs.sh | 314 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 314 insertions(+), 0 deletions(-) create mode 100755 t/t3050-softrefs.sh diff --git a/t/t3050-softrefs.sh b/t/t3050-softrefs.sh new file mode 100755 index 0000000..a925178 --- /dev/null +++ b/t/t3050-softrefs.sh @@ -0,0 +1,314 @@ +#!/bin/sh +# +# Copyright (c) 2007 Johan Herland +# + +test_description='Basic functionality of soft references' +. ./test-lib.sh + + +# Prepare repo and create some notes + +test_expect_success 'Populating repo with test data' ' + echo "foo" > foo && + git-add foo && + test_tick && + git-commit -m "Initial commit" && + git-tag -a -m "Tagging initial commit" footag && + echo "bar" >> foo && + test_tick && + git-commit -m "Second commit" foo && + git-tag -a -m "Tagging second commit" bartag +' + +# At this point we should have: +# - commit @ 301711b66fe71164f646b798706a2c1f7024da8d ("Initial commit") +# - tag @ ad60bc179c6874af6d97f181c67f11adcca5122b ("footag") +# - commit @ 9671cbee7ad26528645b2665c8f74d39a6288864 ("Second commit") +# - tag @ a927fc832d42f1f64d8318e8acec43545d9562de ("bartag") +# - The tag creation should also have created softrefs: +# - From "Initial commit" to "footag" +# - From "Second commit" to "bartag" + +# Testing git-softref --list + +test_expect_success 'Testing git-softref --list on initial test data (1)' ' + cat > expected_output << EOF && +301711b66fe71164f646b798706a2c1f7024da8d ad60bc179c6874af6d97f181c67f11adcca5122b +9671cbee7ad26528645b2665c8f74d39a6288864 a927fc832d42f1f64d8318e8acec43545d9562de +EOF + git-softref > actual_output 2>&1 && + cmp actual_output expected_output && + git-softref --list > actual_output 2>&1 && + cmp actual_output expected_output +' + +test_expect_success 'Testing git-softref --list on initial test data (2)' ' + cat > expected_output << EOF && +9671cbee7ad26528645b2665c8f74d39a6288864 a927fc832d42f1f64d8318e8acec43545d9562de +EOF + git-softref --list 9671cbee7ad26528645b2665c8f74d39a6288864 > actual_output 2>&1 && + cmp actual_output expected_output && + git-softref --list HEAD > actual_output 2>&1 && + cmp actual_output expected_output +' + +test_expect_success 'Testing git-softref --list on initial test data (3)' ' + cat > expected_output << EOF && +301711b66fe71164f646b798706a2c1f7024da8d ad60bc179c6874af6d97f181c67f11adcca5122b +EOF + git-softref --list 301711b66fe71164f646b798706a2c1f7024da8d > actual_output 2>&1 && + cmp actual_output expected_output && + git-softref --list HEAD^ > actual_output 2>&1 && + cmp actual_output expected_output +' + +test_expect_success 'Testing git-softref --list on initial test data (4)' ' + cat > expected_output << EOF && +EOF + git-softref --list footag > actual_output 2>&1 && + cmp actual_output expected_output && + git-softref --list bartag > actual_output 2>&1 && + cmp actual_output expected_output +' + +# Testing git-softref --has + +test_expect_success 'Testing git-softref --has on initial test data' ' + (git-softref --has 301711b66fe71164f646b798706a2c1f7024da8d ad60bc179c6874af6d97f181c67f11adcca5122b; + test "$?" = "1") && + (git-softref --has HEAD^ footag; + test "$?" = "1") && + (git-softref --has footag^{} footag; + test "$?" = "1") && + (git-softref --has 9671cbee7ad26528645b2665c8f74d39a6288864 a927fc832d42f1f64d8318e8acec43545d9562de; + test "$?" = "1") && + (git-softref --has HEAD bartag; + test "$?" = "1") && + (git-softref --has bartag^{} bartag; + test "$?" = "1") && + (git-softref --has ad60bc179c6874af6d97f181c67f11adcca5122b 301711b66fe71164f646b798706a2c1f7024da8d; + test "$?" = "0") && + (git-softref --has a927fc832d42f1f64d8318e8acec43545d9562de 9671cbee7ad26528645b2665c8f74d39a6288864; + test "$?" = "0") && + (git-softref --has HEAD HEAD^; + test "$?" = "0") && + (git-softref --has HEAD^ HEAD; + test "$?" = "0") && + (git-softref --has footag HEAD; + test "$?" = "0") && + (git-softref --has bartag HEAD; + test "$?" = "0") && + (git-softref --has footag HEAD^; + test "$?" = "0") && + (git-softref --has bartag HEAD^; + test "$?" = "0") && + (git-softref --has footag bartag; + test "$?" = "0") && + (git-softref --has bartag footag; + test "$?" = "0") +' + +# Testing git-softref --rebuild-tags + +test_expect_success 'Testing git-softref --rebuild-tags on initial test data' ' + cat > expected_output << EOF && +Added 0 missing softrefs for tag objects. +EOF + cat .git/softrefs.* | sort > expected_softrefs && + git-softref --rebuild-tags > actual_output 2>&1 && + cat .git/softrefs.* | sort > actual_softrefs && + cmp actual_output expected_output && + cmp actual_softrefs expected_softrefs +' + +# Testing git-softref --add + +test_expect_success 'Testing git-softref --add with existing softref' ' + cat > expected_output << EOF && +EOF + cat .git/softrefs.* | sort > expected_softrefs && + git-softref --add HEAD bartag > actual_output 2>&1 && + cat .git/softrefs.* | sort > actual_softrefs && + cmp actual_output expected_output && + cmp actual_softrefs expected_softrefs +' + +test_expect_success 'Testing git-softref --add with self-refential softref' ' + cat > expected_output << EOF && +error: Cannot add self-reference (9671cbee7ad26528645b2665c8f74d39a6288864 -> 9671cbee7ad26528645b2665c8f74d39a6288864) +fatal: Failed to create softref from HEAD to HEAD +EOF + cat .git/softrefs.* | sort > expected_softrefs && + (git-softref --add HEAD HEAD > actual_output 2>&1; test "$?" != "0") && + cat .git/softrefs.* | sort > actual_softrefs && + cmp actual_output expected_output && + cmp actual_softrefs expected_softrefs +' + +test_expect_success 'Testing git-softref --add with non-existing objects (1)' ' + cat > expected_output << EOF && +fatal: Not a valid object name 1234567890123456789012345678901234567890 +EOF + cat .git/softrefs.* | sort > expected_softrefs && + (git-softref --add 1234567890123456789012345678901234567890 HEAD > actual_output 2>&1; + test "$?" != "0") && + cat .git/softrefs.* | sort > actual_softrefs && + cmp actual_output expected_output && + cmp actual_softrefs expected_softrefs && + (git-softref --add HEAD 1234567890123456789012345678901234567890 > actual_output 2>&1; + test "$?" != "0") && + cat .git/softrefs.* | sort > actual_softrefs && + cmp actual_output expected_output && + cmp actual_softrefs expected_softrefs +' + +test_expect_success 'Testing git-softref --add with non-existing objects (2)' ' + cat > expected_output << EOF && +fatal: Not a valid object name HEAD^^^ +EOF + cat .git/softrefs.* | sort > expected_softrefs && + (git-softref --add HEAD^^^ HEAD > actual_output 2>&1; test "$?" != "0") && + cat .git/softrefs.* | sort > actual_softrefs && + cmp actual_output expected_output && + cmp actual_softrefs expected_softrefs +' + +test_expect_success 'Testing git-softref --add with valid arguments (1)' ' + cat > expected_output << EOF && +EOF + cat > new_softref << EOF +301711b66fe71164f646b798706a2c1f7024da8d 9671cbee7ad26528645b2665c8f74d39a6288864 +EOF + cat .git/softrefs.* new_softref | sort > expected_softrefs && + git-softref --add HEAD^ HEAD > actual_output 2>&1 && + cat .git/softrefs.* | sort > actual_softrefs && + cmp actual_output expected_output && + cmp actual_softrefs expected_softrefs +' + +test_expect_success 'Testing git-softref --add with valid arguments (2)' ' + cat > expected_output << EOF && +EOF + cat > new_softref << EOF +ad60bc179c6874af6d97f181c67f11adcca5122b a927fc832d42f1f64d8318e8acec43545d9562de +EOF + cat .git/softrefs.* new_softref | sort > expected_softrefs && + git-softref --add footag bartag > actual_output 2>&1 && + cat .git/softrefs.* | sort > actual_softrefs && + cmp actual_output expected_output && + cmp actual_softrefs expected_softrefs +' + +# Removing softrefs + +test_expect_success 'Removing all softrefs' ' + rm .git/softrefs.* +' + +# Testing git-softref --list and --has + +test_expect_success 'Testing git-softref with no softrefs' ' + cat > expected_output << EOF && +EOF + git-softref > actual_output 2>&1 && + cmp actual_output expected_output && + git-softref --list > actual_output 2>&1 && + cmp actual_output expected_output && + git-softref --list 9671cbee7ad26528645b2665c8f74d39a6288864 > actual_output 2>&1 && + cmp actual_output expected_output && + git-softref --list HEAD > actual_output 2>&1 && + cmp actual_output expected_output && + git-softref --list HEAD^ > actual_output 2>&1 && + cmp actual_output expected_output && + git-softref --list footag > actual_output 2>&1 && + cmp actual_output expected_output && + git-softref --list bartag > actual_output 2>&1 && + cmp actual_output expected_output && + git-softref --has HEAD bartag > actual_output 2>&1 && + cmp actual_output expected_output && + git-softref --has HEAD^ footag > actual_output 2>&1 && + cmp actual_output expected_output +' + +# Testing git-softref --rebuild-tags +# (Should recreated missing softrefs for tag objects reachable from 'refs/tags') + +test_expect_success 'Testing git-softref --rebuild-tags to rebuild missing tag softrefs' ' + cat > expected_output << EOF && +Added 2 missing softrefs for tag objects. +EOF + cat > new_softref << EOF +301711b66fe71164f646b798706a2c1f7024da8d ad60bc179c6874af6d97f181c67f11adcca5122b +9671cbee7ad26528645b2665c8f74d39a6288864 a927fc832d42f1f64d8318e8acec43545d9562de +EOF + cat .git/softrefs.* new_softref | sort > expected_softrefs && + git-softref --rebuild-tags > actual_output 2>&1 && + cat .git/softrefs.* | sort > actual_softrefs && + cmp actual_output expected_output && + cmp actual_softrefs expected_softrefs +' + +# Testing git-softref --merge-unsorted + +test_expect_success 'Testing git-softref --merge-unsorted' ' + cat > expected_output << EOF && +EOF + rm .git/softrefs* + cat > .git/softrefs.unsorted << EOF +9671cbee7ad26528645b2665c8f74d39a6288864 a927fc832d42f1f64d8318e8acec43545d9562de +301711b66fe71164f646b798706a2c1f7024da8d ad60bc179c6874af6d97f181c67f11adcca5122b +EOF + cat > expected_softrefs << EOF +301711b66fe71164f646b798706a2c1f7024da8d ad60bc179c6874af6d97f181c67f11adcca5122b +9671cbee7ad26528645b2665c8f74d39a6288864 a927fc832d42f1f64d8318e8acec43545d9562de +EOF + git-softref --merge-unsorted > actual_output 2>&1 && + cmp actual_output expected_output && + cmp .git/softrefs.sorted expected_softrefs && + test ! -e .git/softrefs.unsorted +' + +# Testing git-softref --merge-unsorted <filename> + +test_expect_success 'Testing git-softref --merge-unsorted <filename>' ' + cat > expected_output << EOF && +EOF + rm .git/softrefs* + cat > new_softrefs << EOF +9671cbee7ad26528645b2665c8f74d39a6288864 a927fc832d42f1f64d8318e8acec43545d9562de +301711b66fe71164f646b798706a2c1f7024da8d ad60bc179c6874af6d97f181c67f11adcca5122b +EOF + cat > expected_softrefs << EOF +301711b66fe71164f646b798706a2c1f7024da8d ad60bc179c6874af6d97f181c67f11adcca5122b +9671cbee7ad26528645b2665c8f74d39a6288864 a927fc832d42f1f64d8318e8acec43545d9562de +EOF + git-softref --merge-unsorted new_softrefs > actual_output 2>&1 && + cmp actual_output expected_output && + cmp .git/softrefs.sorted expected_softrefs && + test -e new_softrefs +' + +# Testing git-softref --merge-sorted <filename> + +test_expect_success 'Testing git-softref --merge-sorted <filename>' ' + cat > expected_output << EOF && +EOF + rm .git/softrefs* + cat > new_softrefs << EOF +301711b66fe71164f646b798706a2c1f7024da8d ad60bc179c6874af6d97f181c67f11adcca5122b +9671cbee7ad26528645b2665c8f74d39a6288864 a927fc832d42f1f64d8318e8acec43545d9562de +EOF + cat > expected_softrefs << EOF +301711b66fe71164f646b798706a2c1f7024da8d ad60bc179c6874af6d97f181c67f11adcca5122b +9671cbee7ad26528645b2665c8f74d39a6288864 a927fc832d42f1f64d8318e8acec43545d9562de +EOF + git-softref --merge-sorted new_softrefs > actual_output 2>&1 && + cmp actual_output expected_output && + cmp .git/softrefs.sorted expected_softrefs && + test -e new_softrefs +' + +# FIXME: More testing needed on how softrefs interact with the rest of git + +test_done -- 1.5.2.1.144.gabc40 - To unsubscribe from this list: send the line "unsubscribe git" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html