blob: e2770e4541f94d60dba1ae8698abf3496a6a50e9 [file] [log] [blame]
Jeff King1e7ba0f2011-12-12 19:48:08 -05001#!/bin/sh
2
3test_description='test fetching of oddly-named refs'
Johannes Schindelin3ac8f632020-11-18 23:44:33 +00004GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
Johannes Schindelin334afbc2020-11-18 23:44:19 +00005export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
6
Jeff King1e7ba0f2011-12-12 19:48:08 -05007. ./test-lib.sh
8
9# afterwards we will have:
10# HEAD - two
Johannes Schindelin3ac8f632020-11-18 23:44:33 +000011# refs/for/refs/heads/main - one
12# refs/heads/main - three
Jeff King1e7ba0f2011-12-12 19:48:08 -050013test_expect_success 'setup repo with odd suffix ref' '
14 echo content >file &&
15 git add . &&
16 git commit -m one &&
Johannes Schindelin3ac8f632020-11-18 23:44:33 +000017 git update-ref refs/for/refs/heads/main HEAD &&
Jeff King1e7ba0f2011-12-12 19:48:08 -050018 echo content >>file &&
19 git commit -a -m two &&
20 echo content >>file &&
21 git commit -a -m three &&
22 git checkout HEAD^
23'
24
25test_expect_success 'suffix ref is ignored during fetch' '
26 git clone --bare file://"$PWD" suffix &&
27 echo three >expect &&
Johannes Schindelin3ac8f632020-11-18 23:44:33 +000028 git --git-dir=suffix log -1 --format=%s refs/heads/main >actual &&
Jeff King1e7ba0f2011-12-12 19:48:08 -050029 test_cmp expect actual
30'
31
Jeff King8e9faf22014-12-10 04:47:02 -050032test_expect_success 'try to create repo with absurdly long refname' '
brian m. carlson8125a582018-05-13 02:24:13 +000033 ref240=$ZERO_OID/$ZERO_OID/$ZERO_OID/$ZERO_OID/$ZERO_OID/$ZERO_OID &&
Jeff King8e9faf22014-12-10 04:47:02 -050034 ref1440=$ref240/$ref240/$ref240/$ref240/$ref240/$ref240 &&
35 git init long &&
36 (
37 cd long &&
38 test_commit long &&
Johannes Schindelin3ac8f632020-11-18 23:44:33 +000039 test_commit main
Jeff King8e9faf22014-12-10 04:47:02 -050040 ) &&
41 if git -C long update-ref refs/heads/$ref1440 long; then
42 test_set_prereq LONG_REF
43 else
44 echo >&2 "long refs not supported"
45 fi
46'
47
48test_expect_success LONG_REF 'fetch handles extremely long refname' '
49 git fetch long refs/heads/*:refs/remotes/long/* &&
50 cat >expect <<-\EOF &&
51 long
Johannes Schindelin3ac8f632020-11-18 23:44:33 +000052 main
Jeff King8e9faf22014-12-10 04:47:02 -050053 EOF
54 git for-each-ref --format="%(subject)" refs/remotes/long >actual &&
55 test_cmp expect actual
56'
57
58test_expect_success LONG_REF 'push handles extremely long refname' '
59 git push long :refs/heads/$ref1440 &&
60 git -C long for-each-ref --format="%(subject)" refs/heads >actual &&
Johannes Schindelin3ac8f632020-11-18 23:44:33 +000061 echo main >expect &&
Jeff King8e9faf22014-12-10 04:47:02 -050062 test_cmp expect actual
63'
64
Jeff King1e7ba0f2011-12-12 19:48:08 -050065test_done