tg-patch.sh: allow git diff-tree options to be passed through
[topgit/pro.git] / tg-annihilate.sh
blob3fdb3236681d5a0a60a855d1d8bfdb915f232a9f
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="$(git symbolic-ref HEAD | sed 's#^refs/heads/##')"
27 branchrev="$(git rev-parse --verify "$name" 2>/dev/null)" ||
28 die "invalid branch name: $name"
29 baserev="$(git rev-parse --verify "refs/top-bases/$name" 2>/dev/null)" ||
30 die "not a TopGit topic branch: $name"
32 [ -z "$force" ] && { branch_empty "$name" || die "branch is non-empty: $name"; }
34 ## Annihilate
35 mb="$(git merge-base "refs/top-bases/$name" "$name")"
36 git read-tree "$mb^{tree}"
37 # Need to pass --no-verify in order to inhibit TopGit's pre-commit hook to run,
38 # which would bark upon missing .top* files.
39 git commit --no-verify -m"TopGit branch $name annihilated."
41 # Propagate the dependencies through to dependents (if any), if they don't already have them
42 dependencies="$(tg prev -w)"
43 $tg next | while read dependent; do
44 git checkout -f $dependent
45 for dependency in $dependencies; do
46 $tg depend add "$dependency" 2>/dev/null
47 done
48 done
50 info "If you have shared your work, you might want to run ${tgname:-tg} push $name now."
51 git status
53 # vim:noet