Imported Upstream version 2.16.3
[platform/upstream/git.git] / t / t1308-config-set.sh
index 9863d0d..bafed5c 100755 (executable)
@@ -183,11 +183,22 @@ test_expect_success 'proper error on non-existent files' '
        test_cmp expect actual
 '
 
+test_expect_success 'proper error on directory "files"' '
+       echo "Error (-1) reading configuration file a-directory." >expect &&
+       mkdir a-directory &&
+       test_expect_code 2 test-config configset_get_value foo.bar a-directory 2>output &&
+       grep "^warning:" output &&
+       grep "^Error" output >actual &&
+       test_cmp expect actual
+'
+
 test_expect_success POSIXPERM,SANITY 'proper error on non-accessible files' '
        chmod -r .git/config &&
        test_when_finished "chmod +r .git/config" &&
        echo "Error (-1) reading configuration file .git/config." >expect &&
-       test_expect_code 2 test-config configset_get_value foo.bar .git/config 2>actual &&
+       test_expect_code 2 test-config configset_get_value foo.bar .git/config 2>output &&
+       grep "^warning:" output &&
+       grep "^Error" output >actual &&
        test_cmp expect actual
 '
 
@@ -195,16 +206,16 @@ test_expect_success 'proper error on error in default config files' '
        cp .git/config .git/config.old &&
        test_when_finished "mv .git/config.old .git/config" &&
        echo "[" >>.git/config &&
-       echo "fatal: bad config file line 34 in .git/config" >expect &&
+       echo "fatal: bad config line 34 in file .git/config" >expect &&
        test_expect_code 128 test-config get_value foo.bar 2>actual &&
-       test_cmp expect actual
+       test_i18ncmp expect actual
 '
 
 test_expect_success 'proper error on error in custom config files' '
        echo "[" >>syntax-error &&
-       echo "fatal: bad config file line 1 in syntax-error" >expect &&
+       echo "fatal: bad config line 1 in file syntax-error" >expect &&
        test_expect_code 128 test-config configset_get_value foo.bar syntax-error 2>actual &&
-       test_cmp expect actual
+       test_i18ncmp expect actual
 '
 
 test_expect_success 'check line errors for malformed values' '
@@ -215,18 +226,49 @@ test_expect_success 'check line errors for malformed values' '
                br
        EOF
        test_expect_code 128 git br 2>result &&
-       test_i18ngrep "fatal: .*alias\.br.*\.git/config.*line 2" result
+       test_i18ngrep "missing value for .alias\.br" result &&
+       test_i18ngrep "fatal: .*\.git/config" result &&
+       test_i18ngrep "fatal: .*line 2" result
 '
 
 test_expect_success 'error on modifying repo config without repo' '
-       mkdir no-repo &&
-       (
-               GIT_CEILING_DIRECTORIES=$(pwd) &&
-               export GIT_CEILING_DIRECTORIES &&
-               cd no-repo &&
-               test_must_fail git config a.b c 2>err &&
-               grep "not in a git directory" err
-       )
+       nongit test_must_fail git config a.b c 2>err &&
+       grep "not in a git directory" err
+'
+
+cmdline_config="'foo.bar=from-cmdline'"
+test_expect_success 'iteration shows correct origins' '
+       echo "[foo]bar = from-repo" >.git/config &&
+       echo "[foo]bar = from-home" >.gitconfig &&
+       if test_have_prereq MINGW
+       then
+               # Use Windows path (i.e. *not* $HOME)
+               HOME_GITCONFIG=$(pwd)/.gitconfig
+       else
+               # Do not get fooled by symbolic links, i.e. $HOME != $(pwd)
+               HOME_GITCONFIG=$HOME/.gitconfig
+       fi &&
+       cat >expect <<-EOF &&
+       key=foo.bar
+       value=from-home
+       origin=file
+       name=$HOME_GITCONFIG
+       scope=global
+
+       key=foo.bar
+       value=from-repo
+       origin=file
+       name=.git/config
+       scope=repo
+
+       key=foo.bar
+       value=from-cmdline
+       origin=command line
+       name=
+       scope=cmdline
+       EOF
+       GIT_CONFIG_PARAMETERS=$cmdline_config test-config iterate >actual &&
+       test_cmp expect actual
 '
 
 test_done