3 test_description='"-C <path>" option and its effects on other path-related options'
7 test_expect_success '"git -C <path>" runs git from the directory <path>' '
8 test_create_repo dir1 &&
10 (cd dir1 && git add a.txt && git commit -m "initial in dir1") &&
11 echo "initial in dir1" >expected &&
12 git -C dir1 log --format=%s >actual &&
13 test_cmp expected actual
16 test_expect_success 'Multiple -C options: "-C dir1 -C dir2" is equivalent to "-C dir1/dir2"' '
17 test_create_repo dir1/dir2 &&
18 echo 1 >dir1/dir2/a.txt &&
19 git -C dir1/dir2 add a.txt &&
20 echo "initial in dir1/dir2" >expected &&
21 git -C dir1/dir2 commit -m "initial in dir1/dir2" &&
22 git -C dir1 -C dir2 log --format=%s >actual &&
23 test_cmp expected actual
26 test_expect_success 'Effect on --git-dir option: "-C c --git-dir=a.git" is equivalent to "--git-dir c/a.git"' '
30 (cd c/a.git && git init --bare) &&
32 git --git-dir c/a.git --work-tree=c/a add a.txt &&
33 git --git-dir c/a.git --work-tree=c/a commit -m "initial" &&
34 git --git-dir=c/a.git log -1 --format=%s >expected &&
35 git -C c --git-dir=a.git log -1 --format=%s >actual &&
36 test_cmp expected actual
39 test_expect_success 'Order should not matter: "--git-dir=a.git -C c" is equivalent to "-C c --git-dir=a.git"' '
40 git -C c --git-dir=a.git log -1 --format=%s >expected &&
41 git --git-dir=a.git -C c log -1 --format=%s >actual &&
42 test_cmp expected actual
45 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"' '
47 git --git-dir=c/a.git --work-tree=c/a status >expected &&
48 git -C c/a.git --work-tree=../a status >actual &&
49 test_cmp expected actual
52 test_expect_success 'Order should not matter: "--work-tree=../a -C c/a.git" is equivalent to "-C c/a.git --work-tree=../a"' '
53 git -C c/a.git --work-tree=../a status >expected &&
54 git --work-tree=../a -C c/a.git status >actual &&
55 test_cmp expected actual
58 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"' '
59 git --git-dir=c/a.git --work-tree=c/a status >expected &&
60 git -C c --git-dir=a.git --work-tree=a status >actual &&
61 test_cmp expected actual
64 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"' '
65 git -C c --git-dir=a.git --work-tree=a status >expected &&
66 git --git-dir=a.git -C c --work-tree=a status >actual &&
67 test_cmp expected actual
70 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"' '
71 git -C c --git-dir=a.git --work-tree=a status >expected &&
72 git --git-dir=a.git --work-tree=a -C c status >actual &&
73 test_cmp expected actual
76 test_expect_success 'Relative followed by fullpath: "-C ./here -C /there" is equivalent to "-C /there"' '
77 echo "initial in dir1/dir2" >expected &&
78 git -C dir1 -C "$(pwd)/dir1/dir2" log --format=%s >actual &&
79 test_cmp expected actual