tg.sh: handle help -h
[topgit/pro.git] / t / t5030-update-newbranch.sh
blob2d861697d4778d34d7fbebed7720c30d5516a808
1 #!/bin/sh
3 test_description='tg update remote sets up newly added branch'
5 TEST_NO_CREATE_REPO=1
7 . ./test-lib.sh
9 test_plan 6
11 tg_test_remote=uranus
13 uctmp="$(test_get_temp update-check)" || die
15 branch_is_up_to_date() {
16 needs_update_check "$@" >"$uctmp" &&
18 read -r uc_processed &&
19 read -r uc_behind &&
20 read -r uc_ahead &&
21 read -r uc_partial
22 } <"$uctmp" &&
23 test z"$uc_behind" = z":"
26 test_expect_success 'setup' '
27 test_create_repo pristine &&
28 cd pristine &&
29 git checkout --orphan release &&
30 git read-tree --empty &&
31 git reset --hard &&
32 test_commit "release~1" &&
33 tg_test_create_branches <<-EOT &&
34 t/patch1 [PATCH] alpha patch
35 release
37 t/patch2 [PATCH] beta patch
38 release
40 :t/patch3 [PATCH] gamma patch
41 release
42 EOT
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 &&
48 git reset --hard &&
49 test_commit "gamma~1" &&
50 git symbolic-ref HEAD refs/remotes/uranus/proposed &&
51 git read-tree --empty &&
52 git reset --hard &&
53 test_commit "proposed~1" &&
54 git symbolic-ref HEAD "$(tg --top-bases -r uranus)/orphan" &&
55 git read-tree --empty &&
56 git reset --hard &&
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" &&
62 git reset --hard &&
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" &&
67 test_tick &&
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 &&
71 test_tick &&
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 &&
76 awk <refs >refs2 "
77 \$0 ~ /^refs\/remotes\// { next }
78 { orig = \$0 }
79 \$0 ~ /\/heads\// {
80 sub(/\/heads\//, \"/remotes/uranus/\")
81 print \$0, orig
82 next
84 \$0 ~ /\/top-bases\// {
85 sub(/\/top-bases\//, \"/remotes/uranus/top-bases/\")
86 print \$0, orig
87 next
89 \$0 ~ /\/heads\/\{top-bases\}\// {
90 sub(/\/heads\/\{top-bases\}\//, \"/remotes/uranus/{top-bases}/\")
91 print \$0, orig
92 next
94 " &&
95 while read -r newref oldref; do
96 echo "oldref = $oldref" &&
97 echo "newref = $newref" &&
98 git update-ref "$newref" "$oldref" ""
99 done <refs2 &&
100 rm -f refs refs2 &&
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 &&
107 cd unknown &&
108 git symbolic-ref HEAD refs/remotes/uranus/stage &&
109 git reset --hard &&
110 echo "t/patch-unknown" >> .topdeps &&
111 git add -u &&
112 test_tick &&
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 &&
120 cd nontgish &&
121 git symbolic-ref HEAD refs/remotes/uranus/stage &&
122 git reset --hard &&
123 echo "proposed" >> .topdeps &&
124 git add -u &&
125 test_tick &&
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 &&
133 cd nontgish &&
134 git symbolic-ref HEAD refs/remotes/uranus/stage &&
135 git reset --hard &&
136 echo "orphan" >> .topdeps &&
137 git add -u &&
138 test_tick &&
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 &&
146 cd blockingbase &&
147 git update-ref "$(tg --top-bases)/t/patch3" release "" &&
148 git symbolic-ref HEAD refs/remotes/uranus/stage &&
149 git reset --hard &&
150 echo "t/patch3" >> .topdeps &&
151 git add -u &&
152 test_tick &&
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 &&
160 cd autosetup &&
161 git symbolic-ref HEAD refs/remotes/uranus/stage &&
162 git reset --hard &&
163 echo "t/patch3" >> .topdeps &&
164 git add -u &&
165 test_tick &&
166 git commit -m ".topdeps: add t/patch3 dependency" &&
167 tg update stage &&
168 cmt="$(git rev-parse --verify refs/heads/stage)" && test -n "$cmt" &&
169 tg update stage &&
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
176 test_done