tg-summary.sh: Take base revision from for-each-ref output
[topgit/greenrd.git] / tg-delete.sh
blob287c4fa738366fac09d0ce126a8f5a55d28644dc
1 #!/bin/sh
2 # TopGit - A different patch queue manager
3 # (c) Petr Baudis <pasky@suse.cz> 2008
4 # GPLv2
6 force= # Whether to delete non-empty branch
7 name=
10 ## Parse options
12 while [ -n "$1" ]; do
13 arg="$1"; shift
14 case "$arg" in
15 -f)
16 force=1;;
17 -*)
18 echo "Usage: tg delete [-f] NAME" >&2
19 exit 1;;
21 [ -z "$name" ] || die "name already specified ($name)"
22 name="$arg";;
23 esac
24 done
27 ## Sanity checks
29 [ -n "$name" ] || die "no branch name specified"
30 branchrev="$(git rev-parse --verify "$name" 2>/dev/null)" ||
31 die "invalid branch name: $name"
32 baserev="$(git rev-parse --verify "refs/top-bases/$name" 2>/dev/null)" ||
33 die "not a TopGit topic branch: $name"
34 [ "$(git symbolic-ref HEAD)" != "refs/heads/$name" ] ||
35 die "cannot delete your current branch"
37 nonempty=
38 [ -z "$(git diff-tree "refs/top-bases/$name" "$name" | fgrep -v " .top")" ] || nonempty=1
40 [ -z "$nonempty" ] || [ -n "$force" ] || die "branch is non-empty: $name"
43 ## Wipe out
45 git update-ref -d "refs/top-bases/$name" "$baserev"
46 git update-ref -d "refs/heads/$name" "$branchrev"