t1050: test tg status output
[topgit/pro.git] / tg-annihilate.sh
blobc99b5e51baab07cb458ee2c6a2469da20f8d2447
1 #!/bin/sh
2 # TopGit - A different patch queue manager
3 # (C) Petr Baudis <pasky@suse.cz> 2008
4 # (C) Per Cederqvist <ceder@lysator.liu.se> 2010
5 # (C) Kyle J. McKay <mackyle@gmail.com> 2017
6 # All rights reserved.
7 # GPLv2
9 force= # Whether to annihilate non-empty branch, or branch where only the base is left.
10 update=1 # Whether to run tg update on affected branches
13 ## Parse options
15 while [ -n "$1" ]; do
16 arg="$1"; shift
17 case "$arg" in
18 -f|--force)
19 force=1;;
20 --no-update)
21 update=;;
22 --update)
23 update=1;;
25 echo "Usage: ${tgname:-tg} [...] annihilate [-f] [--no-update]" >&2
26 exit 1;;
27 esac
28 done
31 ## Sanity checks
33 name="$(verify_topgit_branch HEAD)"
35 [ -z "$force" ] && { branch_empty "$name" || die "branch is non-empty: $name"; }
37 ## Annihilate
38 ensure_clean_tree
39 ensure_ident_available
40 mb="$(git merge-base "refs/$topbases/$name" "refs/heads/$name")"
41 git read-tree "$mb^{tree}"
42 # Need to pass --no-verify in order to inhibit TopGit's pre-commit hook to run,
43 # which would bark upon missing .top* files.
44 git commit --no-verify -m"TopGit branch $name annihilated."
46 # Propagate the dependencies through to dependents (if any), if they don't already have them
47 dependencies="$(tg prev -w)"
48 updatelist=
49 while read dependent && [ -n "$dependent" ]; do
50 # to avoid ambiguity with checkout -f we must use symbolic-ref + reset
51 git symbolic-ref HEAD "refs/heads/$dependent"
52 git reset -q --hard
53 needupdate=
54 while read dependency && [ -n "$dependency" ]; do
55 ! $tg depend add --no-update "$dependency" >/dev/null 2>&1 || needupdate=1
56 done <<-EOT
57 $dependencies
58 EOT
59 [ -z "$needupdate" ] || updatelist="${updatelist:+$updatelist }$dependent"
60 done <<EOT
61 $($tg next)
62 EOT
64 info "branch successfully annihilated: $name"
65 now="now"
66 if [ -n "$updatelist" ]; then
67 if [ -n "$update" ]; then
68 now="after the update completes"
69 else
70 info "skipping update because --no-update given"
71 info "be sure to update affected branches: $updatelist"
72 now="after updating"
75 info "If you have shared your work, you might want to run ${tgname:-tg} push $name $now."
76 if [ -n "$updatelist" ] && [ -n "$update" ]; then
77 info "now updating affected branches: $updatelist"
78 set -- $updatelist
79 . "$TG_INST_CMDDIR"/tg-update