tg-revert.sh: convert any top-bases in TOPGIT REFS
[topgit/pro.git] / tg-annihilate.sh
blob8ff0e31ad6d1c0bc0e9096679ab3983972179899
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 # GPLv2
7 force= # Whether to annihilate non-empty branch, or branch where only the base is left.
10 ## Parse options
12 while [ -n "$1" ]; do
13 arg="$1"; shift
14 case "$arg" in
15 -f|--force)
16 force=1;;
18 echo "Usage: ${tgname:-tg} [...] annihilate [-f]" >&2
19 exit 1;;
20 esac
21 done
24 ## Sanity checks
26 name="$(verify_topgit_branch HEAD)"
28 [ -z "$force" ] && { branch_empty "$name" || die "branch is non-empty: $name"; }
30 ## Annihilate
31 ensure_ident_available
32 mb="$(git merge-base "refs/$topbases/$name" "refs/heads/$name")"
33 git read-tree "$mb^{tree}"
34 # Need to pass --no-verify in order to inhibit TopGit's pre-commit hook to run,
35 # which would bark upon missing .top* files.
36 git commit --no-verify -m"TopGit branch $name annihilated."
38 # Propagate the dependencies through to dependents (if any), if they don't already have them
39 dependencies="$(tg prev -w)"
40 updatelist=
41 while read dependent && [ -n "$dependent" ]; do
42 git checkout -f "refs/heads/$dependent"
43 needupdate=
44 while read dependency && [ -n "$dependency" ]; do
45 ! $tg depend add --no-update "$dependency" >/dev/null 2>&1 || needupdate=1
46 done <<-EOT
47 $dependencies
48 EOT
49 [ -z "$needupdate" ] || updatelist="${updatelist:+$updatelist }$dependent"
50 done <<EOT
51 $($tg next)
52 EOT
54 info "branch successfully annihilated: $name"
55 if [ -n "$updatelist" ]; then
56 info "now updating affected branches: $updatelist"
57 while read dependent && [ -n "$dependent" ]; do
58 $tg update "$dependent"
59 done <<-EOT
60 $(sed 'y/ /\n/' <<-LIST
61 $updatelist
62 LIST
64 EOT
67 info "If you have shared your work, you might want to run ${tgname:-tg} push $name now."
68 git status
70 # vim:noet