hooks/pre-commit: check for deps repetitions
[topgit/tsort.git] / tg-depend.sh
blob474ccda4e098a2046a2e60a52d5addad4b007f81
1 #!/bin/sh
2 # TopGit - A different patch queue manager
3 # (c) Petr Baudis <pasky@suse.cz> 2008
4 # GPLv2
6 name=
9 usage()
11 echo "Usage: tg [...] depend add NAME" >&2
12 exit 1
15 ## Parse options
17 subcmd="$1"; shift || :
18 case "$subcmd" in
19 -h|"")
20 usage;;
21 add)
24 die "unknown subcommand ($subcmd)";;
25 esac
27 while [ -n "$1" ]; do
28 arg="$1"; shift
29 case "$arg" in
30 -*)
31 usage;;
33 [ -z "$name" ] || die "name already specified ($name)"
34 name="$arg";;
35 esac
36 done
39 ## Sanity checks
41 [ -n "$name" ] || die "no branch name specified"
42 branchrev="$(git rev-parse --verify "$name" 2>/dev/null)" ||
43 die "invalid branch name: $name"
45 # Check that we are on a TopGit branch.
46 current_name="$(git symbolic-ref HEAD | sed 's#^refs/\(heads\|top-bases\)/##')"
47 current_base_rev="$(git rev-parse --short --verify "refs/top-bases/$current_name" 2>/dev/null)" ||
48 die "not a TopGit-controlled branch"
50 ## Record new dependency
51 depend_add()
53 [ "$name" = "$current_name" ] &&
54 die "$name cannot depend on itself."
56 { $tg summary --deps; echo "$current_name" "$name"; } |
57 tsort >/dev/null ||
58 die "tg: that dependency would introduce a dependency loop"
60 grep -F -x -e "$name" "$root_dir/.topdeps" >/dev/null &&
61 die "tg: $current_name already depends on $name"
63 echo "$name" >>"$root_dir/.topdeps"
64 git add -f "$root_dir/.topdeps"
65 git commit -m"New TopGit dependency: $name"
66 $tg update
69 depend_$subcmd
71 # vim:noet