]> git.ipfire.org Git - thirdparty/git.git/blobdiff - t/t0003-attributes.sh
Merge branch 'tb/t0003-invoke-dd-more-portably'
[thirdparty/git.git] / t / t0003-attributes.sh
index 07dc8c938e7ee8441a1d146539c590c29bef72da..89b306cb114debb61e787e6d80417cd362cc367f 100755 (executable)
@@ -2,14 +2,20 @@
 
 test_description=gitattributes
 
+TEST_PASSES_SANITIZE_LEAK=true
+TEST_CREATE_REPO_NO_TEMPLATE=1
 . ./test-lib.sh
 
-attr_check () {
+attr_check_basic () {
        path="$1" expect="$2" git_opts="$3" &&
 
        git $git_opts check-attr test -- "$path" >actual 2>err &&
        echo "$path: test: $expect" >expect &&
-       test_cmp expect actual &&
+       test_cmp expect actual
+}
+
+attr_check () {
+       attr_check_basic "$@" &&
        test_must_be_empty err
 }
 
@@ -19,7 +25,15 @@ attr_check_quote () {
        git check-attr test -- "$path" >actual &&
        echo "\"$quoted_path\": test: $expect" >expect &&
        test_cmp expect actual
+}
 
+attr_check_source () {
+       path="$1" expect="$2" source="$3" git_opts="$4" &&
+
+       git $git_opts check-attr --source $source test -- "$path" >actual 2>err &&
+       echo "$path: test: $expect" >expect &&
+       test_cmp expect actual &&
+       test_must_be_empty err
 }
 
 test_expect_success 'open-quoted pathname' '
@@ -27,7 +41,6 @@ test_expect_success 'open-quoted pathname' '
        attr_check a unspecified
 '
 
-
 test_expect_success 'setup' '
        mkdir -p a/b/d a/c b &&
        (
@@ -74,12 +87,23 @@ test_expect_success 'setup' '
        EOF
 '
 
+test_expect_success 'setup branches' '
+       mkdir -p foo/bar &&
+       test_commit --printf "add .gitattributes" foo/bar/.gitattributes \
+               "f test=f\na/i test=n\n" tag-1 &&
+       test_commit --printf "add .gitattributes" foo/bar/.gitattributes \
+               "g test=g\na/i test=m\n" tag-2 &&
+       rm foo/bar/.gitattributes
+'
+
 test_expect_success 'command line checks' '
        test_must_fail git check-attr &&
        test_must_fail git check-attr -- &&
        test_must_fail git check-attr test &&
        test_must_fail git check-attr test -- &&
        test_must_fail git check-attr -- f &&
+       test_must_fail git check-attr --source &&
+       test_must_fail git check-attr --source not-a-valid-ref &&
        echo "f" | test_must_fail git check-attr --stdin &&
        echo "f" | test_must_fail git check-attr --stdin -- f &&
        echo "f" | test_must_fail git check-attr --stdin test -- f &&
@@ -197,18 +221,24 @@ test_expect_success 'attribute test: read paths from stdin' '
        test_cmp expect actual
 '
 
-test_expect_success 'attribute test: --all option' '
+test_expect_success 'setup --all option' '
        grep -v unspecified <expect-all | sort >specified-all &&
-       sed -e "s/:.*//" <expect-all | uniq >stdin-all &&
-       git check-attr --stdin --all <stdin-all | sort >actual &&
+       sed -e "s/:.*//" <expect-all | uniq >stdin-all
+'
+
+test_expect_success 'attribute test: --all option' '
+       git check-attr --stdin --all <stdin-all >tmp &&
+       sort tmp >actual &&
        test_cmp specified-all actual
 '
 
 test_expect_success 'attribute test: --cached option' '
-       git check-attr --cached --stdin --all <stdin-all | sort >actual &&
+       git check-attr --cached --stdin --all <stdin-all >tmp &&
+       sort tmp >actual &&
        test_must_be_empty actual &&
        git add .gitattributes a/.gitattributes a/b/.gitattributes &&
-       git check-attr --cached --stdin --all <stdin-all | sort >actual &&
+       git check-attr --cached --stdin --all <stdin-all >tmp &&
+       sort tmp >actual &&
        test_cmp specified-all actual
 '
 
@@ -275,8 +305,17 @@ test_expect_success 'using --git-dir and --work-tree' '
        )
 '
 
+test_expect_success 'using --source' '
+       attr_check_source foo/bar/f f tag-1 &&
+       attr_check_source foo/bar/a/i n tag-1 &&
+       attr_check_source foo/bar/f unspecified tag-2 &&
+       attr_check_source foo/bar/a/i m tag-2 &&
+       attr_check_source foo/bar/g g tag-2 &&
+       attr_check_source foo/bar/g unspecified tag-1
+'
+
 test_expect_success 'setup bare' '
-       git clone --bare . bare.git
+       git clone --template= --bare . bare.git
 '
 
 test_expect_success 'bare repository: check that .gitattribute is ignored' '
@@ -294,6 +333,18 @@ test_expect_success 'bare repository: check that .gitattribute is ignored' '
        )
 '
 
+test_expect_success 'bare repository: with --source' '
+       (
+               cd bare.git &&
+               attr_check_source foo/bar/f f tag-1 &&
+               attr_check_source foo/bar/a/i n tag-1 &&
+               attr_check_source foo/bar/f unspecified tag-2 &&
+               attr_check_source foo/bar/a/i m tag-2 &&
+               attr_check_source foo/bar/g g tag-2 &&
+               attr_check_source foo/bar/g unspecified tag-1
+       )
+'
+
 test_expect_success 'bare repository: check that --cached honors index' '
        (
                cd bare.git &&
@@ -307,6 +358,7 @@ test_expect_success 'bare repository: check that --cached honors index' '
 test_expect_success 'bare repository: test info/attributes' '
        (
                cd bare.git &&
+               mkdir info &&
                (
                        echo "f test=f" &&
                        echo "a/i test=a/i"
@@ -331,7 +383,6 @@ test_expect_success 'binary macro expanded by -a' '
        test_cmp expect actual
 '
 
-
 test_expect_success 'query binary macro directly' '
        echo "file binary" >.gitattributes &&
        echo file: binary: set >expect &&
@@ -339,6 +390,34 @@ test_expect_success 'query binary macro directly' '
        test_cmp expect actual
 '
 
+test_expect_success SYMLINKS 'set up symlink tests' '
+       echo "* test" >attr &&
+       rm -f .gitattributes
+'
+
+test_expect_success SYMLINKS 'symlinks respected in core.attributesFile' '
+       test_when_finished "rm symlink" &&
+       ln -s attr symlink &&
+       test_config core.attributesFile "$(pwd)/symlink" &&
+       attr_check file set
+'
+
+test_expect_success SYMLINKS 'symlinks respected in info/attributes' '
+       test_when_finished "rm .git/info/attributes" &&
+       mkdir .git/info &&
+       ln -s ../../attr .git/info/attributes &&
+       attr_check file set
+'
+
+test_expect_success SYMLINKS 'symlinks not respected in-tree' '
+       test_when_finished "rm -rf .gitattributes subdir" &&
+       ln -s attr .gitattributes &&
+       mkdir subdir &&
+       ln -s ../attr subdir/.gitattributes &&
+       attr_check_basic subdir/file unspecified &&
+       test_i18ngrep "unable to access.*gitattributes" err
+'
+
 test_expect_success 'large attributes line ignored in tree' '
        test_when_finished "rm .gitattributes" &&
        printf "path %02043d" 1 >.gitattributes &&