chiark / gitweb /
test suite: gitattributes: Change a comment from xxx to todo
[dgit.git] / tests / tests / gitattributes
index 0093f0a454721d4a3b08585e9eb659cd6a2e0954..9ebc2161c83bb600f4eaf2a5156d4a4a159469b6 100755 (executable)
@@ -22,12 +22,20 @@ badattr1 () {
        printf >>af/$filename 'crlf: \r\n'
        echo >>af/$filename 'id $Id: $'
        echo >>af/$filename 'id $Id: SPLARK $'
+       printf >>af/$filename '\xEF\xBB\xBF <- UTF-8 BOM\n'
        echo >>gitattrs "af/$filename" "$attrspec"
 }
 
 badattr () {
        attrname=$1; shift
-       badattr1 $attrname-set $attrname
+
+       case "$attrname" in
+       working-tree-encoding) ;;
+       *)
+               badattr1 $attrname-set $attrname
+               ;;
+       esac
+
        badattr1 $attrname-unset -$attrname
        badattr1 $attrname-unspec \!$attrname
        local val
@@ -36,10 +44,13 @@ badattr () {
        done
 }
 
-# xxx want to make each of these files into a quilt patch
+# todo: want to make each of these files into a quilt patch
 
 t-git-config core.eol crlf
 
+printf >>.dotfile-attr 'dotfiles too?\n'
+echo >>gitattrs '.dotfile-attr filter=dgit-test-crazy-f'
+
 badattr        text auto
 badattr eol lf crlf
 badattr ident
@@ -57,6 +68,7 @@ badattr export-ignore
 badattr export-subst
 badattr delta
 badattr encoding no-such-encoding
+badattr working-tree-encoding ISO-8859-1 UTF-16
 
 man gitattributes \
 | perl -ne 'print $1,"\n" if m/^ *(\w[-a-z]*)$/' \
@@ -67,7 +79,7 @@ while read attr; do
        badattr $attr
 done
 
-sha256sum af/* >sums
+sha256sum .dotfile-attr af/* >sums
 
 # ----- common to source formats -----
 
@@ -92,7 +104,7 @@ sfmt_setup () {
        cp ../gitattrs .gitattributes
        $addpatch gitattrs
 
-       cp -a ../af .
+       cp -a ../af ../.dotfile-attr .
        $addpatch files
 
        cp ../sums .
@@ -108,10 +120,10 @@ sums_check () {
        #   $sums  $branch
        # and check out $branch
 
-       sha256sum af/* >../$sums.checkout
+       sha256sum .dotfile-attr af/* >../$sums.checkout
        diff -U0 ../sums ../$sums.checkout
 
-       for f in af/*; do
+       for f in .dotfile-attr af/*; do
                git cat-file blob "refs/heads/$branch:$f" \
                        | sha256sum \
                        | sed -e 's#-$#'$f'#' \
@@ -121,11 +133,45 @@ sums_check () {
        diff -U0 ../sums ../$sums
 }
 
+sums_check_broken () {
+       # caller should cd into working directory, set
+       #   $sums
+       # and check out the broken branch
+
+       sha256sum .dotfile-attr af/* >../$sums.broken
+
+       for s in ../sums ../$sums.broken; do
+               sed 's/[0-9a-f]* //' $s >$s.nosums
+       done
+       diff -U0 ../sums.nosums ../$sums.broken.nosums
+       set +e
+       diff -U0 ../sums ../$sums.broken
+       rc=$?
+       set -e
+       test $rc = 1
+}
+
+t-dgit-warn-check () {
+       local warnok=$1; shift
+       # warnok should be  0 if the warning is expected
+       #                   1 if the warning is NOT expected
+
+       local err=stderr.$wd
+
+       LC_MESSAGES=C t-dgit "$@" 2>&1 |tee ../$err
+
+       set +e
+       egrep 'warning: .* contains \.gitattributes' ../$err
+       rc=$?
+       set -e
+
+       test "$rc" = "$warnok"
+}
+
 sfmt_import () {
        inst=$1
        dgitargs=$2
        branch="import.$sfmt-$inst"
-       brkerr=stderr.$sfmt-$inst.broken
        dscf=${p}_${v}.dsc
        sums=sums.$sfmt-$inst
        wd=$pdb-import-$inst
@@ -134,27 +180,17 @@ sfmt_import () {
        cd $wd
        git init
 
-       LC_MESSAGES=C \
-       t-dgit $dgitargs import-dsc ../$dscf +$branch.broken \
-               2>&1 |tee ../$brkerr
-       fgrep 'warning: source tree contains .gitattributes' ../$brkerr
+       t-dgit-warn-check 0 $dgitargs import-dsc ../$dscf +$branch.broken
+
        git checkout $branch.broken
-       sha256sum af/* >../$sums.broken
 
-       for s in ../sums ../$sums.broken; do
-               sed 's/[0-9a-f]* //' $s >$s.nosums
-       done
-       diff -U0 ../sums.nosums ../$sums.broken.nosums
-       set +e
-       diff -U0 ../sums ../$sums.broken
-       rc=$?
-       set -e
-       test $rc = 1
+       sums_check_broken
 
        t-dgit setup-new-tree
 
-       t-dgit $dgitargs import-dsc ../$dscf +$branch
+       t-dgit-warn-check 1 $dgitargs import-dsc ../$dscf +$branch
        git checkout $branch
+       touch .dotfile-attr af/*
        git reset --hard
 
        sums_check
@@ -206,4 +242,47 @@ sfmt_setup 1.0-1 quilt
 sfmt_import norm
 sfmt_import absurd --force-import-gitapply-absurd
 
-#t-ok
+: ----- 'test clone (with "3.0 (quilt)")' -----
+
+mv $origtar ${dscf%.dsc}.* $tmp/mirror/pool/main/
+t-archive-query sid
+
+t-dgit-warn-check 0 -cdgit.default.setup-gitattributes=false \
+       clone $p sid $p.clone.broken
+cd $p.clone.broken
+
+sums=sums.broken
+sums_check_broken
+
+cd ..
+
+t-dgit-warn-check 1 clone $p sid $p.clone
+
+cd $p.clone
+sums=sums.clone
+branch=dgit/sid
+sums_check
+
+cd ..
+
+t-dgit-warn-check 0 -cdgit.default.setup-gitattributes=false \
+       clone $p sid $p.clone.old
+
+cd $p.clone.old
+
+mkdir -p .git/info
+cat >.git/info/attributes <<'END'
+*       dgit-defuse-attrs
+[attr]dgit-defuse-attrs -text -eol -crlf -ident -filter
+# ^ see GITATTRIBUTES in dgit(7) and dgit setup-new-tree in dgit(1)
+END
+
+t-dgit setup-gitattributes
+git reset --hard
+
+sums=sums.old
+sums_check
+
+cd ..
+
+t-ok