test_cmp expected "$actual"
'
+test_expect_success '__gitdir - from command line while "git -C"' '
+ echo "$ROOT/.git" >expected &&
+ (
+ __git_dir="$ROOT/.git" &&
+ __git_C_args=(-C otherrepo) &&
+ __gitdir >"$actual"
+ ) &&
+ test_cmp expected "$actual"
+'
+
+test_expect_success '__gitdir - relative dir from command line and "git -C"' '
+ echo "$ROOT/otherrepo/.git" >expected &&
+ (
+ cd subdir &&
+ __git_dir="otherrepo/.git" &&
+ __git_C_args=(-C ..) &&
+ __gitdir >"$actual"
+ ) &&
+ test_cmp expected "$actual"
+'
+
+test_expect_success '__gitdir - $GIT_DIR set while "git -C"' '
+ echo "$ROOT/.git" >expected &&
+ (
+ GIT_DIR="$ROOT/.git" &&
+ export GIT_DIR &&
+ __git_C_args=(-C otherrepo) &&
+ __gitdir >"$actual"
+ ) &&
+ test_cmp expected "$actual"
+'
+
+test_expect_success '__gitdir - 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 ..) &&
+ __gitdir >"$actual"
+ ) &&
+ test_cmp expected "$actual"
+'
+
+test_expect_success '__gitdir - "git -C" while .git directory in cwd' '
+ echo "$ROOT/otherrepo/.git" >expected &&
+ (
+ __git_C_args=(-C otherrepo) &&
+ __gitdir >"$actual"
+ ) &&
+ test_cmp expected "$actual"
+'
+
+test_expect_success '__gitdir - "git -C" while cwd is a .git directory' '
+ echo "$ROOT/otherrepo/.git" >expected &&
+ (
+ cd .git &&
+ __git_C_args=(-C .. -C otherrepo) &&
+ __gitdir >"$actual"
+ ) &&
+ test_cmp expected "$actual"
+'
+
+test_expect_success '__gitdir - "git -C" while .git directory in parent' '
+ echo "$ROOT/otherrepo/.git" >expected &&
+ (
+ cd subdir &&
+ __git_C_args=(-C .. -C otherrepo) &&
+ __gitdir >"$actual"
+ ) &&
+ test_cmp expected "$actual"
+'
+
+test_expect_success '__gitdir - non-existing path in "git -C"' '
+ (
+ __git_C_args=(-C non-existing) &&
+ test_must_fail __gitdir >"$actual"
+ ) &&
+ test_must_be_empty "$actual"
+'
+
+test_expect_success '__gitdir - non-existing path in $__git_dir' '
+ (
+ __git_dir="non-existing" &&
+ test_must_fail __gitdir >"$actual"
+ ) &&
+ test_must_be_empty "$actual"
+'
+
test_expect_success '__gitdir - non-existing $GIT_DIR' '
(
GIT_DIR="$ROOT/non-existing" &&
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 &&
test_cmp expected "$actual"
'
-test_expect_failure '__git_refs - configured remote - repo given on the command line' '
+test_expect_success '__git_refs - configured remote - repo given on the command line' '
cat >expected <<-EOF &&
HEAD
branch-in-other
test_cmp expected "$actual"
'
-test_expect_failure '__git_refs - configured remote - full refs - repo given on the command line' '
+test_expect_success '__git_refs - configured remote - full refs - repo given on the command line' '
cat >expected <<-EOF &&
refs/heads/branch-in-other
refs/heads/master-in-other
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
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
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"
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"
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 &&
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' '
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