1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117
|
#!/bin/sh
test_description='check random commands outside repo'
. ./test-lib.sh
test_expect_success 'set up a non-repo directory and test file' '
GIT_CEILING_DIRECTORIES=$(pwd) &&
export GIT_CEILING_DIRECTORIES &&
mkdir non-repo &&
(
cd non-repo &&
# confirm that git does not find a repo
test_must_fail git rev-parse --git-dir
) &&
test_write_lines one two three four >nums &&
git add nums &&
cp nums nums.old &&
test_write_lines five >>nums &&
git diff >sample.patch
'
test_expect_success 'compute a patch-id outside repository (uses SHA-1)' '
nongit env GIT_DEFAULT_HASH=sha1 \
git patch-id <sample.patch >patch-id.expect &&
nongit \
git patch-id <sample.patch >patch-id.actual &&
test_cmp patch-id.expect patch-id.actual
'
test_expect_success 'hash-object outside repository (uses SHA-1)' '
nongit env GIT_DEFAULT_HASH=sha1 \
git hash-object --stdin <sample.patch >hash.expect &&
nongit \
git hash-object --stdin <sample.patch >hash.actual &&
test_cmp hash.expect hash.actual
'
test_expect_success 'apply a patch outside repository' '
(
cd non-repo &&
cp ../nums.old nums &&
git apply ../sample.patch
) &&
test_cmp nums non-repo/nums
'
test_expect_success 'grep outside repository' '
git grep --cached two >expect &&
(
cd non-repo &&
cp ../nums.old nums &&
git grep --no-index two >../actual
) &&
test_cmp expect actual
'
test_expect_success 'imap-send outside repository' '
test_config_global imap.host imaps://localhost &&
test_config_global imap.folder Drafts &&
echo nothing to send >expect &&
test_must_fail git imap-send -v </dev/null 2>actual &&
test_cmp expect actual &&
(
cd non-repo &&
test_must_fail git imap-send -v </dev/null 2>../actual
) &&
test_cmp expect actual
'
test_expect_success 'check-ref-format outside repository' '
git check-ref-format --branch refs/heads/xyzzy >expect &&
nongit git check-ref-format --branch refs/heads/xyzzy >actual &&
test_cmp expect actual
'
test_expect_success 'diff outside repository' '
echo one >one &&
echo two >two &&
test_must_fail git diff --no-index one two >expect.raw &&
(
cd non-repo &&
cp ../one . &&
cp ../two . &&
test_must_fail git diff one two >../actual.raw
) &&
# outside repository diff falls back to SHA-1 but
# GIT_DEFAULT_HASH may be set to sha256 on the in-repo side.
sed -e "/^index /d" expect.raw >expect &&
sed -e "/^index /d" actual.raw >actual &&
test_cmp expect actual
'
test_expect_success 'stripspace outside repository' '
nongit git stripspace -s </dev/null
'
test_expect_success LIBCURL 'remote-http outside repository' '
test_must_fail git remote-http 2>actual &&
test_grep "^error: remote-curl" actual &&
(
cd non-repo &&
test_must_fail git remote-http 2>../actual
) &&
test_grep "^error: remote-curl" actual
'
test_expect_success 'update-server-info does not crash with -h' '
test_expect_code 129 git update-server-info -h >usage &&
test_grep "[Uu]sage: git update-server-info " usage &&
test_expect_code 129 nongit git update-server-info -h >usage &&
test_grep "[Uu]sage: git update-server-info " usage
'
test_done
|