Merge branch 'jk/show-branch-lift-name-len-limit'
[gitweb.git] / t / t9902-completion.sh
index 6e64cd6bac2da706d70434a499ed0f8fd2adbb09..d711bef2402cb7abd69c0bbcec49f7faba2530dd 100755 (executable)
@@ -131,126 +131,217 @@ else
        ROOT="$(pwd)"
 fi
 
-test_expect_success 'setup for __gitdir tests' '
+test_expect_success 'setup for __git_find_repo_path/__gitdir tests' '
        mkdir -p subdir/subsubdir &&
+       mkdir -p non-repo &&
        git init otherrepo
 '
 
-test_expect_success '__gitdir - from command line (through $__git_dir)' '
+test_expect_success '__git_find_repo_path - from command line (through $__git_dir)' '
        echo "$ROOT/otherrepo/.git" >expected &&
        (
                __git_dir="$ROOT/otherrepo/.git" &&
-               __gitdir >"$actual"
+               __git_find_repo_path &&
+               echo "$__git_repo_path" >"$actual"
        ) &&
        test_cmp expected "$actual"
 '
 
-test_expect_success '__gitdir - repo as argument' '
-       echo "otherrepo/.git" >expected &&
-       __gitdir "otherrepo" >"$actual" &&
-       test_cmp expected "$actual"
-'
-
-test_expect_success '__gitdir - remote as argument' '
-       echo "remote" >expected &&
-       __gitdir "remote" >"$actual" &&
-       test_cmp expected "$actual"
-'
-
-test_expect_success '__gitdir - .git directory in cwd' '
+test_expect_success '__git_find_repo_path - .git directory in cwd' '
        echo ".git" >expected &&
-       __gitdir >"$actual" &&
+       (
+               __git_find_repo_path &&
+               echo "$__git_repo_path" >"$actual"
+       ) &&
        test_cmp expected "$actual"
 '
 
-test_expect_success '__gitdir - .git directory in parent' '
+test_expect_success '__git_find_repo_path - .git directory in parent' '
        echo "$ROOT/.git" >expected &&
        (
                cd subdir/subsubdir &&
-               __gitdir >"$actual"
+               __git_find_repo_path &&
+               echo "$__git_repo_path" >"$actual"
        ) &&
        test_cmp expected "$actual"
 '
 
-test_expect_success '__gitdir - cwd is a .git directory' '
+test_expect_success '__git_find_repo_path - cwd is a .git directory' '
        echo "." >expected &&
        (
                cd .git &&
-               __gitdir >"$actual"
+               __git_find_repo_path &&
+               echo "$__git_repo_path" >"$actual"
        ) &&
        test_cmp expected "$actual"
 '
 
-test_expect_success '__gitdir - parent is a .git directory' '
+test_expect_success '__git_find_repo_path - parent is a .git directory' '
        echo "$ROOT/.git" >expected &&
        (
                cd .git/refs/heads &&
-               __gitdir >"$actual"
+               __git_find_repo_path &&
+               echo "$__git_repo_path" >"$actual"
        ) &&
        test_cmp expected "$actual"
 '
 
-test_expect_success '__gitdir - $GIT_DIR set while .git directory in cwd' '
+test_expect_success '__git_find_repo_path - $GIT_DIR set while .git directory in cwd' '
        echo "$ROOT/otherrepo/.git" >expected &&
        (
                GIT_DIR="$ROOT/otherrepo/.git" &&
                export GIT_DIR &&
-               __gitdir >"$actual"
+               __git_find_repo_path &&
+               echo "$__git_repo_path" >"$actual"
        ) &&
        test_cmp expected "$actual"
 '
 
-test_expect_success '__gitdir - $GIT_DIR set while .git directory in parent' '
+test_expect_success '__git_find_repo_path - $GIT_DIR set while .git directory in parent' '
        echo "$ROOT/otherrepo/.git" >expected &&
        (
                GIT_DIR="$ROOT/otherrepo/.git" &&
                export GIT_DIR &&
                cd subdir &&
-               __gitdir >"$actual"
+               __git_find_repo_path &&
+               echo "$__git_repo_path" >"$actual"
        ) &&
        test_cmp expected "$actual"
 '
 
-test_expect_success '__gitdir - non-existing path in $__git_dir' '
+test_expect_success '__git_find_repo_path - from command line while "git -C"' '
+       echo "$ROOT/.git" >expected &&
+       (
+               __git_dir="$ROOT/.git" &&
+               __git_C_args=(-C otherrepo) &&
+               __git_find_repo_path &&
+               echo "$__git_repo_path" >"$actual"
+       ) &&
+       test_cmp expected "$actual"
+'
+
+test_expect_success '__git_find_repo_path - relative dir from command line and "git -C"' '
+       echo "$ROOT/otherrepo/.git" >expected &&
+       (
+               cd subdir &&
+               __git_dir="otherrepo/.git" &&
+               __git_C_args=(-C ..) &&
+               __git_find_repo_path &&
+               echo "$__git_repo_path" >"$actual"
+       ) &&
+       test_cmp expected "$actual"
+'
+
+test_expect_success '__git_find_repo_path - $GIT_DIR set while "git -C"' '
+       echo "$ROOT/.git" >expected &&
+       (
+               GIT_DIR="$ROOT/.git" &&
+               export GIT_DIR &&
+               __git_C_args=(-C otherrepo) &&
+               __git_find_repo_path &&
+               echo "$__git_repo_path" >"$actual"
+       ) &&
+       test_cmp expected "$actual"
+'
+
+test_expect_success '__git_find_repo_path - relative dir in $GIT_DIR and "git -C"' '
+       echo "$ROOT/otherrepo/.git" >expected &&
+       (
+               cd subdir &&
+               GIT_DIR="otherrepo/.git" &&
+               export GIT_DIR &&
+               __git_C_args=(-C ..) &&
+               __git_find_repo_path &&
+               echo "$__git_repo_path" >"$actual"
+       ) &&
+       test_cmp expected "$actual"
+'
+
+test_expect_success '__git_find_repo_path - "git -C" while .git directory in cwd' '
+       echo "$ROOT/otherrepo/.git" >expected &&
+       (
+               __git_C_args=(-C otherrepo) &&
+               __git_find_repo_path &&
+               echo "$__git_repo_path" >"$actual"
+       ) &&
+       test_cmp expected "$actual"
+'
+
+test_expect_success '__git_find_repo_path - "git -C" while cwd is a .git directory' '
+       echo "$ROOT/otherrepo/.git" >expected &&
+       (
+               cd .git &&
+               __git_C_args=(-C .. -C otherrepo) &&
+               __git_find_repo_path &&
+               echo "$__git_repo_path" >"$actual"
+       ) &&
+       test_cmp expected "$actual"
+'
+
+test_expect_success '__git_find_repo_path - "git -C" while .git directory in parent' '
+       echo "$ROOT/otherrepo/.git" >expected &&
+       (
+               cd subdir &&
+               __git_C_args=(-C .. -C otherrepo) &&
+               __git_find_repo_path &&
+               echo "$__git_repo_path" >"$actual"
+       ) &&
+       test_cmp expected "$actual"
+'
+
+test_expect_success '__git_find_repo_path - non-existing path in "git -C"' '
+       (
+               __git_C_args=(-C non-existing) &&
+               test_must_fail __git_find_repo_path &&
+               printf "$__git_repo_path" >"$actual"
+       ) &&
+       test_must_be_empty "$actual"
+'
+
+test_expect_success '__git_find_repo_path - non-existing path in $__git_dir' '
        (
                __git_dir="non-existing" &&
-               test_must_fail __gitdir >"$actual"
+               test_must_fail __git_find_repo_path &&
+               printf "$__git_repo_path" >"$actual"
        ) &&
        test_must_be_empty "$actual"
 '
 
-test_expect_success '__gitdir - non-existing $GIT_DIR' '
+test_expect_success '__git_find_repo_path - non-existing $GIT_DIR' '
        (
                GIT_DIR="$ROOT/non-existing" &&
                export GIT_DIR &&
-               test_must_fail __gitdir >"$actual"
+               test_must_fail __git_find_repo_path &&
+               printf "$__git_repo_path" >"$actual"
        ) &&
        test_must_be_empty "$actual"
 '
 
-test_expect_success '__gitdir - gitfile in cwd' '
+test_expect_success '__git_find_repo_path - gitfile in cwd' '
        echo "$ROOT/otherrepo/.git" >expected &&
        echo "gitdir: $ROOT/otherrepo/.git" >subdir/.git &&
        test_when_finished "rm -f subdir/.git" &&
        (
                cd subdir &&
-               __gitdir >"$actual"
+               __git_find_repo_path &&
+               echo "$__git_repo_path" >"$actual"
        ) &&
        test_cmp expected "$actual"
 '
 
-test_expect_success '__gitdir - gitfile in parent' '
+test_expect_success '__git_find_repo_path - gitfile in parent' '
        echo "$ROOT/otherrepo/.git" >expected &&
        echo "gitdir: $ROOT/otherrepo/.git" >subdir/.git &&
        test_when_finished "rm -f subdir/.git" &&
        (
                cd subdir/subsubdir &&
-               __gitdir >"$actual"
+               __git_find_repo_path &&
+               echo "$__git_repo_path" >"$actual"
        ) &&
        test_cmp expected "$actual"
 '
 
-test_expect_success SYMLINKS '__gitdir - resulting path avoids symlinks' '
+test_expect_success SYMLINKS '__git_find_repo_path - resulting path avoids symlinks' '
        echo "$ROOT/otherrepo/.git" >expected &&
        mkdir otherrepo/dir &&
        test_when_finished "rm -rf otherrepo/dir" &&
@@ -258,16 +349,57 @@ test_expect_success SYMLINKS '__gitdir - resulting path avoids symlinks' '
        test_when_finished "rm -f link" &&
        (
                cd link &&
+               __git_find_repo_path &&
+               echo "$__git_repo_path" >"$actual"
+       ) &&
+       test_cmp expected "$actual"
+'
+
+test_expect_success '__git_find_repo_path - not a git repository' '
+       (
+               cd non-repo &&
+               GIT_CEILING_DIRECTORIES="$ROOT" &&
+               export GIT_CEILING_DIRECTORIES &&
+               test_must_fail __git_find_repo_path &&
+               printf "$__git_repo_path" >"$actual"
+       ) &&
+       test_must_be_empty "$actual"
+'
+
+test_expect_success '__gitdir - finds repo' '
+       echo "$ROOT/.git" >expected &&
+       (
+               cd subdir/subsubdir &&
                __gitdir >"$actual"
        ) &&
        test_cmp expected "$actual"
 '
 
-test_expect_success '__gitdir - not a git repository' '
-       nongit test_must_fail __gitdir >"$actual" &&
+
+test_expect_success '__gitdir - returns error when cant find repo' '
+       (
+               __git_dir="non-existing" &&
+               test_must_fail __gitdir >"$actual"
+       ) &&
        test_must_be_empty "$actual"
 '
 
+test_expect_success '__gitdir - repo as argument' '
+       echo "otherrepo/.git" >expected &&
+       (
+               __gitdir "otherrepo" >"$actual"
+       ) &&
+       test_cmp expected "$actual"
+'
+
+test_expect_success '__gitdir - remote as argument' '
+       echo "remote" >expected &&
+       (
+               __gitdir "remote" >"$actual"
+       ) &&
+       test_cmp expected "$actual"
+'
+
 test_expect_success '__gitcomp - trailing space - options' '
        test_gitcomp "--re" "--dry-run --reuse-message= --reedit-message=
                --reset-author" <<-EOF
@@ -369,10 +501,23 @@ test_expect_success '__git_remotes - list remotes from $GIT_DIR/remotes and from
        git remote add remote_in_config_1 git://remote_1 &&
        test_when_finished "git remote remove remote_in_config_2" &&
        git remote add remote_in_config_2 git://remote_2 &&
-       __git_remotes >actual &&
+       (
+               __git_remotes >actual
+       ) &&
        test_cmp expect actual
 '
 
+test_expect_success '__git_is_configured_remote' '
+       test_when_finished "git remote remove remote_1" &&
+       git remote add remote_1 git://remote_1 &&
+       test_when_finished "git remote remove remote_2" &&
+       git remote add remote_2 git://remote_2 &&
+       (
+               verbose __git_is_configured_remote remote_2 &&
+               test_must_fail __git_is_configured_remote non-existent
+       )
+'
+
 test_expect_success 'setup for ref completion' '
        git commit --allow-empty -m initial &&
        git branch matching-branch &&
@@ -516,7 +661,7 @@ test_expect_success '__git_refs - configured remote - full refs - repo given on
        test_cmp expected "$actual"
 '
 
-test_expect_failure '__git_refs - configured remote - remote name matches a directory' '
+test_expect_success '__git_refs - configured remote - remote name matches a directory' '
        cat >expected <<-EOF &&
        HEAD
        branch-in-other
@@ -531,7 +676,7 @@ test_expect_failure '__git_refs - configured remote - remote name matches a dire
        test_cmp expected "$actual"
 '
 
-test_expect_failure '__git_refs - URL remote' '
+test_expect_success '__git_refs - URL remote' '
        cat >expected <<-EOF &&
        HEAD
        branch-in-other
@@ -558,7 +703,7 @@ test_expect_success '__git_refs - URL remote - full refs' '
        test_cmp expected "$actual"
 '
 
-test_expect_failure '__git_refs - non-existing remote' '
+test_expect_success '__git_refs - non-existing remote' '
        (
                cur= &&
                __git_refs non-existing >"$actual"
@@ -574,7 +719,7 @@ test_expect_success '__git_refs - non-existing remote - full refs' '
        test_must_be_empty "$actual"
 '
 
-test_expect_failure '__git_refs - non-existing URL remote' '
+test_expect_success '__git_refs - non-existing URL remote' '
        (
                cur= &&
                __git_refs "file://$ROOT/non-existing" >"$actual"
@@ -590,7 +735,7 @@ test_expect_success '__git_refs - non-existing URL remote - full refs' '
        test_must_be_empty "$actual"
 '
 
-test_expect_failure '__git_refs - not in a git repository' '
+test_expect_success '__git_refs - not in a git repository' '
        (
                GIT_CEILING_DIRECTORIES="$ROOT" &&
                export GIT_CEILING_DIRECTORIES &&
@@ -746,7 +891,12 @@ test_expect_success 'general options plus command' '
        test_completion "git --namespace=foo check" "checkout " &&
        test_completion "git --paginate check" "checkout " &&
        test_completion "git --info-path check" "checkout " &&
-       test_completion "git --no-replace-objects check" "checkout "
+       test_completion "git --no-replace-objects check" "checkout " &&
+       test_completion "git --git-dir some/path check" "checkout " &&
+       test_completion "git -c conf.var=value check" "checkout " &&
+       test_completion "git -C some/path check" "checkout " &&
+       test_completion "git --work-tree some/path check" "checkout " &&
+       test_completion "git --namespace name/space check" "checkout "
 '
 
 test_expect_success 'git --help completion' '
@@ -771,6 +921,12 @@ test_expect_success 'checkout completes ref names' '
        EOF
 '
 
+test_expect_success 'git -C <path> checkout uses the right repo' '
+       test_completion "git -C subdir -C subsubdir -C .. -C ../otherrepo checkout b" <<-\EOF
+       branch-in-other Z
+       EOF
+'
+
 test_expect_success 'show completes all refs' '
        test_completion "git show m" <<-\EOF
        master Z