3 test_description
='check random commands outside repo'
5 TEST_PASSES_SANITIZE_LEAK
=true
8 test_expect_success
'set up a non-repo directory and test file' '
9 GIT_CEILING_DIRECTORIES=$(pwd) &&
10 export GIT_CEILING_DIRECTORIES &&
14 # confirm that git does not find a repo
15 test_must_fail git rev-parse --git-dir
17 test_write_lines one two three four >nums &&
20 test_write_lines five >>nums &&
21 git diff >sample.patch
24 test_expect_success
'compute a patch-id outside repository (uses SHA-1)' '
25 nongit env GIT_DEFAULT_HASH=sha1 \
26 git patch-id <sample.patch >patch-id.expect &&
28 git patch-id <sample.patch >patch-id.actual &&
29 test_cmp patch-id.expect patch-id.actual
32 test_expect_success
'hash-object outside repository (uses SHA-1)' '
33 nongit env GIT_DEFAULT_HASH=sha1 \
34 git hash-object --stdin <sample.patch >hash.expect &&
36 git hash-object --stdin <sample.patch >hash.actual &&
37 test_cmp hash.expect hash.actual
40 test_expect_success
'apply a patch outside repository' '
43 cp ../nums.old nums &&
44 git apply ../sample.patch
46 test_cmp nums non-repo/nums
49 test_expect_success
'grep outside repository' '
50 git grep --cached two >expect &&
53 cp ../nums.old nums &&
54 git grep --no-index two >../actual
56 test_cmp expect actual
59 test_expect_success
'imap-send outside repository' '
60 test_config_global imap.host imaps://localhost &&
61 test_config_global imap.folder Drafts &&
63 echo nothing to send >expect &&
64 test_must_fail git imap-send -v </dev/null 2>actual &&
65 test_cmp expect actual &&
69 test_must_fail git imap-send -v </dev/null 2>../actual
71 test_cmp expect actual
74 test_expect_success
'check-ref-format outside repository' '
75 git check-ref-format --branch refs/heads/xyzzy >expect &&
76 nongit git check-ref-format --branch refs/heads/xyzzy >actual &&
77 test_cmp expect actual
80 test_expect_success
'diff outside repository' '
83 test_must_fail git diff --no-index one two >expect.raw &&
88 test_must_fail git diff one two >../actual.raw
90 # outside repository diff falls back to SHA-1 but
91 # GIT_DEFAULT_HASH may be set to sha256 on the in-repo side.
92 sed -e "/^index /d" expect.raw >expect &&
93 sed -e "/^index /d" actual.raw >actual &&
94 test_cmp expect actual
97 test_expect_success
'stripspace outside repository' '
98 nongit git stripspace -s </dev/null
101 test_expect_success
'remote-http outside repository' '
102 test_must_fail git remote-http 2>actual &&
103 test_grep "^error: remote-curl" actual &&
106 test_must_fail git remote-http 2>../actual
108 test_grep "^error: remote-curl" actual