clone_submodule: avoid using `access()` on directories
[git.git] / t / t0056-git-C.sh
blob752aa8c945431b909e580f557ef738a455fa8132
1 #!/bin/sh
3 test_description='"-C <path>" option and its effects on other path-related options'
5 TEST_PASSES_SANITIZE_LEAK=true
6 . ./test-lib.sh
8 test_expect_success '"git -C <path>" runs git from the directory <path>' '
9 test_create_repo dir1 &&
10 echo 1 >dir1/a.txt &&
11 msg="initial in dir1" &&
12 (cd dir1 && git add a.txt && git commit -m "$msg") &&
13 echo "$msg" >expected &&
14 git -C dir1 log --format=%s >actual &&
15 test_cmp expected actual
18 test_expect_success '"git -C <path>" with an empty <path> is a no-op' '
20 mkdir -p dir1/subdir &&
21 cd dir1/subdir &&
22 git -C "" rev-parse --show-prefix >actual &&
23 echo subdir/ >expect &&
24 test_cmp expect actual
28 test_expect_success 'Multiple -C options: "-C dir1 -C dir2" is equivalent to "-C dir1/dir2"' '
29 test_create_repo dir1/dir2 &&
30 echo 1 >dir1/dir2/b.txt &&
31 git -C dir1/dir2 add b.txt &&
32 msg="initial in dir1/dir2" &&
33 echo "$msg" >expected &&
34 git -C dir1/dir2 commit -m "$msg" &&
35 git -C dir1 -C dir2 log --format=%s >actual &&
36 test_cmp expected actual
39 test_expect_success 'Effect on --git-dir option: "-C c --git-dir=a.git" is equivalent to "--git-dir c/a.git"' '
40 mkdir c &&
41 mkdir c/a &&
42 mkdir c/a.git &&
43 (cd c/a.git && git init --bare) &&
44 echo 1 >c/a/a.txt &&
45 git --git-dir c/a.git --work-tree=c/a add a.txt &&
46 git --git-dir c/a.git --work-tree=c/a commit -m "initial" &&
47 git --git-dir=c/a.git log -1 --format=%s >expected &&
48 git -C c --git-dir=a.git log -1 --format=%s >actual &&
49 test_cmp expected actual
52 test_expect_success 'Order should not matter: "--git-dir=a.git -C c" is equivalent to "-C c --git-dir=a.git"' '
53 git -C c --git-dir=a.git log -1 --format=%s >expected &&
54 git --git-dir=a.git -C c log -1 --format=%s >actual &&
55 test_cmp expected actual
58 test_expect_success 'Effect on --work-tree option: "-C c/a.git --work-tree=../a" is equivalent to "--work-tree=c/a --git-dir=c/a.git"' '
59 rm c/a/a.txt &&
60 git --git-dir=c/a.git --work-tree=c/a status >expected &&
61 git -C c/a.git --work-tree=../a status >actual &&
62 test_cmp expected actual
65 test_expect_success 'Order should not matter: "--work-tree=../a -C c/a.git" is equivalent to "-C c/a.git --work-tree=../a"' '
66 git -C c/a.git --work-tree=../a status >expected &&
67 git --work-tree=../a -C c/a.git status >actual &&
68 test_cmp expected actual
71 test_expect_success 'Effect on --git-dir and --work-tree options - "-C c --git-dir=a.git --work-tree=a" is equivalent to "--git-dir=c/a.git --work-tree=c/a"' '
72 git --git-dir=c/a.git --work-tree=c/a status >expected &&
73 git -C c --git-dir=a.git --work-tree=a status >actual &&
74 test_cmp expected actual
77 test_expect_success 'Order should not matter: "-C c --git-dir=a.git --work-tree=a" is equivalent to "--git-dir=a.git -C c --work-tree=a"' '
78 git -C c --git-dir=a.git --work-tree=a status >expected &&
79 git --git-dir=a.git -C c --work-tree=a status >actual &&
80 test_cmp expected actual
83 test_expect_success 'Order should not matter: "-C c --git-dir=a.git --work-tree=a" is equivalent to "--git-dir=a.git --work-tree=a -C c"' '
84 git -C c --git-dir=a.git --work-tree=a status >expected &&
85 git --git-dir=a.git --work-tree=a -C c status >actual &&
86 test_cmp expected actual
89 test_expect_success 'Relative followed by fullpath: "-C ./here -C /there" is equivalent to "-C /there"' '
90 echo "initial in dir1/dir2" >expected &&
91 git -C dir1 -C "$(pwd)/dir1/dir2" log --format=%s >actual &&
92 test_cmp expected actual
95 test_done