1#!/bin/sh
2
3test_description='"-C <path>" option and its effects on other path-related options'
4
5. ./test-lib.sh
6
7test_expect_success '"git -C <path>" runs git from the directory <path>' '
8 test_create_repo dir1 &&
9 echo 1 >dir1/a.txt &&
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
14'
15
16test_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
24'
25
26test_expect_success 'Effect on --git-dir option: "-C c --git-dir=a.git" is equivalent to "--git-dir c/a.git"' '
27 mkdir c &&
28 mkdir c/a &&
29 mkdir c/a.git &&
30 (cd c/a.git && git init --bare) &&
31 echo 1 >c/a/a.txt &&
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
37'
38
39test_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
43'
44
45test_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"' '
46 rm c/a/a.txt &&
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
50'
51
52test_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
56'
57
58test_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
62'
63
64test_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
68'
69
70test_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
74'
75
76test_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
80'
81
82test_done