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
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
25 echo "Usage: ${tgname:-tg} [...] annihilate [-f] [--no-update]" >&2
33 v_verify_topgit_branch name HEAD
34 ! branch_annihilated
"$name" || die
"TopGit branch $name is already annihilated."
36 [ -z "$force" ] && { branch_empty
"$name" || die
"branch is non-empty: $name"; }
41 ensure_ident_available
42 alldeps
="$(get_temp alldeps)"
43 tg
--no-pager summary
--deps >"$alldeps" || die
"tg summary --deps failed"
44 mb
="$(git merge-base "refs
/$topbases/$name" "refs
/heads
/$name")"
45 git read-tree
"$mb^{tree}"
46 # Need to pass --no-verify in order to inhibit TopGit's pre-commit hook to run,
47 # which would bark upon missing .top* files.
48 git commit
--no-verify -m"TopGit branch $name annihilated."
50 # Propagate the dependencies through to dependents (if any), if they don't already have them
51 dependencies
="$(awk -v annb="$name" 'NF == 2 && $2 != "" && $1 == annb { print $2 }' <"$alldeps")"
53 while read dependent
&& [ -n "$dependent" ]; do
54 # to avoid ambiguity with checkout -f we must use symbolic-ref + reset
55 git symbolic-ref HEAD
"refs/heads/$dependent"
58 while read dependency
&& [ -n "$dependency" ]; do
59 ! tg depend add
--no-update "$dependency" >/dev
/null
2>&1 || needupdate
=1
63 [ -z "$needupdate" ] || updatelist
="${updatelist:+$updatelist }$dependent"
65 $(awk -v annb="$name" 'NF == 2 && $1 != "" && $2 == annb { print $1 }' <"$alldeps")
68 info
"branch successfully annihilated: $name"
70 if [ -n "$updatelist" ]; then
71 if [ -n "$update" ]; then
72 now
="after the update completes"
74 info
"skipping update because --no-update given"
75 info
"be sure to update affected branches: $updatelist"
79 info
"If you have shared your work, you might want to run ${tgname:-tg} push $name $now."
80 if [ -n "$updatelist" ] && [ -n "$update" ]; then
81 info
"now updating affected branches: $updatelist"
83 .
"$TG_INST_CMDDIR"/tg-update