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