3 test_description
='tg update remote sets up newly added branch'
13 uctmp
="$(test_get_temp update-check)" || die
15 branch_is_up_to_date
() {
16 needs_update_check
"$@" >"$uctmp" &&
18 read -r uc_processed
&&
23 test z
"$uc_behind" = z
":"
26 test_expect_success
'setup' '
27 test_create_repo pristine &&
29 git checkout --orphan release &&
30 git read-tree --empty &&
32 test_commit "release~1" &&
33 tg_test_create_branches <<-EOT &&
34 t/patch1 [PATCH] alpha patch
37 t/patch2 [PATCH] beta patch
40 :t/patch3 [PATCH] gamma patch
43 git checkout -f t/patch1 &&
44 test_commit "alpha~1" &&
45 git checkout -f t/patch2 &&
46 test_commit "beta~1" &&
47 git symbolic-ref HEAD refs/remotes/uranus/t/patch3 &&
49 test_commit "gamma~1" &&
50 git symbolic-ref HEAD refs/remotes/uranus/proposed &&
51 git read-tree --empty &&
53 test_commit "proposed~1" &&
54 git symbolic-ref HEAD "$(tg --top-bases -r uranus)/orphan" &&
55 git read-tree --empty &&
57 test_commit "orphan~1" &&
58 tg_test_create_branch t/int -m "[INTERMEDIATE] extra level" t/patch2 &&
59 tg_test_create_branch stage -m "[STAGE] staging branch" release t/patch1 t/int &&
60 test_must_fail branch_is_up_to_date stage &&
61 git symbolic-ref HEAD "$(tg --top-bases)/stage" &&
63 git rm --force --ignore-unmatch -- .topmsg .topdeps &&
64 git read-tree -m release t/patch1 t/int &&
65 git rm --force --ignore-unmatch -- .topmsg .topdeps &&
66 newtree="$(git write-tree)" && test -n "$newtree" &&
68 newcommit="$(git commit-tree -p HEAD -p t/patch1 -p t/int -m "mighty octopus" "$newtree")" &&
69 test -n "$newcommit" && git update-ref HEAD "$newcommit" HEAD &&
70 git checkout -f stage &&
72 git merge -m "bases up" "$(tg --top-bases)/stage" &&
73 git config remote.uranus.url "." &&
74 git config topgit.remote uranus &&
75 git for-each-ref --format="%(refname)" >refs &&
77 \$0 ~ /^refs\/remotes\// { next }
80 sub(/\/heads\//, \"/remotes/uranus/\")
84 \$0 ~ /\/top-bases\// {
85 sub(/\/top-bases\//, \"/remotes/uranus/top-bases/\")
89 \$0 ~ /\/heads\/\{top-bases\}\// {
90 sub(/\/heads\/\{top-bases\}\//, \"/remotes/uranus/{top-bases}/\")
95 while read -r newref oldref; do
96 echo "oldref = $oldref" &&
97 echo "newref = $newref" &&
98 git update-ref "$newref" "$oldref" ""
101 branch_is_up_to_date stage &&
102 git gc --aggressive --prune=now
105 test_expect_success
'unknown branch fails' '
106 cp -pR pristine unknown &&
108 git symbolic-ref HEAD refs/remotes/uranus/stage &&
110 echo "t/patch-unknown" >> .topdeps &&
113 git commit -m ".topdeps: add t/patch-unknown dependency" &&
114 test_might_fail tg update stage &&
115 test_must_fail tg update stage
118 test_expect_success
'non-tgish remote branch fails' '
119 cp -pR pristine nontgish &&
121 git symbolic-ref HEAD refs/remotes/uranus/stage &&
123 echo "proposed" >> .topdeps &&
126 git commit -m ".topdeps: add proposed dependency" &&
127 test_might_fail tg update stage &&
128 test_must_fail tg update stage
131 test_expect_success
'orphan remote branch base fails' '
132 cp -pR pristine nontgish &&
134 git symbolic-ref HEAD refs/remotes/uranus/stage &&
136 echo "orphan" >> .topdeps &&
139 git commit -m ".topdeps: add orphan dependency" &&
140 test_might_fail tg update stage &&
141 test_must_fail tg update stage
144 test_expect_success
'blocked base remote branch setup fails' '
145 cp -pR pristine blockingbase &&
147 git update-ref "$(tg --top-bases)/t/patch3" release "" &&
148 git symbolic-ref HEAD refs/remotes/uranus/stage &&
150 echo "t/patch3" >> .topdeps &&
153 git commit -m ".topdeps: add t/patch3 dependency" &&
154 test_might_fail tg update stage &&
155 test_must_fail tg update stage
158 test_expect_success
'auto setup local branch' '
159 cp -pR pristine autosetup &&
161 git symbolic-ref HEAD refs/remotes/uranus/stage &&
163 echo "t/patch3" >> .topdeps &&
166 git commit -m ".topdeps: add t/patch3 dependency" &&
168 cmt="$(git rev-parse --verify refs/heads/stage)" && test -n "$cmt" &&
170 cmt2="$(git rev-parse --verify refs/heads/stage)" && test -n "$cmt2" &&
171 test z"$cmt" = z"$cmt2" &&
172 test_cmp_rev "$(tg --top-bases -r)/t/patch3" "$(tg --top-bases)/t/patch3" &&
173 test_cmp_rev refs/remotes/uranus/t/patch3 refs/heads/t/patch3