]>
Commit | Line | Data |
---|---|---|
44e1e4d6 NR |
1 | #!/bin/sh |
2 | ||
3 | test_description='"-C <path>" option and its effects on other path-related options' | |
4 | ||
a52f07af | 5 | TEST_PASSES_SANITIZE_LEAK=true |
44e1e4d6 NR |
6 | . ./test-lib.sh |
7 | ||
8 | test_expect_success '"git -C <path>" runs git from the directory <path>' ' | |
9 | test_create_repo dir1 && | |
10 | echo 1 >dir1/a.txt && | |
28a81f8b NR |
11 | msg="initial in dir1" && |
12 | (cd dir1 && git add a.txt && git commit -m "$msg") && | |
13 | echo "$msg" >expected && | |
44e1e4d6 NR |
14 | git -C dir1 log --format=%s >actual && |
15 | test_cmp expected actual | |
16 | ' | |
17 | ||
6a536e20 KN |
18 | test_expect_success '"git -C <path>" with an empty <path> is a no-op' ' |
19 | ( | |
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 | |
25 | ) | |
26 | ' | |
27 | ||
44e1e4d6 NR |
28 | test_expect_success 'Multiple -C options: "-C dir1 -C dir2" is equivalent to "-C dir1/dir2"' ' |
29 | test_create_repo dir1/dir2 && | |
28a81f8b NR |
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" && | |
44e1e4d6 NR |
35 | git -C dir1 -C dir2 log --format=%s >actual && |
36 | test_cmp expected actual | |
37 | ' | |
38 | ||
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 | |
50 | ' | |
51 | ||
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 | |
56 | ' | |
57 | ||
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 | |
63 | ' | |
64 | ||
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 | |
69 | ' | |
70 | ||
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 | |
75 | ' | |
76 | ||
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 | |
81 | ' | |
82 | ||
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 | |
87 | ' | |
88 | ||
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 | |
93 | ' | |
94 | ||
95 | test_done |