Raw
1 #!/bin/sh
2
3 test_description='check random commands outside repo'
4
5 . ./test-lib.sh
6
7 test_expect_success 'set up a non-repo directory and test file' '
8 GIT_CEILING_DIRECTORIES=$(pwd) &&
9 export GIT_CEILING_DIRECTORIES &&
10 mkdir non-repo &&
11 (
12 cd non-repo &&
13 # confirm that git does not find a repo
14 test_must_fail git rev-parse --git-dir
15 ) &&
16 test_write_lines one two three four >nums &&
17 git add nums &&
18 cp nums nums.old &&
19 test_write_lines five >>nums &&
20 git diff >sample.patch
21 '
22
23 test_expect_success 'compute a patch-id outside repository (uses SHA-1)' '
24 nongit env GIT_DEFAULT_HASH=sha1 \
25 git patch-id <sample.patch >patch-id.expect &&
26 nongit \
27 git patch-id <sample.patch >patch-id.actual &&
28 test_cmp patch-id.expect patch-id.actual
29 '
30
31 test_expect_success 'hash-object outside repository (uses SHA-1)' '
32 nongit env GIT_DEFAULT_HASH=sha1 \
33 git hash-object --stdin <sample.patch >hash.expect &&
34 nongit \
35 git hash-object --stdin <sample.patch >hash.actual &&
36 test_cmp hash.expect hash.actual
37 '
38
39 test_expect_success 'apply a patch outside repository' '
40 (
41 cd non-repo &&
42 cp ../nums.old nums &&
43 git apply ../sample.patch
44 ) &&
45 test_cmp nums non-repo/nums
46 '
47
48 test_expect_success 'grep outside repository' '
49 git grep --cached two >expect &&
50 (
51 cd non-repo &&
52 cp ../nums.old nums &&
53 git grep --no-index two >../actual
54 ) &&
55 test_cmp expect actual
56 '
57
58 test_expect_success 'imap-send outside repository' '
59 test_config_global imap.host imaps://localhost &&
60 test_config_global imap.folder Drafts &&
61
62 echo nothing to send >expect &&
63 test_must_fail git imap-send -v </dev/null 2>actual &&
64 test_cmp expect actual &&
65
66 (
67 cd non-repo &&
68 test_must_fail git imap-send -v </dev/null 2>../actual
69 ) &&
70 test_cmp expect actual
71 '
72
73 test_expect_success 'check-ref-format outside repository' '
74 git check-ref-format --branch refs/heads/xyzzy >expect &&
75 nongit git check-ref-format --branch refs/heads/xyzzy >actual &&
76 test_cmp expect actual
77 '
78
79 test_expect_success 'diff outside repository' '
80 echo one >one &&
81 echo two >two &&
82 test_must_fail git diff --no-index one two >expect.raw &&
83 (
84 cd non-repo &&
85 cp ../one . &&
86 cp ../two . &&
87 test_must_fail git diff one two >../actual.raw
88 ) &&
89 # outside repository diff falls back to SHA-1 but
90 # GIT_DEFAULT_HASH may be set to sha256 on the in-repo side.
91 sed -e "/^index /d" expect.raw >expect &&
92 sed -e "/^index /d" actual.raw >actual &&
93 test_cmp expect actual
94 '
95
96 test_expect_success 'hash object exceeding bigFileThreshold outside repository' '
97 (
98 cd non-repo &&
99 echo foo >foo &&
100 git -c core.bigFileThreshold=1 hash-object --stdin <foo
101 )
102 '
103
104 test_expect_success 'stripspace outside repository' '
105 nongit git stripspace -s </dev/null
106 '
107
108 test_expect_success LIBCURL 'remote-http outside repository' '
109 test_must_fail git remote-http 2>actual &&
110 test_grep "^error: remote-curl" actual &&
111 (
112 cd non-repo &&
113 test_must_fail git remote-http 2>../actual
114 ) &&
115 test_grep "^error: remote-curl" actual
116 '
117
118 for cmd in $(git --list-cmds=main)
119 do
120 cmd=${cmd%.*} # strip .sh, .perl, etc.
121 case "$cmd" in
122 archimport | citool | credential-netrc | credential-libsecret | \
123 credential-osxkeychain | cvsexportcommit | cvsimport | cvsserver | \
124 daemon | \
125 difftool--helper | filter-branch | format-rev | fsck-objects | \
126 get-tar-commit-id | \
127 gui | gui--askpass | \
128 http-backend | http-fetch | http-push | init-db | \
129 merge-octopus | merge-one-file | merge-resolve | mergetool | \
130 mktag | p4 | p4.py | pickaxe | remote-ftp | remote-ftps | \
131 remote-http | remote-https | replay | send-email | \
132 sh-i18n--envsubst | shell | show | stage | submodule | svn | \
133 upload-archive--writer | upload-pack | web--browse | whatchanged)
134 expect_outcome=expect_failure ;;
135 *)
136 expect_outcome=expect_success ;;
137 esac
138 case "$cmd" in
139 instaweb)
140 prereq=PERL ;;
141 *)
142 prereq= ;;
143 esac
144 test_$expect_outcome $prereq "'git $cmd -h' outside a repository" '
145 test_expect_code 129 nongit git $cmd -h >usage &&
146 test_grep "[Uu]sage: git $cmd " usage
147 '
148 test_$expect_outcome $prereq "'git $cmd --help-all' outside a repository" '
149 test_expect_code 129 nongit git $cmd --help-all >usage &&
150 test_grep "[Uu]sage: git $cmd " usage
151 '
152 done
153
154 test_expect_success 'fmt-merge-msg does not crash with -h' '
155 test_expect_code 129 git fmt-merge-msg -h >usage &&
156 test_grep "[Uu]sage: git fmt-merge-msg " usage &&
157 test_expect_code 129 nongit git fmt-merge-msg -h >usage &&
158 test_grep "[Uu]sage: git fmt-merge-msg " usage
159 '
160
161 test_done