3 test_description
='tg migrate-bases tests'
14 refs_new
="$PWD/refs_new"
15 refs_old
="$PWD/refs_old"
16 spec_new
="$PWD/spec_new"
17 spec_old
="$PWD/spec_old"
22 if [ "$1" = "--reverse" ]; then
23 tb
="heads/{top-bases}"
27 test_commit
--notick initial
&&
28 for b
in $branches; do
29 git update-ref
"refs/heads/$b" initial
&&
30 git update-ref
"refs/$tb/$b" initial ||
exit 1
33 git symbolic-ref HEAD
"refs/$tb/$b"
35 git config remote.origin.url .
&&
36 git config
--add remote.origin.fetch
"+refs/heads/*:refs/remotes/origin/*" &&
37 git config
--add remote.origin.fetch
"+refs/$tb/*:refs/remotes/origin/${tb#heads/}/*"
43 git
-C "$1" for-each-ref
--format="%(refname)" &&
45 git
-C "$1" symbolic-ref HEAD
49 git
-C "$1" config
--get-regexp '^remote\..*fetch\.*'
52 test_expect_success
'setup' '
53 test_create_repo r1 &&
54 test_create_repo r2 &&
55 test_create_repo r3 &&
56 test_create_repo r4 &&
57 test_create_repo r5 &&
58 test_create_repo r6 &&
59 test_create_repo r7 &&
60 test_create_repo r8 &&
64 setup_refs --reverse r4 &&
65 setup_refs --reverse r5 &&
66 setup_refs --reverse r6 &&
67 show_refnames r1 > "$refs_old" &&
68 show_refspecs r1 > "$spec_old" &&
69 show_refnames r4 > "$refs_new" &&
70 show_refspecs r4 > "$spec_new" &&
72 setup_refs --reverse r8 1 &&
73 show_refnames r7 > "$refs_old-HEAD" &&
74 show_refnames r8 > "$refs_new-HEAD"
77 test_expect_success
'invalid options' '
78 test_must_fail tg -C r1 migrate-bases --dry-run --no-remotes --remotes-only &&
79 test_must_fail tg -C r1 migrate-bases --force --no-remotes --remotes-only &&
80 test_must_fail tg -C r1 migrate-bases --no-remotes --remotes-only &&
81 test_must_fail tg -C r1 migrate-bases --remotes-only --no-remotes &&
82 test_must_fail tg -C r1 migrate-bases --no-remotes &&
83 test_must_fail tg -C r1 migrate-bases --remotes-only &&
84 test_must_fail tg -C r1 migrate-bases
87 test_expect_success
'migrate old (refs only) to new' '
88 show_refnames r1 >refs &&
89 show_refspecs r1 >spec &&
90 test_cmp refs refs_old &&
91 test_cmp spec spec_old &&
92 tg -C r1 migrate-bases --dry-run --no-remotes &&
93 test_cmp refs refs_old &&
94 test_cmp spec spec_old &&
95 tg -C r1 migrate-bases --force --no-remotes &&
96 show_refnames r1 >refs &&
97 show_refspecs r1 >spec &&
98 test_cmp refs refs_new &&
99 test_cmp spec spec_old
102 test_expect_success
'migrate old (remotes only) to new' '
103 show_refnames r2 >refs &&
104 show_refspecs r2 >spec &&
105 test_cmp refs refs_old &&
106 test_cmp spec spec_old &&
107 tg -C r2 migrate-bases --dry-run --remotes-only &&
108 test_cmp refs refs_old &&
109 test_cmp spec spec_old &&
110 tg -C r2 migrate-bases --force --remotes-only &&
111 show_refnames r2 >refs &&
112 show_refspecs r2 >spec &&
113 test_cmp refs refs_old &&
114 test_cmp spec spec_new
117 test_expect_success
'migrate old (refs & remotes) to new' '
118 show_refnames r3 >refs &&
119 show_refspecs r3 >spec &&
120 test_cmp refs refs_old &&
121 test_cmp spec spec_old &&
122 tg -C r3 migrate-bases --dry-run &&
123 test_cmp refs refs_old &&
124 test_cmp spec spec_old &&
125 tg -C r3 migrate-bases --force &&
126 show_refnames r3 >refs &&
127 show_refspecs r3 >spec &&
128 test_cmp refs refs_new &&
129 test_cmp spec spec_new
132 test_expect_success
'migrate new (refs only) to old' '
133 show_refnames r4 >refs &&
134 show_refspecs r4 >spec &&
135 test_cmp refs refs_new &&
136 test_cmp spec spec_new &&
137 tg -C r4 migrate-bases --dry-run --reverse --no-remotes &&
138 test_cmp refs refs_new &&
139 test_cmp spec spec_new &&
140 tg -C r4 migrate-bases --force --reverse --no-remotes &&
141 show_refnames r4 >refs &&
142 show_refspecs r4 >spec &&
143 test_cmp refs refs_old &&
144 test_cmp spec spec_new
147 test_expect_success
'migrate new (remotes only) to old' '
148 show_refnames r5 >refs &&
149 show_refspecs r5 >spec &&
150 test_cmp refs refs_new &&
151 test_cmp spec spec_new &&
152 tg -C r5 migrate-bases --dry-run --remotes-only --reverse &&
153 test_cmp refs refs_new &&
154 test_cmp spec spec_new &&
155 tg -C r5 migrate-bases --force --remotes-only --reverse &&
156 show_refnames r5 >refs &&
157 show_refspecs r5 >spec &&
158 test_cmp refs refs_new &&
159 test_cmp spec spec_old
162 test_expect_success
'migrate new (refs & remotes) to old' '
163 show_refnames r6 >refs &&
164 show_refspecs r6 >spec &&
165 test_cmp refs refs_new &&
166 test_cmp spec spec_new &&
167 tg -C r6 migrate-bases --reverse --dry-run &&
168 test_cmp refs refs_new &&
169 test_cmp spec spec_new &&
170 tg -C r6 migrate-bases --reverse --force &&
171 show_refnames r6 >refs &&
172 show_refspecs r6 >spec &&
173 test_cmp refs refs_old &&
174 test_cmp spec spec_old
177 test_expect_failure
'migrate old top-bases HEAD symref to new' '
178 tg -C r7 migrate-bases --force &&
179 show_refnames r7 >refs &&
180 test_cmp refs refs_new-HEAD
183 test_expect_failure
'migrate new top-bases HEAD symref to old' '
184 tg -C r8 migrate-bases --force --reverse &&
185 show_refnames r8 >refs &&
186 test_cmp refs refs_old-HEAD